Ejemplo n.º 1
0
    def __init__(self, args):
        """
        Initializes global shared properties
        :param args: Arguments passed in from user, collected from ArgParse
        """
        self._profile = None
        self._command_factory = None
        self._setup = None
        self._is_setup_command: bool = FiggyCLI.is_setup_command(args)
        self._utils = Utils(self.get_colors_enabled())
        self._profile = Utils.attr_if_exists(profile, args)
        self._defaults: CLIDefaults = FiggySetup.stc_get_defaults(skip=self._is_setup_command, profile=self._profile)
        self._run_env = self._defaults.run_env
        role_override = Utils.attr_if_exists(role, args)
        self._role: Role = self.get_role(args.prompt, role_override=role_override, is_setup=self._is_setup_command)

        FiggyCLI.validate_environment(self._defaults)

        if not self._is_setup_command:
            if not hasattr(args, 'env') or args.env is None:
                print(f"{EMPTY_ENV_HELP_TEXT}{self._run_env.env}\n")
            else:
                Utils.stc_validate(args.env in self._defaults.valid_envs,
                                   f'{ENV_HELP_TEXT} {self._defaults.valid_envs}. Provided: {args.env}')
                self._run_env = RunEnv(env=args.env)

        self._utils.validate(Utils.attr_exists(configure, args) or Utils.attr_exists(command, args),
                             f"No command found. Proper format is `{CLI_NAME} <resource> <command> --option(s)`")

        self._assumable_role = self.find_assumable_role(self._run_env, self._role, skip=self._is_setup_command,
                                                        profile=self._profile)

        command_name = Utils.attr_if_exists(command, args)
        resource_name = Utils.attr_if_exists(resource, args)

        found_command: CliCommand = Utils.find_command(str(command_name))
        found_resource: CliCommand = Utils.find_resource(str(resource_name))

        self._context: FiggyContext = FiggyContext(self.get_colors_enabled(), found_resource, found_command,
                                                   self._run_env, self._assumable_role, args)
Ejemplo n.º 2
0
    def __init__(self, colors_enabled: bool, resource: CliCommand,
                 command: CliCommand, run_env: RunEnv, role: AssumableRole,
                 args: argparse.Namespace):
        self.colors_enabled = colors_enabled
        self.command: CliCommand = command
        self.resource: CliCommand = resource

        # This enables us to have "commands" without resources. Like `figgy login` instead of `figgy login login`.
        # Makes things a bit more flexible.
        self.command = self.command if command else resource

        self.args = args
        self.run_env: RunEnv = run_env
        self.selected_role: AssumableRole = role
        self.role: Role = self.selected_role.role if self.selected_role else None
        self.ci_config_path = Utils.attr_if_exists(config, args)
        self.from_path = Utils.attr_if_exists(from_path, args)
        self.out_file = Utils.attr_if_exists(out, args)
        self.query_prefix = Utils.attr_if_exists(prefix, args)
        self.service = Utils.attr_if_exists(service, args)
        self.profile = Utils.attr_if_exists(profile, args)

        # Flags like --prompt that are unset or set to true
        self.repl = Utils.is_set_true(replication_only, args)
        self.manual = Utils.is_set_true(manual, args)
        self.point_in_time = Utils.is_set_true(point_in_time, args)
        self.all_profiles = Utils.is_set_true(all_profiles, args)
        self.skip_upgrade = Utils.is_set_true(skip_upgrade, args)
        self.configure = Utils.is_set_true(configure, args)
        self.version = Utils.is_set_true(version, args)

        logger.info(self.__dict__)
Ejemplo n.º 3
0
    def __init__(self, ssm_init: SsmDao, colors_enabled: bool,
                 config_context: ConfigContext,
                 config_view: RBACLimitedConfigView, get: Get):
        super().__init__(put, colors_enabled, config_context)
        self._ssm = ssm_init
        self._utils = Utils(colors_enabled)
        self._config_view = config_view
        self._get = get
        self._source_key = Utils.attr_if_exists(copy_from, config_context.args)
        self._out = Output(colors_enabled)

        self._select_name = [('class:', 'Please input a PS Name: ')]

        self._FILE_PREFIX = "file://"
Ejemplo n.º 4
0
    def __init__(self, run_env: RunEnv, role: Role, args, resource: CliCommand,
                 defaults: Optional[CLIDefaults]):
        super().__init__(run_env, resource, defaults=defaults)
        self.role = role  # type: Role
        self.args = args
        self.ci_config_path = Utils.attr_if_exists(config, args)
        self.from_path = Utils.attr_if_exists(from_path, args)
        self.out_file = Utils.attr_if_exists(out, args)
        self.prefix = Utils.attr_if_exists(prefix, args)
        self.service = Utils.attr_if_exists(service, args)

        # Flags like --prompt that are unset or set to true
        self.repl = Utils.is_set_true(replication_only, args)
        self.manual = Utils.is_set_true(manual, args)
        self.point_in_time = Utils.is_set_true(point_in_time, args)
        self.all_profiles = Utils.is_set_true(all_profiles, args)
        self.skip_upgrade = Utils.is_set_true(skip_upgrade, args)
        self.replication_only = Utils.is_set_true(replication_only, args)
        self.point_in_time = Utils.is_set_true(point_in_time, args)
        self.profile = Utils.attr_if_exists(profile, args)