Exemple #1
0
    def batch_get_aggregate_resource_config(
        self, aggregator_name, resource_identifiers
    ):
        """Returns the configuration of an item in the AWS Config format of the resource for the current regional backend.

            As far a moto goes -- the only real difference between this function and the `batch_get_resource_config` function is that
            this will require a Config Aggregator be set up a priori and can search based on resource regions.

            Note: moto will IGNORE the resource account ID in the search query.
        """
        if not self.config_aggregators.get(aggregator_name):
            raise NoSuchConfigurationAggregatorException()

        # Can't have more than 100 items
        if len(resource_identifiers) > 100:
            raise TooManyResourceKeys(
                ["com.amazonaws.starling.dove.AggregateResourceIdentifier@12345"]
                * len(resource_identifiers)
            )

        found = []
        not_found = []
        for identifier in resource_identifiers:
            resource_type = identifier["ResourceType"]
            resource_region = identifier["SourceRegion"]
            resource_id = identifier["ResourceId"]
            resource_name = identifier.get("ResourceName", None)

            # Does the resource type exist?
            if not RESOURCE_MAP.get(resource_type):
                not_found.append(identifier)
                continue

            # Get the item:
            item = RESOURCE_MAP[resource_type].get_config_resource(
                resource_id,
                resource_name=resource_name,
                resource_region=resource_region,
            )
            if not item:
                not_found.append(identifier)
                continue

            item["accountId"] = DEFAULT_ACCOUNT_ID

            # The 'tags' field is not included in aggregate results for some reason...
            item.pop("tags", None)

            found.append(item)

        return {
            "BaseConfigurationItems": found,
            "UnprocessedResourceIdentifiers": not_found,
        }
Exemple #2
0
    def batch_get_resource_config(self, resource_keys, backend_region):
        """Returns the configuration of an item in the AWS Config format of the resource for the current regional backend.

        :param resource_keys:
        :param backend_region:
        """
        # Can't have more than 100 items
        if len(resource_keys) > 100:
            raise TooManyResourceKeys(
                ["com.amazonaws.starling.dove.ResourceKey@12345"] * len(resource_keys)
            )

        results = []
        for resource in resource_keys:
            # Does the resource type exist?
            if not RESOURCE_MAP.get(resource["resourceType"]):
                # Not found so skip.
                continue

            # Is the resource type global?
            config_backend_region = backend_region
            backend_query_region = (
                backend_region  # Always provide the backend this request arrived from.
            )
            if RESOURCE_MAP[resource["resourceType"]].backends.get("global"):
                config_backend_region = "global"

            # If the backend region isn't implemented then we won't find the item:
            if not RESOURCE_MAP[resource["resourceType"]].backends.get(
                config_backend_region
            ):
                continue

            # Get the item:
            item = RESOURCE_MAP[resource["resourceType"]].get_config_resource(
                resource["resourceId"], backend_region=backend_query_region
            )
            if not item:
                continue

            item["accountId"] = DEFAULT_ACCOUNT_ID

            results.append(item)

        return {
            "baseConfigurationItems": results,
            "unprocessedResourceKeys": [],
        }  # At this time, moto is not adding unprocessed items.
Exemple #3
0
    def batch_get_resource_config(self, resource_keys, backend_region):
        """Returns the configuration of an item in the AWS Config format of the resource for the current regional backend.

        :param resource_keys:
        :param backend_region:
        """
        # Can't have more than 100 items
        if len(resource_keys) > 100:
            raise TooManyResourceKeys(
                ['com.amazonaws.starling.dove.ResourceKey@12345'] *
                len(resource_keys))

        results = []
        for resource in resource_keys:
            # Does the resource type exist?
            if not RESOURCE_MAP.get(resource['resourceType']):
                # Not found so skip.
                continue

            # Is the resource type global?
            if RESOURCE_MAP[resource['resourceType']].backends.get('global'):
                backend_region = 'global'

            # If the backend region isn't implemented then we won't find the item:
            if not RESOURCE_MAP[resource['resourceType']].backends.get(
                    backend_region):
                continue

            # Get the item:
            item = RESOURCE_MAP[resource['resourceType']].get_config_resource(
                resource['resourceId'], backend_region=backend_region)
            if not item:
                continue

            item['accountId'] = DEFAULT_ACCOUNT_ID

            results.append(item)

        return {
            'baseConfigurationItems': results,
            'unprocessedResourceKeys': []
        }  # At this time, moto is not adding unprocessed items.