예제 #1
0
    def add_arguments(self, parser: CommandParser) -> None:
        class SubCommandParser(CommandParser):
            def __init__(self, **kwargs: Any) -> None:
                super().__init__(**kwargs)

        subparsers = parser.add_subparsers(
            dest='scmd',
            title="subcommands",
            parser_class=SubCommandParser
        )  # type: argparse._SubParsersAction

        inst_sp = subparsers.add_parser("install", help="Create stored procedure API in the database")
        grant_sp = subparsers.add_parser("grant", help="Grant access to the stored procedure API to a database user")
        grant_sp.add_argument(
            "user", nargs="+",
            help="The names of the database users to grant access to the stored procedures. 'install' must have been "
                 "called before and the users must already have been created in PostgreSQL"
        )
        revoke_sp = subparsers.add_parser("revoke", help="Revoke access to the stored procedure API from a database "
                                                         "user")
        revoke_sp.add_argument("user", nargs="+", action="append", default=[],
                               help="The names of the database users to revoke access from")
        check_sp = subparsers.add_parser("check", help="Check whether the spapi is installed or a user as access")
        check_sp_g = check_sp.add_mutually_exclusive_group(required=True)
        check_sp_g.add_argument("--installed", dest="check_installed", action="store_true", default=False)
        check_sp_g.add_argument("--grant", dest="user", type=str)
예제 #2
0
파일: group.py 프로젝트: yopiti/authserver
    def add_arguments(self, parser: CommandParser) -> None:
        class SubCommandParser(CommandParser):
            def __init__(self, **kwargs: Any) -> None:
                super().__init__(**kwargs)

        subparsers = parser.add_subparsers(
            dest='scmd', title="subcommands",
            parser_class=SubCommandParser)  # type: argparse._SubParsersAction

        create_sp = subparsers.add_parser("create", help="Create user groups")
        create_sp.add_argument("groupname",
                               help="The name of the group to create")

        list_sp = subparsers.add_parser("list")
        list_sp.add_argument("--format",
                             dest="format",
                             choices=["json", "table"],
                             default="table",
                             help="The output format for the results")

        remove_sp = subparsers.add_parser("remove", help="Remove user group")
        remove_sp.add_argument("groupname", help="The group's UUID or name")
예제 #3
0
    def add_arguments(self, parser: CommandParser) -> None:
        class SubCommandParser(CommandParser):
            def __init__(self, **kwargs: Any) -> None:
                super().__init__(**kwargs)

        subparsers = parser.add_subparsers(
            dest='scmd', title="subcommands",
            parser_class=SubCommandParser)  # type: argparse._SubParsersAction

        domain_create = subparsers.add_parser("create",
                                              help="Create domain entries")
        domain_create.add_argument(
            "--jwt-allow-subdomain-signing",
            dest="jwt_allow_subdomain_signing",
            action="store_true",
            default=False,
            help="Allow this domain's JWT signing key to be used for subdomains"
        )
        domain_create.add_argument(
            "--redirect-all-email-to",
            dest="redirect_to",
            metavar="FQDN",
            default="",
            help="Redirect all email sent to this domain to FQDN")
        domain_create.add_argument(
            "--create-key",
            dest="create_keys",
            choices=KEY_CHOICES,
            action="append",
            default=[],
            help="Create these keys when creating the domain")
        domain_create.add_argument(
            "--dkim-selector",
            dest="dkim_selector",
            default="",
            help=
            "The DKIM selector to print in the DKIM records (for the pubkey command, for "
            "example)")
        domain_create.add_argument("domain",
                                   nargs="?",
                                   help="The domain name to create as FQDN")

        domain_remove = subparsers.add_parser("remove",
                                              help="Remove domain entries")
        domain_remove.add_argument(
            "--remove-multiple",
            dest="delete_multiple",
            action="store_true",
            default=False,
            help="If multiple domains are matched, remove all of them")
        domain_remove.add_argument(
            "--yes",
            dest="approved",
            action="store_true",
            default=False,
            help="Do not ask for confirmation on removal")
        domain_remove.add_argument(
            "contains", help="A string matching the domain(s) to remove")

        domain_pubkey = subparsers.add_parser("pubkey",
                                              help="Export public keys")
        domain_pubkey.add_argument("--key",
                                   dest="key",
                                   choices=KEY_CHOICES,
                                   default="jwt",
                                   help="Choose which domain key to export")
        domain_pubkey.add_argument(
            "--create-key",
            dest="create_key",
            default=False,
            action="store_true",
            help="Create key on domain if it doesn't exist yet (Default: False)"
        )
        domain_pubkey.add_argument(
            "--format",
            choices=["dkimdns", "pem"],
            default="pem",
            help=
            "The output format: either 'dkimdns' or 'pem' (Default: 'pem'). 'dkimdns' is "
            "suitable for being added to a DNS TXT entry")
        domain_pubkey.add_argument("-o",
                                   "--output",
                                   dest="output",
                                   default="-",
                                   help="Output filename (or '-' for stdout)")
        domain_pubkey.add_argument(
            "domain", nargs="?", help="The domain to export public keys from")

        domain_list = subparsers.add_parser("list", help="List domains")
        domain_list.add_argument(
            "--include-parent-domain",
            dest="include_parent_domain",
            action="store_true",
            default=False,
            help="Return a parent domain if such a domain exists")
        domain_list.add_argument("--format",
                                 dest="format",
                                 choices=["json", "list"],
                                 default="list",
                                 help="The output format for the results")
        domain_list.add_argument(
            "--no-require-subdomain-signing",
            dest="require_jwt_subdomains",
            action="store_false",
            default=True,
            help=
            "Find parent domains even if they can't sign for subdomains. By default this "
            "command will only list domains that can sign for subdomains if "
            "--include-parent-domain is set.")
        domain_list.add_argument("contains",
                                 nargs="?",
                                 help="Filter list by this string")

        domain_edit = subparsers.add_parser("edit", help="Edit domains")
        domain_edit.add_argument(
            "--jwt-allow-subdomain-signing",
            dest="jwt_allow_subdomain_signing",
            choices=["true", "false"],
            default="true",
            help=
            "Allow or disallow this domain's JWT signing key to be used for subdomains"
        )
        domain_edit.add_argument(
            "--redirect-all-email-to",
            dest="redirect_to",
            metavar="FQDN",
            help="Redirect all email sent to this domain to FQDN")
        domain_edit.add_argument(
            "--remove-key",
            dest="remove_keys",
            choices=KEY_CHOICES,
            action="append",
            default=[],
            help=
            "Remove these keys from the domain (can't be used together with --create-key)"
        )
        domain_edit.add_argument(
            "--create-key",
            dest="create_keys",
            choices=KEY_CHOICES,
            action="append",
            default=[],
            help=
            "Create these keys on the domain (can't be used together with --remove-key)"
        )
        domain_edit.add_argument(
            "--dkim-selector",
            dest="dkim_selector",
            default="",
            help=
            "The DKIM selector to print in the DKIM records (for the pubkey command, for "
            "example)")
        domain_edit.add_argument(
            "--overwrite",
            dest="overwrite",
            default=False,
            action="store_true",
            help="Overwrite existing values (like keys on --create-key)")
        domain_edit.add_argument("domain",
                                 nargs="?",
                                 help="The domain to edit as FQDN")
예제 #4
0
    def add_arguments(self, parser: CommandParser) -> None:
        class SubCommandParser(CommandParser):
            def __init__(self, **kwargs: Any) -> None:
                super().__init__(**kwargs)

        subparsers = parser.add_subparsers(
            dest='scmd', title="subcommands",
            parser_class=SubCommandParser)  # type: argparse._SubParsersAction

        create_sp = subparsers.add_parser(
            "create", help="Create application permissions")
        create_sp.add_argument(
            "--name",
            dest="name",
            required=True,
            help="The human-readable name for this permission")
        create_sp.add_argument(
            "scope",
            help=
            "The scope string to use in JWT claims and OAuth2 for this permission"
        )

        list_sp = subparsers.add_parser("list",
                                        help="List application permissions")
        list_sp.add_argument(
            "--filter-scope",
            dest="filter_scope",
            metavar="CONTAINS",
            help="Filter the list for permissions containing this string")
        list_sp.add_argument(
            "--filter-name",
            dest="filter_name",
            metavar="CONTAINS",
            help="Filter the list for permission names containing this string")
        list_sp.add_argument("--format",
                             dest="format",
                             choices=["json", "table"],
                             default="table",
                             help="The output format for the results")

        remove_sp = subparsers.add_parser(
            "remove", help="Remove application permissions")
        remove_sp.add_argument("scope", help="The scope name to be removed")

        grant_menu = subparsers.add_parser(
            "grant", help="Grant application permission to an user or group")
        sps_grant = grant_menu.add_subparsers(
            dest='gcmd', title='grantcommands',
            parser_class=SubCommandParser)  # type: argparse._SubParsersAction
        grant_usp = sps_grant.add_parser(
            "user", help="Grant application permission to an user")
        grant_usp.add_argument(
            "userid",
            help="The user identifier or name to add the permission to")
        grant_usp.add_argument("perms",
                               nargs="+",
                               help="The permission to add to the user")
        grant_gsp = sps_grant.add_parser(
            "group", help="Grant application permission to a group")
        grant_gsp.add_argument(
            "groupid", help="The group id or name to add the permission to")
        grant_gsp.add_argument("perms",
                               nargs="+",
                               help="The permission to add to the group")
        grant_msp = sps_grant.add_parser(
            "membership", help="Grant group membership to a user")
        grant_msp.add_argument(
            "userid",
            help="The user identifier UUID or name to add to the groups")
        grant_msp.add_argument("groups",
                               nargs="+",
                               help="Group IDs or names to add the user into")

        revoke_menu = subparsers.add_parser(
            "revoke",
            help="Revoke application permission from an user or group")
        sps_revoke = revoke_menu.add_subparsers(
            dest='rcmd', title='revokecommands',
            parser_class=SubCommandParser)  # type: argparse._SubParsersAction
        revoke_usp = sps_revoke.add_parser(
            "user", help="Revoke application permission from an user")
        revoke_usp.add_argument("--all",
                                dest="revoke_all",
                                action="store_true",
                                help="Revoke all permissions from an user")
        revoke_usp.add_argument(
            "userid",
            help=
            "The user identifier UUID or name whose permission is being revoked"
        )
        revoke_usp.add_argument("perms",
                                nargs="*",
                                help="The permissions to remove from the user")
        revoke_gsp = sps_revoke.add_parser(
            "group", help="Revoke application permission from a group")
        revoke_gsp.add_argument("--all",
                                dest="revoke_all",
                                action="store_true",
                                help="Revoke all permissions from a group")
        revoke_gsp.add_argument(
            "groupid",
            help="The group id or name whose permission is being revoked")
        revoke_gsp.add_argument(
            "perms",
            nargs="*",
            help="The permissions to remove from the group")
        revoke_msp = sps_revoke.add_parser(
            "membership", help="Revoke group membership from an user")
        revoke_msp.add_argument("--all",
                                dest="revoke_all",
                                action="store_true",
                                help="Revoke all permissions from a group")
        revoke_msp.add_argument(
            "userid",
            help="The user identifier UUID or name to remove from the groups")
        revoke_msp.add_argument(
            "groups",
            nargs="+",
            help="Group UUIDs or names to remove the user from")

        require_menu = subparsers.add_parser(
            "require",
            help="Require application permissions for an application")
        require_menu.add_argument(
            "client_name",
            help="The client_name of the application. Must have been previously "
            "created using 'manage.py oauth2 create'")
        require_menu.add_argument(
            "perms",
            nargs="+",
            help="The permissions to require for this application")

        drop_menu = subparsers.add_parser(
            "drop",
            help="Drop required application permissions from an "
            "application")
        drop_menu.add_argument(
            "client_name",
            help="The client_name of the application. Must have been previously "
            "created using 'manage.py oauth2 create'")
        drop_menu.add_argument(
            "perms",
            nargs="+",
            help="The required permissions to drop from this application")

        show_menu = subparsers.add_parser(
            "show",
            help=
            "Show permissions for users, groups or required permissions for "
            "applications")
        sps_show = show_menu.add_subparsers(
            dest='showcmd',
            title='showcommands',
            parser_class=SubCommandParser)  # type: argparse._SubParsersAction
        show_usp = sps_show.add_parser("user",
                                       help="Show permissions for an user")
        show_usp.add_argument("--format",
                              dest="format",
                              choices=["json", "table"],
                              default="table",
                              help="The output format for the results")
        show_usp.add_argument(
            "userid", help="The user identifier to show permissions for")
        show_gsp = sps_show.add_parser("group",
                                       help="Show permissions for a group")
        show_gsp.add_argument("--format",
                              dest="format",
                              choices=["json", "table"],
                              default="table",
                              help="The output format for the results")
        show_gsp.add_argument(
            "groupid", help="The group identifier to show permissions for")
        show_csp = sps_show.add_parser(
            "application", help="Show required permissions for an application")
        show_csp.add_argument("--format",
                              dest="format",
                              choices=["json", "table"],
                              default="table",
                              help="The output format for the results")
        show_csp.add_argument(
            "client_name",
            help="The client_name of the application. Must have been previously "
            "created using 'manage.py oauth2 create'")
        show_msp = sps_show.add_parser(
            "membership", help="Show group memberships for an user")
        show_msp.add_argument("--format",
                              dest="format",
                              choices=["json", "table"],
                              default="table",
                              help="The output format for the results")
        show_msp.add_argument("userid",
                              help="The user to show group memberships for")