def __deploy_api_gateway()

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


    def __deploy_api_gateway(self, api_id, meta, api_resources):
        deploy_stage = self.get_deploy_stage_name(meta.get('deploy_stage'))
        cache_cluster_configuration = meta.get('cluster_cache_configuration')
        root_cache_enabled = cache_cluster_configuration.get(
            'cache_enabled') if cache_cluster_configuration else None
        cache_size = cache_cluster_configuration.get(
            'cache_size') if cache_cluster_configuration else None
        self.connection.deploy_api(api_id, stage_name=deploy_stage,
                                   cache_cluster_enabled=root_cache_enabled,
                                   cache_cluster_size=str(
                                       cache_size) if cache_size else None)

        patch_operations = []
        throttling_cluster_configuration = meta.get(
            'cluster_throttling_configuration')
        throttling_enabled = throttling_cluster_configuration.get(
            'throttling_enabled') if throttling_cluster_configuration else None
        if not throttling_enabled:
            patch_operations.append({
                'op': OPERATION_REPLACE,
                'path': '/*/*/throttling/rateLimit',
                'value': str(_DISABLE_THROTTLING_VALUE),
            })
            patch_operations.append({
                'op': OPERATION_REPLACE,
                'path': '/*/*/throttling/burstLimit',
                'value': str(_DISABLE_THROTTLING_VALUE),
            })

        # configure caching
        if root_cache_enabled:
            _LOG.debug(
                f'Cluster cache configuration found: '
                f'{cache_cluster_configuration}'
            )
            # set default ttl for root endpoint
            cluster_cache_ttl_sec = cache_cluster_configuration.get(
                'cache_ttl_sec')
            encrypt_cache_data = cache_cluster_configuration.get(
                'encrypt_cache_data')
            if cluster_cache_ttl_sec is not None:
                patch_operations.append({
                    'op': OPERATION_REPLACE,
                    'path': '/*/*/caching/ttlInSeconds',
                    'value': str(cluster_cache_ttl_sec),
                })
            if encrypt_cache_data is not None:
                patch_operations.append({
                    'op': OPERATION_REPLACE,
                    'path': '/*/*/caching/dataEncrypted',
                    'value': 'true' if bool(encrypt_cache_data) else 'false'
                })

        # configure throttling
        if throttling_enabled:
            throttling_rate_limit = throttling_cluster_configuration.get(
                'throttling_rate_limit', API_GW_DEFAULT_THROTTLING_RATE_LIMIT)
            throttling_burst_limit = throttling_cluster_configuration.get(
                'throttling_burst_limit', API_GW_DEFAULT_THROTTLING_BURST_LIMIT)
            patch_operations.append({
                'op': OPERATION_REPLACE,
                'path': '/*/*/throttling/rateLimit',
                'value': str(throttling_rate_limit),
            })
            patch_operations.append({
                'op': OPERATION_REPLACE,
                'path': '/*/*/throttling/burstLimit',
                'value': str(throttling_burst_limit),
            })

        # configure logging
        log_config = meta.get('logging_configuration')
        logging_enabled = log_config.get('logging_enabled') if (
            isinstance(log_config, dict)) else False
        if logging_enabled:
            patch_operations.append({
                'op': OPERATION_REPLACE,
                'path': '/*/*/logging/loglevel',
                'value': log_config.get('log_level', 'ERROR'),
            })
            if log_config.get('data_tracing'):
                patch_operations.append({
                    'op': OPERATION_REPLACE,
                    'path': '/*/*/logging/dataTrace',
                    'value': 'true',
                })
            if log_config.get('detailed_metrics'):
                patch_operations.append({
                    'op': OPERATION_REPLACE,
                    'path': '/*/*/metrics/enabled',
                    'value': 'true',
                })

        if any([root_cache_enabled, throttling_enabled, logging_enabled]):
            self.connection.update_configuration(
                rest_api_id=api_id,
                stage_name=deploy_stage,
                patch_operations=patch_operations
            )
        # customize settings for endpoints
        self.configure_resources(api_id, deploy_stage, api_resources)