Beispiel #1
0
    def __init__(self):
        # Set up of endpoints is delayed until program is run.
        self.client = None

        # Set up the main parser.
        self.parser = argparse.ArgumentParser(description=CLI_DESCRIPTION)

        # Set up general program options.
        self.parser.add_argument(
            '--version',
            action='version',
            version='%(prog)s {version}, on Python {python_major}.{python_minor}.{python_patch}'
                    .format(version=get_stackstorm_version(),
                            python_major=sys.version_info.major,
                            python_minor=sys.version_info.minor,
                            python_patch=sys.version_info.micro))

        self.parser.add_argument(
            '--url',
            action='store',
            dest='base_url',
            default=None,
            help='Base URL for the API servers. Assumes all servers use the '
                 'same base URL and default ports are used. Get ST2_BASE_URL '
                 'from the environment variables by default.'
        )

        self.parser.add_argument(
            '--auth-url',
            action='store',
            dest='auth_url',
            default=None,
            help='URL for the authentication service. Get ST2_AUTH_URL '
                 'from the environment variables by default.'
        )

        self.parser.add_argument(
            '--api-url',
            action='store',
            dest='api_url',
            default=None,
            help='URL for the API server. Get ST2_API_URL '
                 'from the environment variables by default.'
        )

        self.parser.add_argument(
            '--stream-url',
            action='store',
            dest='stream_url',
            default=None,
            help='URL for the stream endpoint. Get ST2_STREAM_URL'
                 'from the environment variables by default.'
        )

        self.parser.add_argument(
            '--api-version',
            action='store',
            dest='api_version',
            default=None,
            help='API version to use. Get ST2_API_VERSION '
                 'from the environment variables by default.'
        )

        self.parser.add_argument(
            '--cacert',
            action='store',
            dest='cacert',
            default=None,
            help='Path to the CA cert bundle for the SSL endpoints. '
                 'Get ST2_CACERT from the environment variables by default. '
                 'If this is not provided, then SSL cert will not be verified.'
        )

        self.parser.add_argument(
            '--config-file',
            action='store',
            dest='config_file',
            default=None,
            help='Path to the CLI config file'
        )

        self.parser.add_argument(
            '--print-config',
            action='store_true',
            dest='print_config',
            default=False,
            help='Parse the config file and print the values'
        )

        self.parser.add_argument(
            '--skip-config',
            action='store_true',
            dest='skip_config',
            default=False,
            help='Don\'t parse and use the CLI config file'
        )

        self.parser.add_argument(
            '--debug',
            action='store_true',
            dest='debug',
            default=False,
            help='Enable debug mode'
        )

        # Set up list of commands and subcommands.
        self.subparsers = self.parser.add_subparsers(dest='parser')
        self.subparsers.required = True
        self.commands = {}

        self.commands['run'] = action.ActionRunCommand(
            models.Action, self, self.subparsers, name='run', add_help=False)

        self.commands['action'] = action.ActionBranch(
            'An activity that happens as a response to the external event.',
            self, self.subparsers)

        self.commands['action-alias'] = action_alias.ActionAliasBranch(
            'Action aliases.',
            self, self.subparsers)

        self.commands['auth'] = auth.TokenCreateCommand(
            models.Token, self, self.subparsers, name='auth')

        self.commands['login'] = auth.LoginCommand(
            models.Token, self, self.subparsers, name='login')

        self.commands['whoami'] = auth.WhoamiCommand(
            models.Token, self, self.subparsers, name='whoami')

        self.commands['api-key'] = auth.ApiKeyBranch(
            'API Keys.',
            self, self.subparsers)

        self.commands['execution'] = action.ActionExecutionBranch(
            'An invocation of an action.',
            self, self.subparsers)

        self.commands['inquiry'] = inquiry.InquiryBranch(
            'Inquiries provide an opportunity to ask a question '
            'and wait for a response in a workflow.',
            self, self.subparsers)

        self.commands['key'] = keyvalue.KeyValuePairBranch(
            'Key value pair is used to store commonly used configuration '
            'for reuse in sensors, actions, and rules.',
            self, self.subparsers)

        self.commands['pack'] = pack.PackBranch(
            'A group of related integration resources: '
            'actions, rules, and sensors.',
            self, self.subparsers)

        self.commands['policy'] = policy.PolicyBranch(
            'Policy that is enforced on a resource.',
            self, self.subparsers)

        self.commands['policy-type'] = policy.PolicyTypeBranch(
            'Type of policy that can be applied to resources.',
            self, self.subparsers)

        self.commands['rule'] = rule.RuleBranch(
            'A specification to invoke an "action" on a "trigger" selectively '
            'based on some criteria.',
            self, self.subparsers)

        self.commands['webhook'] = webhook.WebhookBranch(
            'Webhooks.',
            self, self.subparsers)

        self.commands['timer'] = timer.TimerBranch(
            'Timers.',
            self, self.subparsers)

        self.commands['runner'] = resource.ResourceBranch(
            models.RunnerType,
            'Runner is a type of handler for a specific class of actions.',
            self, self.subparsers, read_only=True, has_disable=True)

        self.commands['sensor'] = sensor.SensorBranch(
            'An adapter which allows you to integrate StackStorm with external system.',
            self, self.subparsers)

        self.commands['trace'] = trace.TraceBranch(
            'A group of executions, rules and triggerinstances that are related.',
            self, self.subparsers)

        self.commands['trigger'] = trigger.TriggerTypeBranch(
            'An external event that is mapped to a st2 input. It is the '
            'st2 invocation point.',
            self, self.subparsers)

        self.commands['trigger-instance'] = triggerinstance.TriggerInstanceBranch(
            'Actual instances of triggers received by st2.',
            self, self.subparsers)

        self.commands['rule-enforcement'] = rule_enforcement.RuleEnforcementBranch(
            'Models that represent enforcement of rules.',
            self, self.subparsers)

        self.commands['workflow'] = workflow.WorkflowBranch(
            'Commands for workflow authoring related operations. '
            'Only orquesta workflows are supported.',
            self, self.subparsers)

        # RBAC
        self.commands['role'] = rbac.RoleBranch(
            'RBAC roles.',
            self, self.subparsers)
        self.commands['role-assignment'] = rbac.RoleAssignmentBranch(
            'RBAC role assignments.',
            self, self.subparsers)
Beispiel #2
0
    def __init__(self):
        # Set up of endpoints is delayed until program is run.
        self.client = None

        # Set up the main parser.
        self.parser = argparse.ArgumentParser(description=CLI_DESCRIPTION)

        # Set up general program options.
        self.parser.add_argument(
            "--version",
            action="version",
            version="%(prog)s {version}, on Python {python_major}.{python_minor}.{python_patch}".format(
                version=get_stackstorm_version(),
                python_major=sys.version_info.major,
                python_minor=sys.version_info.minor,
                python_patch=sys.version_info.micro,
            ),
        )

        self.parser.add_argument(
            "--url",
            action="store",
            dest="base_url",
            default=None,
            help="Base URL for the API servers. Assumes all servers use the "
            "same base URL and default ports are used. Get ST2_BASE_URL "
            "from the environment variables by default.",
        )

        self.parser.add_argument(
            "--auth-url",
            action="store",
            dest="auth_url",
            default=None,
            help="URL for the authentication service. Get ST2_AUTH_URL "
            "from the environment variables by default.",
        )

        self.parser.add_argument(
            "--api-url",
            action="store",
            dest="api_url",
            default=None,
            help="URL for the API server. Get ST2_API_URL "
            "from the environment variables by default.",
        )

        self.parser.add_argument(
            "--stream-url",
            action="store",
            dest="stream_url",
            default=None,
            help="URL for the stream endpoint. Get ST2_STREAM_URL"
            "from the environment variables by default.",
        )

        self.parser.add_argument(
            "--api-version",
            action="store",
            dest="api_version",
            default=None,
            help="API version to use. Get ST2_API_VERSION "
            "from the environment variables by default.",
        )

        self.parser.add_argument(
            "--cacert",
            action="store",
            dest="cacert",
            default=None,
            help="Path to the CA cert bundle for the SSL endpoints. "
            "Get ST2_CACERT from the environment variables by default. "
            "If this is not provided, then SSL cert will not be verified.",
        )

        self.parser.add_argument(
            "--config-file",
            action="store",
            dest="config_file",
            default=None,
            help="Path to the CLI config file",
        )

        self.parser.add_argument(
            "--print-config",
            action="store_true",
            dest="print_config",
            default=False,
            help="Parse the config file and print the values",
        )

        self.parser.add_argument(
            "--skip-config",
            action="store_true",
            dest="skip_config",
            default=False,
            help="Don't parse and use the CLI config file",
        )

        self.parser.add_argument(
            "--debug",
            action="store_true",
            dest="debug",
            default=False,
            help="Enable debug mode",
        )

        # Set up list of commands and subcommands.
        self.subparsers = self.parser.add_subparsers(dest="parser")
        self.subparsers.required = True
        self.commands = {}

        self.commands["run"] = action.ActionRunCommand(
            models.Action, self, self.subparsers, name="run", add_help=False
        )

        self.commands["action"] = action.ActionBranch(
            "An activity that happens as a response to the external event.",
            self,
            self.subparsers,
        )

        self.commands["action-alias"] = action_alias.ActionAliasBranch(
            "Action aliases.", self, self.subparsers
        )

        self.commands["auth"] = auth.TokenCreateCommand(
            models.Token, self, self.subparsers, name="auth"
        )

        self.commands["login"] = auth.LoginCommand(
            models.Token, self, self.subparsers, name="login"
        )

        self.commands["whoami"] = auth.WhoamiCommand(
            models.Token, self, self.subparsers, name="whoami"
        )

        self.commands["api-key"] = auth.ApiKeyBranch("API Keys.", self, self.subparsers)

        self.commands["execution"] = action.ActionExecutionBranch(
            "An invocation of an action.", self, self.subparsers
        )

        self.commands["inquiry"] = inquiry.InquiryBranch(
            "Inquiries provide an opportunity to ask a question "
            "and wait for a response in a workflow.",
            self,
            self.subparsers,
        )

        self.commands["key"] = keyvalue.KeyValuePairBranch(
            "Key value pair is used to store commonly used configuration "
            "for reuse in sensors, actions, and rules.",
            self,
            self.subparsers,
        )

        self.commands["pack"] = pack.PackBranch(
            "A group of related integration resources: " "actions, rules, and sensors.",
            self,
            self.subparsers,
        )

        self.commands["policy"] = policy.PolicyBranch(
            "Policy that is enforced on a resource.", self, self.subparsers
        )

        self.commands["policy-type"] = policy.PolicyTypeBranch(
            "Type of policy that can be applied to resources.", self, self.subparsers
        )

        self.commands["rule"] = rule.RuleBranch(
            'A specification to invoke an "action" on a "trigger" selectively '
            "based on some criteria.",
            self,
            self.subparsers,
        )

        self.commands["webhook"] = webhook.WebhookBranch(
            "Webhooks.", self, self.subparsers
        )

        self.commands["timer"] = timer.TimerBranch("Timers.", self, self.subparsers)

        self.commands["runner"] = resource.ResourceBranch(
            models.RunnerType,
            "Runner is a type of handler for a specific class of actions.",
            self,
            self.subparsers,
            read_only=True,
            has_disable=True,
        )

        self.commands["sensor"] = sensor.SensorBranch(
            "An adapter which allows you to integrate StackStorm with external system.",
            self,
            self.subparsers,
        )

        self.commands["trace"] = trace.TraceBranch(
            "A group of executions, rules and triggerinstances that are related.",
            self,
            self.subparsers,
        )

        self.commands["trigger"] = trigger.TriggerTypeBranch(
            "An external event that is mapped to a st2 input. It is the "
            "st2 invocation point.",
            self,
            self.subparsers,
        )

        self.commands["trigger-instance"] = triggerinstance.TriggerInstanceBranch(
            "Actual instances of triggers received by st2.", self, self.subparsers
        )

        self.commands["rule-enforcement"] = rule_enforcement.RuleEnforcementBranch(
            "Models that represent enforcement of rules.", self, self.subparsers
        )

        self.commands["workflow"] = workflow.WorkflowBranch(
            "Commands for workflow authoring related operations. "
            "Only orquesta workflows are supported.",
            self,
            self.subparsers,
        )

        # Service Registry
        self.commands["service-registry"] = service_registry.ServiceRegistryBranch(
            "Service registry group and membership related commands.",
            self,
            self.subparsers,
        )

        # RBAC
        self.commands["role"] = rbac.RoleBranch("RBAC roles.", self, self.subparsers)
        self.commands["role-assignment"] = rbac.RoleAssignmentBranch(
            "RBAC role assignments.", self, self.subparsers
        )