Example #1
0
def manual_login_success(token, username, password):
    if token:
        # Login using authentication token
        floyd_logger.info(
            "Please paste the authentication token from %s/settings/security.",
            floyd.floyd_web_host)
        access_token = click.prompt(
            'This is an invisible field. Paste token and press ENTER',
            type=str,
            hide_input=True)
        access_token = access_token.strip()

        if not access_token:
            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

    elif username or password:
        access_token = get_access_code_from_password(username, password)
    else:
        return False

    user = AuthClient().get_user(access_token)
    AuthConfigManager.set_access_token(
        AccessToken(username=user.username, token=access_token))
    floyd_logger.info("Login Successful as %s", user.username)
    return True
Example #2
0
def login(token):
    """
    Log into Floyd via Auth0.
    """
    if not token:
        cli_info_url = "{}/settings/security".format(floyd.floyd_web_host)
        click.confirm(
            'Authentication token page will now open in your browser. Continue?',
            abort=True,
            default=True)

        webbrowser.open(cli_info_url)

    floyd_logger.info("Please copy and paste the authentication token.")
    access_code = click.prompt(
        'This is an invisible field. Paste token and press ENTER',
        type=str,
        hide_input=True)

    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(" ")
    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)
 def test_auth_config(self, sys_exit, expanduser):
     import base64
     from floyd.model.access_token import assert_token_not_expired, AccessToken
     expanduser.return_value = '/tmp/.floydconfig'
     mock_token = 'a.' + base64.b64encode('{"exp": 1}'.encode('ascii')).decode('ascii') + '.c'
     access_token = AccessToken('foo', mock_token)
     AuthConfigManager.set_access_token(access_token)
     assert AuthConfigManager.get_access_token().token == mock_token
Example #4
0
def login(token, username, password):
    """
    Log into Floyd via Auth0.
    """
    if username:
        # Use username / password login
        if not password:
            password = click.prompt('Please enter your 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

    else:
        # Fallback to the access token from the browser login
        if not token:
            cli_info_url = "{}/settings/security".format(floyd.floyd_web_host)
            click.confirm(
                'Authentication token page will now open in your browser. Continue?',
                abort=True,
                default=True)
            webbrowser.open(cli_info_url)

        floyd_logger.info("Please copy and paste the authentication token.")
        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(" ")

    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)
Example #5
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)
Example #6
0
def login():
    """
    Log into Floyd via Auth0.
    """
    cli_info_url = "{}/cli".format(floyd.floyd_web_host)
    click.confirm('Access token page will now open in your browser. Continue?', abort=True, default=True)

    webbrowser.open(cli_info_url)
    access_code = click.prompt('Please paste the code here', type=str, hide_input=True)

    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")