Exemplo n.º 1
0
    def run(self, parsed_args):
        if parsed_args.experimental_login:
            raise ArgumentParsingError(
                "--experimental-login no longer supported. "
                f"Set {store.constants.ENVIRONMENT_STORE_AUTH}=candid instead",
            )

        kwargs: Dict[str, Union[str, int]] = {}
        if parsed_args.snaps:
            kwargs["packages"] = parsed_args.snaps.split(",")
        if parsed_args.channels:
            kwargs["channels"] = parsed_args.channels.split(",")
        if parsed_args.acls:
            kwargs["acls"] = parsed_args.acls.split(",")
        if parsed_args.expires is not None:
            for date_format in _VALID_DATE_FORMATS:
                with contextlib.suppress(ValueError):
                    expiry_date = datetime.strptime(parsed_args.expires,
                                                    date_format)
                    break
            else:
                valid_formats = utils.humanize_list(_VALID_DATE_FORMATS, "or")
                raise ArgumentParsingError(
                    f"The expiry follow an ISO 8601 format ({valid_formats})")

            kwargs["ttl"] = int((expiry_date - datetime.now()).total_seconds())

        credentials = store.StoreClientCLI(ephemeral=True).login(**kwargs)

        # Support a login_file of '-', which indicates a desire to print to stdout
        if parsed_args.login_file.strip() == "-":
            message = f"Exported login credentials:\n{credentials}"
        else:
            # This is sensitive-- it should only be accessible by the owner
            private_open = functools.partial(os.open, mode=0o600)

            with open(parsed_args.login_file,
                      "w",
                      opener=private_open,
                      encoding="utf-8") as login_fd:
                print(credentials, file=login_fd, end="")

            # Now that the file has been written, we can just make it
            # owner-readable
            os.chmod(parsed_args.login_file, stat.S_IRUSR)

            message = f"Exported login credentials to {parsed_args.login_file!r}"

        message += "\n\nThese credentials must be used on Snapcraft 7.0 or greater."
        if os.getenv(store.constants.ENVIRONMENT_STORE_AUTH) == "candid":
            message += (
                f"\nSet '{store.constants.ENVIRONMENT_STORE_AUTH}=candid' for "
                "these credentials to work.")
        emit.message(message)
Exemplo n.º 2
0
    def run(self, parsed_args):
        channels = parsed_args.channels.split(",")

        store.StoreClientCLI().release(
            snap_name=parsed_args.name,
            revision=parsed_args.revision,
            channels=channels,
            progressive_percentage=parsed_args.progressive_percentage,
        )

        humanized_channels = utils.humanize_list(channels, conjunction="and")
        emit.message(f"Released {parsed_args.name!r} "
                     f"revision {parsed_args.revision!r} "
                     f"to channels: {humanized_channels}")
Exemplo n.º 3
0
def test_humanize_list(items, conjunction, expected):
    assert utils.humanize_list(items, conjunction) == expected