Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add plugin API to customize custodia client CLI #239

Open
tiran opened this issue Jan 11, 2018 · 1 comment
Open

Add plugin API to customize custodia client CLI #239

tiran opened this issue Jan 11, 2018 · 1 comment
Assignees

Comments

@tiran
Copy link
Member

tiran commented Jan 11, 2018

Custodia has plugins for store, authn and authz but no plugins to modify the behavior of custodia.cli. Rather than baking features like #238 directly into the CLI, Custodia should have an API to allow customization of CLI. I'm thinking about a similar approach as https://docs.pytest.org/en/latest/writing_plugins.html

Any package can provide a CLI plugin as custodia.cli entry point.

API draft

class CustodiaCLIPlugin(object):
    name = 'gssapi'
    priority = 100
    title = 'GSSAPI authentication'
    description = None

    def __init__(self, parser, subparsers):
        """Init
        
        :param parser: argparse Parser instance 
        :param subparsers: subparser instance 
        """
        self.parser = parser
        self.subparsers = subparsers

    def add_arguments(self):
        """Add argparse arguments

        :param group: argparse Parser group
        :return: None
        """
        group = self.parser.add_argument_group(
            self.title, self.description
        )
        group.add_argument(
           '--gssapi', action='store_true',
            help='Use Negotiate / GSSAPI auth'
        )

    def validate_arguments(self, args):
        """Validate arguments after parsing
        
        :param args: namespace from parser.parse_args(...)
        :return: None
        """
        if args.gssapi and args.certfile:
            self.parser.error(
                "gssapi and certfile are mutually exclusive.\n"
            )
        if args.gssapi and requests_gssapi is None:
            self.parser.error(
                "'requests_gssapi' package is not available! You can "
                "install it with: 'pip install custodia[gssapi]'.\n"
            )

    def create_client(self, args):
        """Create custodia client instance
        
        Plugins are sorted by priority and name. The first plugin that
        returns a client instance wins.
        
        :param args: namespace from parser.parse_args(...)
        :return: None or instance of CustodiaHTTPClient subclass
        """

    def update_client(self, args, client):
        """Update client with settings
        
        :param args: namespace from parser.parse_args(...) 
        :param client: Custodia client instance 
        :return: 
        """
        if args.gssapi:
            client.set_gssapi_auth()
@simo5
Copy link
Member

simo5 commented Jan 17, 2018

SGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants