def configure_resources()

in syndicate/core/resources/api_gateway_resource.py [0:0]


    def configure_resources(self, api_id, stage_name, api_resources):
        for resource_path, resource_meta in api_resources.items():
            for method_name, method_meta in resource_meta.items():
                if method_name in SUPPORTED_METHODS:
                    cache_configuration = method_meta.get(
                        'cache_configuration')
                    throttling_configuration = method_meta.get(
                        'throttling_configuration')
                    cache_ttl_setting = cache_configuration.get(
                        'cache_ttl_sec') if cache_configuration else None
                    encrypt_cache_data = cache_configuration.get(
                        'encrypt_cache_data') if cache_configuration else None
                    throttling_enabled = throttling_configuration.get(
                        'throttling_enabled') if throttling_configuration \
                        else None
                    throttling_rate_limit = throttling_configuration.get(
                        'throttling_rate_limit',
                        API_GW_DEFAULT_THROTTLING_RATE_LIMIT) if (
                        throttling_configuration and throttling_enabled) else \
                        _DISABLE_THROTTLING_VALUE
                    throttling_burst_limit = throttling_configuration.get(
                        'throttling_burst_limit',
                        API_GW_DEFAULT_THROTTLING_BURST_LIMIT) if (
                        throttling_configuration and throttling_enabled) else \
                        _DISABLE_THROTTLING_VALUE

                    patch_operations = []
                    escaped_resource = self._escape_path(resource_path)
                    methods_to_configure = SUPPORTED_STAGE_METHODS \
                        if method_name == 'ANY' else [method_name]
                    for method in methods_to_configure:
                        if cache_ttl_setting is not None:
                            _LOG.info(f'Configuring cache for {resource_path};'
                                      f' TTL: {cache_ttl_setting}')
                            patch_operations.append({
                                'op': OPERATION_REPLACE,
                                'path': f'/{escaped_resource}/{method}'
                                        f'/caching/ttlInSeconds',
                                'value': str(cache_ttl_setting),
                            })
                            patch_operations.append({
                                'op': OPERATION_REPLACE,
                                'path': f'/{escaped_resource}/{method}'
                                        f'/caching/enabled',
                                'value': 'True',
                            })
                        if encrypt_cache_data is not None:
                            patch_operations.append({
                                'op': OPERATION_REPLACE,
                                'path': f'/{escaped_resource}/{method}'
                                        f'/caching/enabled',
                                'value': 'True',
                            })
                            patch_operations.append({
                                'op': OPERATION_REPLACE,
                                'path': f'/{escaped_resource}/{method}'
                                        f'/caching/dataEncrypted',
                                'value': 'true' if bool(
                                    encrypt_cache_data) else 'false'
                            })

                        if throttling_enabled:
                            _LOG.info(
                                f'Configuring throttling for {resource_path}; '
                                f'rateLimit: {throttling_rate_limit}; '
                                f'burstLimit: {throttling_burst_limit}')
                        else:
                            _LOG.info(
                                f'Throttling for {resource_path} disabled.')
                        patch_operations.append({
                            'op': OPERATION_REPLACE,
                            'path': f'/{escaped_resource}/{method}'
                                    f'/throttling/rateLimit',
                            'value': str(throttling_rate_limit),
                        })
                        patch_operations.append({
                            'op': OPERATION_REPLACE,
                            'path': f'/{escaped_resource}/{method}/'
                                    f'throttling/burstLimit',
                            'value': str(throttling_burst_limit),
                        })

                        log_config = method_meta.get('logging_configuration')
                        if isinstance(log_config, dict):
                            logging_enabled = log_config.get('logging_enabled')
                        else:
                            logging_enabled = False
                        if logging_enabled:
                            _LOG.info(
                                f'Configuring logging for {resource_path};'
                                f'log_level: '
                                f"{log_config.get('log_level', 'ERROR')};"
                                f'data_tracing: '
                                f"{log_config.get('data_tracing', False)};"
                                f'detailed_metrics: '
                                f"{log_config.get('detailed_metrics', False)}"
                            )
                            patch_operations.append({
                                'op': OPERATION_REPLACE,
                                'path': f'/{escaped_resource}/{method}/'
                                        f'logging/loglevel',
                                'value': log_config.get('log_level', 'ERROR'),
                            })
                            if log_config.get('data_tracing'):
                                patch_operations.append({
                                    'op': OPERATION_REPLACE,
                                    'path': f'/{escaped_resource}/{method}/'
                                            f'logging/dataTrace',
                                    'value': 'true',
                                })
                            if log_config.get('detailed_metrics'):
                                patch_operations.append({
                                    'op': OPERATION_REPLACE,
                                    'path': f'/{escaped_resource}/{method}/'
                                            f'metrics/enabled',
                                    'value': 'true',
                                })

                    if patch_operations:
                        self.connection.update_configuration(
                            rest_api_id=api_id,
                            stage_name=stage_name,
                            patch_operations=patch_operations
                        )
                    _LOG.info(f'Resource {resource_path} was configured')