Пример #1
0
def login(token, apikey, username, password):
    """
    Log into Floyd via Auth0.
    """
    if apikey:
        user = AuthClient().get_user(apikey, True)
        AuthConfigManager.set_apikey(username=user.username, apikey=apikey)
        floyd_logger.info("Login Successful as %s", user.username)
        return

    elif token:
        # Login using authentication token
        floyd_logger.info(
            "Please paste the authentication token from {}/settings/security.".format(floyd.floyd_web_host))
        access_code = click.prompt('This is an invisible field. Paste token and press ENTER', type=str, hide_input=True)
        access_code = access_code.strip()

        if not access_code:
            floyd_logger.info("Empty token received. Make sure your shell is handling the token appropriately.")
            floyd_logger.info("See docs for help: http://docs.floydhub.com/faqs/authentication/")
            return

        access_code = access_code.strip(" ")

    else:
        # Use username / password login
        floyd_logger.info("Login with your FloydHub username and password to run jobs.")

        if not username:
            username = click.prompt('Username', type=str, default=getpass.getuser())
            username = username.strip()
            if not username:
                floyd_logger.info('You entered an empty string. Please make sure you enter your username correctly.')
                sys.exit(1)

        if not password:
            password = click.prompt('Password', type=str, hide_input=True)
            password = password.strip()
            if not password:
                floyd_logger.info('You entered an empty string. Please make sure you enter your password correctly.')
                sys.exit(1)

        login_credentials = Credentials(username=username,
                                        password=password)
        access_code = AuthClient().login(login_credentials)
        if not access_code:
            floyd_logger.info("Failed to login")
            return

    user = AuthClient().get_user(access_code)
    access_token = AccessToken(username=user.username,
                               token=access_code)
    AuthConfigManager.set_access_token(access_token)
    floyd_logger.info("Login Successful as %s", user.username)
Пример #2
0
def login(token, apikey, username, password):
    """
    Login to FloydHub.
    """
    if manual_login_success(token, username, password):
        return

    if not apikey:
        if has_browser():
            apikey = wait_for_apikey()
        else:
            floyd_logger.error(
                "No browser found, please login manually by creating login key at %s/settings/apikey.",
                floyd.floyd_web_host)
            sys.exit(1)

    if apikey:
        user = AuthClient().get_user(apikey, is_apikey=True)
        AuthConfigManager.set_apikey(username=user.username, apikey=apikey)
        floyd_logger.info("Login Successful as %s", user.username)
    else:
        floyd_logger.error(
            "Login failed, please see --help for other login options.")