def init(ctx: Context, author: str): """Initialize your AEA configurations.""" config = _get_or_create_cli_config() if config.get(AUTHOR, None) is None: is_not_valid_author = True if author is not None and _is_validate_author_handle(author): is_not_valid_author = False while is_not_valid_author: author = click.prompt( "Please enter the author handle you would like to use", type=str) if _is_validate_author_handle(author): is_not_valid_author = False else: click.echo( "Not a valid author handle. Please try again. Author handles must satisfy the following regex: {}" .format(PublicId.AUTHOR_REGEX)) _update_cli_config({AUTHOR: author}) config = _get_or_create_cli_config() success_msg = "AEA configurations successfully initialized: {}".format( config) else: success_msg = "AEA configurations already initialized: {}".format( config) click.echo(AEA_LOGO + "v" + __version__ + "\n") click.echo(success_msg)
def do_init(author: str, reset: bool, registry: bool) -> None: """ Initialize your AEA configurations. :param author: str author username. :param reset: True, if resetting the author name :param registry: True, if registry is used :return: None. """ config = _get_or_create_cli_config() if reset or config.get(AUTHOR, None) is None: author = validate_author_name(author) if registry: _registry_init(username=author) _update_cli_config({AUTHOR: author}) config = _get_or_create_cli_config() config.pop(AUTH_TOKEN_KEY, None) # for security reasons success_msg = "AEA configurations successfully initialized: {}".format( config) else: config.pop(AUTH_TOKEN_KEY, None) # for security reasons success_msg = "AEA configurations already initialized: {}. To reset use '--reset'.".format( config) click.echo(AEA_LOGO + "v" + __version__ + "\n") click.echo(success_msg)
def do_login(username: str, password: str): """ Login to Registry account and save auth token in config. :param username: str username. :param password: str password. :return: None """ click.echo("Signing in as {}...".format(username)) token = registry_login(username, password) _update_cli_config({AUTH_TOKEN_KEY: token}) click.echo("Successfully signed in: {}.".format(username))
def do_register( username: str, email: str, password: str, password_confirmation: str ) -> None: """ Register a new Registry account and save auth token. :param username: str username. :param email: str email. :param password: str password. :param password_confirmation: str password confirmation. :return: None """ username = validate_author_name(username) token = register_new_account(username, email, password, password_confirmation) _update_cli_config({AUTH_TOKEN_KEY: token}) click.echo("Successfully registered and logged in: {}".format(username))
def login(username, password): """Login to Registry account.""" click.echo("Signing in as {}...".format(username)) token = registry_login(username, password) _update_cli_config({AUTH_TOKEN_KEY: token}) click.echo("Successfully signed in: {}.".format(username))
def logout(): """Logout from Registry account.""" click.echo("Logging out...") registry_logout() _update_cli_config({AUTH_TOKEN_KEY: None}) click.echo("Successfully logged out.")
def test_update_cli_config_positive(self, dump_mock, icf_mock): """Test for _update_cli_config method positive result.""" _update_cli_config({"some": "config"}) icf_mock.assert_called_once() dump_mock.assert_called_once()