async fn filter_resource(
        &self,
        resource: &mut Resource,
        config: &ResourceConfig,
        cw_client: Arc<Box<CwClient>>,
    ) -> EnforcementState {
        if resource.enforcement_state == EnforcementState::SkipUnknownState {
            if self.filter_by_whitelist(resource, config) {
                // Skip a resource if its in the whitelist
                debug!(resource = resource.id.as_str(), "Resource whitelisted");
                EnforcementState::SkipConfig
            } else if self.filter_by_state(resource) {
                // Skip resource if its state is stopped
                EnforcementState::SkipStopped
            } else if self.filter_by_tags(resource, config) {
                // Enforce provided required tags
                debug!(
                    resource = resource.id.as_str(),
                    "Resource tags does not match."
                );
                resource.enforcement_reason = Some(EnforcementReason::TagRule);
                EnforcementState::from_target_state(&config.target_state)
            } else if self.filter_by_allowed_types(resource, config) {
                // Enforce allowed types
                debug!(
                    resource = resource.id.as_str(),
                    "Resource is not in list of allowed types."
                );
                resource.enforcement_reason = Some(EnforcementReason::AllowedTypeRule);
                EnforcementState::from_target_state(&config.target_state)
            } else if self.filter_by_runtime(resource, config) {
                // Enforce max runtime for a resource if max_run_time is provided
                debug!(
                    resource = resource.id.as_str(),
                    "Resource exceeded max runtime."
                );
                resource.enforcement_reason = Some(EnforcementReason::Runtime);
                EnforcementState::from_target_state(&config.target_state)
            } else if self.filter_by_idle_rules(resource, cw_client).await {
                // Enforce Idle rules
                debug!(resource = resource.id.as_str(), "Resource is idle.");
                resource.enforcement_reason = Some(EnforcementReason::Idle);
                EnforcementState::from_target_state(&config.target_state)
            } else if self.filter_by_naming_prefix(resource, config) {
                debug!(
                    resource = resource.id.as_str(),
                    "Resource naming prefix not met."
                );
                resource.enforcement_reason = Some(EnforcementReason::NameRule);
                EnforcementState::from_target_state(&config.target_state)
            } else {
                if let Some(additional_filters) =
                    self.additional_filters(resource, config).await.take()
                {
                    if additional_filters {
                        {
                            // Apply any additional filters that are implemented by
                            // Resource clients.
                            debug!(
                                resource = resource.id.as_str(),
                                "Resource does not meet additional filters."
                            );
                            resource.enforcement_reason = Some(EnforcementReason::AdditionalRules);
                            return EnforcementState::from_target_state(&config.target_state);
                        }
                    }
                }

                EnforcementState::Skip
            }
        } else {
            resource.enforcement_state
        }
    }
/// Filters a provided resource by applying all the filters
Filters a provided resource by applying all the filters
Filters a provided resource by applying all the filters
async fn filter_resource(
        &self,
        resource: &mut Resource,
        config: &ResourceConfig,
        cw_client: Arc<Box<CwClient>>,
    ) -> EnforcementState {
        if resource.enforcement_state == EnforcementState::SkipUnknownState {
            if self.filter_by_whitelist(resource, config) {
                // Skip a resource if its in the whitelist
                debug!(resource = resource.id.as_str(), "Resource whitelisted");
                EnforcementState::SkipConfig
            } else if self.filter_by_state(resource) {
                // Skip resource if its state is stopped
                EnforcementState::SkipStopped
            } else if self.filter_by_tags(resource, config) {
                // Enforce provided required tags
                debug!(
                    resource = resource.id.as_str(),
                    "Resource tags does not match."
                );
                resource.enforcement_reason = Some(EnforcementReason::TagRule);
                EnforcementState::from_target_state(&config.target_state)
            } else if self.filter_by_allowed_types(resource, config) {
                // Enforce allowed types
                debug!(
                    resource = resource.id.as_str(),
                    "Resource is not in list of allowed types."
                );
                resource.enforcement_reason = Some(EnforcementReason::AllowedTypeRule);
                EnforcementState::from_target_state(&config.target_state)
            } else if self.filter_by_runtime(resource, config) {
                // Enforce max runtime for a resource if max_run_time is provided
                debug!(
                    resource = resource.id.as_str(),
                    "Resource exceeded max runtime."
                );
                resource.enforcement_reason = Some(EnforcementReason::Runtime);
                EnforcementState::from_target_state(&config.target_state)
            } else if self.filter_by_idle_rules(resource, cw_client).await {
                // Enforce Idle rules
                debug!(resource = resource.id.as_str(), "Resource is idle.");
                resource.enforcement_reason = Some(EnforcementReason::Idle);
                EnforcementState::from_target_state(&config.target_state)
            } else if self.filter_by_naming_prefix(resource, config) {
                debug!(
                    resource = resource.id.as_str(),
                    "Resource naming prefix not met."
                );
                resource.enforcement_reason = Some(EnforcementReason::NameRule);
                EnforcementState::from_target_state(&config.target_state)
            } else {
                if let Some(additional_filters) =
                    self.additional_filters(resource, config).await.take()
                {
                    if additional_filters {
                        {
                            // Apply any additional filters that are implemented by
                            // Resource clients.
                            debug!(
                                resource = resource.id.as_str(),
                                "Resource does not meet additional filters."
                            );
                            resource.enforcement_reason = Some(EnforcementReason::AdditionalRules);
                            return EnforcementState::from_target_state(&config.target_state);
                        }
                    }
                }
                EnforcementState::Skip
            }
        } else {
            resource.enforcement_state
        }
    }
async fn filter_resource ( & self , resource : & mut Resource , config : & ResourceConfig , cw_client : Arc < Box < CwClient > > , ) -> EnforcementState { if resource . enforcement_state == EnforcementState :: SkipUnknownState { if self . filter_by_whitelist ( resource , config ) { // Skip a resource if its in the whitelist debug ! ( resource resource id as_str ( ) " " ) ; EnforcementState :: SkipConfig } else if self . filter_by_state ( resource ) { // Skip resource if its state is stopped EnforcementState :: SkipStopped } else if self . filter_by_tags ( resource , config ) { // Enforce provided required tags debug ! ( resource resource id as_str ( ) " " ) ; resource . enforcement_reason = Some ( EnforcementReason :: TagRule ) ; EnforcementState :: from_target_state ( & config . target_state ) } else if self . filter_by_allowed_types ( resource , config ) { // Enforce allowed types debug ! ( resource resource id as_str ( ) " " ) ; resource . enforcement_reason = Some ( EnforcementReason :: AllowedTypeRule ) ; EnforcementState :: from_target_state ( & config . target_state ) } else if self . filter_by_runtime ( resource , config ) { // Enforce max runtime for a resource if max_run_time is provided debug ! ( resource resource id as_str ( ) " " ) ; resource . enforcement_reason = Some ( EnforcementReason :: Runtime ) ; EnforcementState :: from_target_state ( & config . target_state ) } else if self . filter_by_idle_rules ( resource , cw_client ) . await { // Enforce Idle rules debug ! ( resource resource id as_str ( ) " " ) ; resource . enforcement_reason = Some ( EnforcementReason :: Idle ) ; EnforcementState :: from_target_state ( & config . target_state ) } else if self . filter_by_naming_prefix ( resource , config ) { debug ! ( resource resource id as_str ( ) " " ) ; resource . enforcement_reason = Some ( EnforcementReason :: NameRule ) ; EnforcementState :: from_target_state ( & config . target_state ) } else { if let Some ( additional_filters ) = self . additional_filters ( resource , config ) . await . take ( ) { if additional_filters { { // Apply any additional filters that are implemented by // Resource clients. debug ! ( resource resource id as_str ( ) " " ) ; resource . enforcement_reason = Some ( EnforcementReason :: AdditionalRules ) ; return EnforcementState :: from_target_state ( & config . target_state ) ; } } } EnforcementState :: Skip } } else { resource . enforcement_state } }
Filters a provided resource by applying all the filters
Filters a provided resource by applying all the filters
&self
resource
&mut Resource
config
&ResourceConfig
cw_client
Arc<Box<CwClient>>