def login(): """Login with your Ubuntu One e-mail address and password. If you do not have an Ubuntu One account, you can create one at https://dashboard.snapcraft.io/openid/login """ if not snapcraft.login(): sys.exit(1)
def export_login(login_file: TextIO, snaps: str, channels: str, acls: str, expires: str): """Save login configuration for a store account in FILE. This file can then be used to log in to the given account with the specified permissions. For example, to limit access to the edge channel of any snap the account can access: snapcraft export-login --channels=edge exported Or to limit access to only the edge channel of a single snap: snapcraft export-login --snaps=my-snap --channels=edge exported To limit access to a single snap, but only until 2019: snapcraft export-login --expires="2019-01-01T00:00:00" exported """ snap_list = None channel_list = None acl_list = None if snaps: snap_list = [] for package in snaps.split(','): snap_list.append({'name': package, 'series': '16'}) if channels: channel_list = channels.split(',') if acls: acl_list = acls.split(',') store = storeapi.StoreClient() if not snapcraft.login(store=store, packages=snap_list, channels=channel_list, acls=acl_list, expires=expires, save=False): sys.exit(1) store.conf.save(config_fd=login_file) print() echo.info( dedent("""\ Login successfully exported to {0!r}. This file can now be used with 'snapcraft login --with {0}' to log in to this account with no password and have these capabilities:\n""".format(login_file.name))) echo.info(_human_readable_acls(store)) echo.warning( 'This exported login is not encrypted. Do not commit it to version ' 'control!')
def login(login_file, experimental_login: bool): """Login with your Ubuntu One e-mail address and password. If you do not have an Ubuntu One account, you can create one at https://snapcraft.io/account """ store_client = storeapi.StoreClient(use_candid=experimental_login) if store_client.use_candid: store_client.login(config_fd=login_file, save=True) else: snapcraft.login(store=store_client, config_fd=login_file) print() if login_file: try: human_acls = _human_readable_acls(store_client) echo.info("Login successful. You now have these capabilities:\n") echo.info(human_acls) except NotImplementedError: echo.info("Login successful.") else: echo.info("Login successful.")
def login(login_file): """Login with your Ubuntu One e-mail address and password. If you do not have an Ubuntu One account, you can create one at https://dashboard.snapcraft.io/openid/login """ store = storeapi.StoreClient() if not snapcraft.login(store=store, config_fd=login_file): sys.exit(1) print() if login_file: echo.info('Login successful. You now have these capabilities:\n') echo.info(_human_readable_acls(store)) else: echo.info('Login successful.')
def login(login_file): """Login with your Ubuntu One e-mail address and password. If you do not have an Ubuntu One account, you can create one at https://dashboard.snapcraft.io/openid/login """ store = storeapi.StoreClient() if not snapcraft.login(store=store, config_fd=login_file): sys.exit(1) print() if login_file: echo.info("Login successful. You now have these capabilities:\n") echo.info(_human_readable_acls(store)) else: echo.info("Login successful.")
def export_login( login_file: str, snaps: str, channels: str, acls: str, expires: str, experimental_login: bool, ): """Save login configuration for a store account in FILE. This file can then be used to log in to the given account with the specified permissions. One can also request the login to be exported to stdout instead of a file: snapcraft export-login - For example, to limit access to the edge channel of any snap the account can access: snapcraft export-login --channels=edge exported Or to limit access to only the edge channel of a single snap: snapcraft export-login --snaps=my-snap --channels=edge exported To limit access to a single snap, but only until 2019: snapcraft export-login --expires="2019-01-01T00:00:00" exported """ snap_list = None channel_list = None acl_list = None if snaps: snap_list = [] for package in snaps.split(","): snap_list.append({"name": package, "series": DEFAULT_SERIES}) if channels: channel_list = channels.split(",") if acls: acl_list = acls.split(",") store_client = storeapi.StoreClient(use_candid=experimental_login) if store_client.use_candid: store_client.login( packages=snap_list, channels=channel_list, acls=acl_list, expires=expires, save=False, ) else: snapcraft.login( store=store_client, packages=snap_list, channels=channel_list, acls=acl_list, expires=expires, save=False, ) # Support a login_file of '-', which indicates a desire to print to stdout if login_file.strip() == "-": echo.info("\nExported login starts on next line:") store_client.export_login(config_fd=sys.stdout, encode=True) print() preamble = "Login successfully exported and printed above" login_action = 'echo "<login>" | snapcraft login --with -' else: # This is sensitive-- it should only be accessible by the owner private_open = functools.partial(os.open, mode=0o600) # mypy doesn't have the opener arg in its stub. Ignore its warning with open(login_file, "w", opener=private_open) as f: # type: ignore store_client.export_login(config_fd=f) # Now that the file has been written, we can just make it # owner-readable os.chmod(login_file, stat.S_IRUSR) preamble = "Login successfully exported to {0!r}".format(login_file) login_action = "snapcraft login --with {0}".format(login_file) print() echo.info( dedent( """\ {}. This can now be used with {} """.format( preamble, login_action ) ) ) try: human_acls = _human_readable_acls(store_client) echo.info( "to log in to this account with no password and have these " f"capabilities:\n{human_acls}" ) except NotImplementedError: pass echo.warning( "This exported login is not encrypted. Do not commit it to version control!" )
def login(): """Authenticate session against Ubuntu One SSO.""" if not snapcraft.login(): sys.exit(1)
def export_login(login_file: str, snaps: str, channels: str, acls: str, expires: str): """Save login configuration for a store account in FILE. This file can then be used to log in to the given account with the specified permissions. One can also request the login to be exported to stdout instead of a file: snapcraft export-login - For example, to limit access to the edge channel of any snap the account can access: snapcraft export-login --channels=edge exported Or to limit access to only the edge channel of a single snap: snapcraft export-login --snaps=my-snap --channels=edge exported To limit access to a single snap, but only until 2019: snapcraft export-login --expires="2019-01-01T00:00:00" exported """ snap_list = None channel_list = None acl_list = None if snaps: snap_list = [] for package in snaps.split(","): snap_list.append({"name": package, "series": "16"}) if channels: channel_list = channels.split(",") if acls: acl_list = acls.split(",") store = storeapi.StoreClient() if not snapcraft.login( store=store, packages=snap_list, channels=channel_list, acls=acl_list, expires=expires, save=False, ): sys.exit(1) # Support a login_file of '-', which indicates a desire to print to stdout if login_file.strip() == "-": echo.info("\nExported login starts on next line:") store.conf.save(config_fd=sys.stdout, encode=True) print() preamble = "Login successfully exported and printed above" login_action = 'echo "<login>" | snapcraft login --with -' else: # This is sensitive-- it should only be accessible by the owner private_open = functools.partial(os.open, mode=0o600) # mypy doesn't have the opener arg in its stub. Ignore its warning with open(login_file, "w", opener=private_open) as f: # type: ignore store.conf.save(config_fd=f) # Now that the file has been written, we can just make it # owner-readable os.chmod(login_file, stat.S_IRUSR) preamble = "Login successfully exported to {0!r}".format(login_file) login_action = "snapcraft login --with {0}".format(login_file) print() echo.info( dedent( """\ {}. This can now be used with {} to log in to this account with no password and have these capabilities:\n""".format( preamble, login_action ) ) ) echo.info(_human_readable_acls(store)) echo.warning( "This exported login is not encrypted. Do not commit it to version control!" )
def export_login(login_file: str, snaps: str, channels: str, acls: str, expires: str): """Save login configuration for a store account in FILE. This file can then be used to log in to the given account with the specified permissions. For example, to limit access to the edge channel of any snap the account can access: snapcraft export-login --channels=edge exported Or to limit access to only the edge channel of a single snap: snapcraft export-login --snaps=my-snap --channels=edge exported To limit access to a single snap, but only until 2019: snapcraft export-login --expires="2019-01-01T00:00:00" exported """ snap_list = None channel_list = None acl_list = None if snaps: snap_list = [] for package in snaps.split(','): snap_list.append({'name': package, 'series': '16'}) if channels: channel_list = channels.split(',') if acls: acl_list = acls.split(',') store = storeapi.StoreClient() if not snapcraft.login(store=store, packages=snap_list, channels=channel_list, acls=acl_list, expires=expires, save=False): sys.exit(1) # This is sensitive-- it should only be accessible by the owner private_open = functools.partial(os.open, mode=0o600) # mypy doesn't have the opener arg in its stub. Ignore its warning with open(login_file, 'w', opener=private_open) as f: # type: ignore store.conf.save(config_fd=f) # Now that the file has been written, we can just make it owner-readable os.chmod(login_file, stat.S_IRUSR) print() echo.info( dedent("""\ Login successfully exported to {0!r}. This file can now be used with 'snapcraft login --with {0}' to log in to this account with no password and have these capabilities:\n""".format(login_file))) echo.info(_human_readable_acls(store)) echo.warning( 'This exported login is not encrypted. Do not commit it to version ' 'control!')