예제 #1
0
def keyring_get_password(username):
    keyring_impl = keyring.get_keyring()
    verbose("Note: will use the backend: '{0}'".format(keyring_impl))
    password = keyring.get_password('cbas', username)
    if not password:
        info("No password found in keychain, please enter it now to store it.")
        password = prompt_get_password(username)
        keyring.set_password('cbas', username, password)
    return password
예제 #2
0
def keyring_get_password(username):
    keyring_impl = keyring.get_keyring()
    verbose("Note: will use the backend: '{0}'".format(keyring_impl))
    password = keyring.get_password('cbas', username)
    if not password:
        info("No password found in keychain, please enter it now to store it.")
        password = prompt_get_password(username)
        keyring.set_password('cbas', username, password)
    return password
예제 #3
0
def get_password(password_provider, username):
    verbose("Password provider is: '{}'".format(password_provider))
    if password_provider == PROMPT:
        password = prompt_get_password(username)
    elif password_provider == KEYRING:
        password = keyring_get_password(username)
    elif password_provider == TESTING:
        password = '******'
    else:
        raise CMDLineExit("'{0}' is not a valid password provider.\n".format(
            password_provider) +
                          "Valid options are: {0}".format(PASSWORD_PROVIDERS))

    return password
예제 #4
0
def get_password(password_provider, username):
    verbose("Password provider is: '{}'".format(password_provider))
    if password_provider == PROMPT:
        password = prompt_get_password(username)
    elif password_provider == KEYRING:
        password = keyring_get_password(username)
    elif password_provider == TESTING:
        password = '******'
    else:
        raise CMDLineExit("'{0}' is not a valid password provider.\n".
                          format(password_provider) +
                          "Valid options are: {0}".
                          format(PASSWORD_PROVIDERS))

    return password
예제 #5
0
def obtain_access_token(config, password):
    info("Will now attempt to obtain an JWT...")
    auth_request_data = {'client_id': 'jumpauth',
                         'username': config.username,
                         'password': password,
                         'grant_type': 'password'}
    auth_url = get_auth_url(config)
    auth_response = requests.post(auth_url, auth_request_data)

    if auth_response.status_code not in [200, 201]:
        log.info("Authentication failed: {0}".
                 format(auth_response.json().get("error")))
        auth_response.raise_for_status()
    else:
        log.info("Authentication OK!")

    # TODO bail out if there was no access token in the answer
    access_token = auth_response.json()['access_token']
    info("Access token was received.")
    verbose("Access token is:\n'{0}'".format(access_token))
    return access_token
예제 #6
0
def obtain_access_token(config, password):
    info("Will now attempt to obtain an JWT...")
    auth_request_data = {
        'client_id': 'jumpauth',
        'username': config.username,
        'password': password,
        'grant_type': 'password'
    }
    auth_url = get_auth_url(config)
    auth_response = requests.post(auth_url, auth_request_data)

    if auth_response.status_code not in [200, 201]:
        log.info("Authentication failed: {0}".format(
            auth_response.json().get("error")))
        auth_response.raise_for_status()
    else:
        log.info("Authentication OK!")

    # TODO bail out if there was no access token in the answer
    access_token = auth_response.json()['access_token']
    info("Access token was received.")
    verbose("Access token is:\n'{0}'".format(access_token))
    return access_token
예제 #7
0
 def read(ctx, param, value):
     config = ctx.ensure_object(CBASConfig)
     config_path = os.path.expanduser(value)
     if os.path.exists(config_path):
         verbose("Config path is: {0}".format(config_path))
         loaded_config = config.load_config(config_path)
         config.validate_options(loaded_config)
         verbose("Loaded values from config file are:\n{0}".
                 format(pp.pformat(loaded_config)))
         config.inject(loaded_config)
         verbose("Processed config after loading:\n{0}".format(config))
     return config
예제 #8
0
 def __init__(self):
     for option, default in self.options.items():
         self[option] = (default()
                         if hasattr(default, '__call__') else default)
     verbose("Default config is:\n{0}".format(self))
예제 #9
0
 def __init__(self):
     for option, default in self.options.items():
         self[option] = (default()
                         if hasattr(default, '__call__')
                         else default)
     verbose("Default config is:\n{0}".format(self))