def __init__(self, defaults: CLIDefaults, context: FiggyContext):
     super().__init__(defaults, context)
     keychain_enabled = defaults.extras.get(DISABLE_KEYRING) is not True
     vault = FiggyVault(keychain_enabled=keychain_enabled,
                        secrets_mgr=self._secrets_mgr)
     self._cache_manager: CacheManager = CacheManager(
         file_override=OKTA_SESSION_CACHE_PATH, vault=vault)
     self._saml_cache: CacheManager = CacheManager(
         file_override=SAML_SESSION_CACHE_PATH, vault=vault)
 def __init__(self, defaults: CLIDefaults, context: FiggyContext):
     super().__init__(defaults, context)
     self._utils = Utils(defaults.colors_enabled)
     self._sts = boto3.client('sts')
     self._context = context
     keychain_enabled = defaults.extras.get(DISABLE_KEYRING) is not True
     vault = FiggyVault(keychain_enabled=keychain_enabled,
                        secrets_mgr=self._secrets_mgr)
     self._sts_cache: CacheManager = CacheManager(
         file_override=STS_SESSION_CACHE_PATH, vault=vault)
     self._saml_cache: CacheManager = CacheManager(
         file_override=SAML_SESSION_CACHE_PATH, vault=vault)
示例#3
0
    def __cache_mgr(self) -> CacheManager:
        """Builds a cache manager service for the specified resource."""
        if not self._cache_mgr:
            self._cache_mgr: CacheManager = CacheManager(
                self._context.resource)

        return self._cache_mgr
示例#4
0
 def __init__(self, context: FiggyContext):
     self._cache_mgr = CacheManager(file_override=DEFAULTS_FILE_CACHE_PATH)
     self._config_mgr, self.c = ConfigManager.figgy(), Utils.default_colors()
     self._session_mgr = None
     self._session_provider = None
     self._secrets_mgr = SecretsManager()
     self._figgy_context = context
示例#5
0
    def stc_get_defaults(skip: bool = False, profile: str = None) -> Optional[CLIDefaults]:
        """Lookup a user's defaults as configured by --configure option.
        :param skip - Boolean, if this is true, exit and return none.
        :param profile - AWS CLI profile to use as an override. If this is passed in all other options are ignored.
        :return: hydrated CLIDefaults object of default values stored in cache file or None if no cache found
        """
        if profile:
            return CLIDefaults.from_profile(profile)

        cache_mgr = CacheManager(file_override=DEFAULTS_FILE_CACHE_PATH)
        try:
            last_write, defaults = cache_mgr.get(DEFAULTS_KEY)
            if not defaults:
                if skip:
                    return CLIDefaults.unconfigured()
                else:
                    Utils.stc_error_exit(f'{CLI_NAME} has not been configured.\n\nIf your organization has already '
                                         f'installed Figgy Cloud, please run '
                                         f'`{CLI_NAME} --{configure.name}`.\n\n'
                                         f'You may also provide the `--profile` flag, or log-in to our free sandbox with '
                                         f'`figgy login sandbox` to experiment with {CLI_NAME}.')

            return defaults
        except JSONDecodeError:
            return None
 def __init__(self, defaults: CLIDefaults, context: FiggyContext):
     super().__init__(defaults, context)
     self.__id = uuid.uuid4()
     self._utils = Utils(defaults.colors_enabled)
     self.__bastion_session = boto3.session.Session(
         profile_name=self._defaults.provider_config.profile_name)
     self._ssm = None
     self._sts = None
     self._iam_client = None
     self._iam = None
     keychain_enabled = defaults.extras.get(DISABLE_KEYRING) is not True
     vault = FiggyVault(keychain_enabled=keychain_enabled,
                        secrets_mgr=self._secrets_mgr)
     self._sts_cache: CacheManager = CacheManager(
         file_override=STS_SESSION_CACHE_PATH, vault=vault)
     self._role_name_prefix = os.getenv(FIGGY_ROLE_PREFIX_OVERRIDE_ENV,
                                        FIGGY_ROLE_NAME_PREFIX)
        def inner(self, *args, **kwargs):
            if os.environ.get(
                    AnonymousUsageTracker._DISABLE_METRICS_ENV_VAR) == "true":
                return function(self, *args, **kwargs)

            command = getattr(self, 'type', None)
            log.info(f'GOt command {command}')

            if command:
                command = command.name
                cache = CacheManager(AnonymousUsageTracker._CACHE_NAME)

                if hasattr(self, 'context') and hasattr(
                        self.context,
                        'defaults') and self.context.defaults is not None:
                    if isinstance(self.context.defaults, CLIDefaults):
                        user_id = self.context.defaults.user_id
                    else:
                        user_id = "EmptyDefaults"
                else:
                    user_id = "NoOne"

                last_write, metrics = cache.get(
                    AnonymousUsageTracker._METRICS_KEY,
                    default=FiggyMetrics(user_id=user_id))

                metrics.increment_count(command)
                if Utils.millis_since_epoch(
                ) - metrics.last_report > AnonymousUsageTracker.REPORT_FREQUENCY:
                    defaults = FiggySetup.stc_get_defaults(skip=True)
                    if defaults and defaults.usage_tracking:
                        # Ship it async. If it don't worky, oh well :shruggie:
                        with ThreadPoolExecutor(max_workers=1) as pool:
                            pool.submit(AnonymousUsageTracker.report_usage,
                                        metrics)
                            log.info(
                                f'Reporting anonymous usage for metrics: {metrics}'
                            )
                            cache.write(AnonymousUsageTracker._METRICS_KEY,
                                        FiggyMetrics(user_id=user_id))
                            return function(self, *args, **kwargs)
                else:
                    cache.write(AnonymousUsageTracker._METRICS_KEY, metrics)

            return function(self, *args, **kwargs)
示例#8
0
 def __cache_mgr(self, env: GlobalEnvironment, refresh: bool = False):
     return CacheManager(f'{env.cache_key()}')