Пример #1
0
def auth_basic(retry=False):
    config = utils.user_config()
    username = config.pytheon.username or utils.get_input("Username")
    password = None
    if keyring:
        log.debug("Use keyring module. Great!")
        password = keyring.get_password("basic:api.pytheon.net", username)
    if password == None or retry:
        password = utils.get_input("Password", password=True)
    if keyring:
        keyring.set_password("basic:api.pytheon.net", username, password)
    auth = base64.encodestring("%s:%s" % (username, password))
    return {"Authorization": "Basic " + auth.strip()}
Пример #2
0
def create(parser, options, args):
    """create your pytheon project"""
    binary = utils.vcs_binary()

    global_config = utils.user_config()
    if not os.path.isfile(global_config._filename):
        global_config.pytheon = dict(
                username=options.username or utils.get_input('Username'),
            )
        global_config.write()
    rc = global_config.pytheon

    config = utils.project_config(filename=options.buildout)
    if not os.path.isfile(config._filename):
        if not options.project_name:
            options.project_name = utils.get_input('Project name',
                           default=os.path.basename(os.getcwd()))
        config.deploy = dict(
                version='1',
                use='gunicorn',
                project_name=options.project_name,
            )
    if options.project_name:
        config.deploy.project_name = options.project_name
    config.write()

    kw = dict(username=rc.username, project_name=config.deploy.project_name)
    if binary == 'git':
        remote = os.environ.get('PYTHEON_REMOTE',
                        '[email protected]:%(project_name)s.git').rstrip('/')
        remote = remote % kw
        utils.call(binary, 'remote', 'add', 'pytheon', remote, silent=True)

    else:
        remote = os.environ.get('PYTHEON_REMOTE',
                        '[email protected]/%(project_name)s').rstrip('/')
        remote = remote % kw
        filename = '.hg/hgrc'
        config = Config.from_file(filename)
        config.paths.pytheon = remote
        config.write()

    commit(binary, config._filename)

    return http.request('/v1/applications', name=config.deploy.project_name)
Пример #3
0
def register(parser, options, args):
    """register on pytheon"""
    if options.key and options.reset:
        parser.error("You can't reset a password with a confirmation key")

    config = utils.user_config()
    if options.username:
        config.pytheon.username = options.username
        config.write()

    if not config.pytheon.username:
        parser.error('Please specify a valid email')

    if options.key:
        return http.request('/v1/set_password/%s' % options.key.strip('/'),
                            auth=False,
                            password=utils.get_input('Password',
                            password=True))
    elif options.reset:
        return http.request('/v1/reset_password/', auth=False,
                            email=options.username)
    else:
        return http.request('/v1/register', auth=False, email=options.username)