proxy/meta: only create proxies for providers that are enabled

This commit is contained in:
Iain Learmonth 2022-10-23 12:14:29 +01:00
parent 18d6f294f4
commit 3f07f0e08f
5 changed files with 13 additions and 1 deletions

View file

@ -5,6 +5,7 @@ import datetime
from collections import defaultdict from collections import defaultdict
from typing import Optional, Any, List, Dict from typing import Optional, Any, List, Dict
from flask import current_app
from sqlalchemy import text from sqlalchemy import text
from app import app from app import app
@ -65,10 +66,18 @@ class ProxyAutomation(TerraformAutomation):
Whether this provider supports "smart" proxies. Whether this provider supports "smart" proxies.
""" """
cloud_name: str
"""
The name of the cloud provider used by this proxy provider. Used to determine if this provider can be enabled.
"""
@abstractmethod @abstractmethod
def import_state(self, state: Any) -> None: def import_state(self, state: Any) -> None:
raise NotImplementedError() raise NotImplementedError()
def enabled(self) -> bool:
return current_app.config.get(self.cloud_name.upper() + "_ENABLED", False)
def tf_prehook(self) -> Optional[Any]: # pylint: disable=useless-return def tf_prehook(self) -> Optional[Any]: # pylint: disable=useless-return
return None return None

View file

@ -11,6 +11,7 @@ class ProxyAzureCdnAutomation(ProxyAutomation):
provider = "azure_cdn" provider = "azure_cdn"
subgroup_members_max = 25 subgroup_members_max = 25
parallelism = 1 parallelism = 1
cloud_name = "azure"
template_parameters = [ template_parameters = [
"azure_resource_group_name", "azure_resource_group_name",

View file

@ -11,6 +11,7 @@ class ProxyCloudfrontAutomation(ProxyAutomation):
description = "Deploy proxies to AWS CloudFront" description = "Deploy proxies to AWS CloudFront"
provider = "cloudfront" provider = "cloudfront"
smart_proxies = True smart_proxies = True
cloud_name = "aws"
template_parameters = [ template_parameters = [
"aws_access_key", "aws_access_key",

View file

@ -12,6 +12,7 @@ class ProxyFastlyAutomation(ProxyAutomation):
description = "Deploy proxies to Fastly" description = "Deploy proxies to Fastly"
provider = "fastly" provider = "fastly"
subgroup_members_max = 20 subgroup_members_max = 20
cloud_name = "fastly"
template_parameters = [ template_parameters = [
"aws_access_key", "aws_access_key",

View file

@ -18,7 +18,7 @@ PROXY_PROVIDERS = {p.provider: p for p in [ # In order of preference
ProxyCloudfrontAutomation, ProxyCloudfrontAutomation,
ProxyFastlyAutomation, ProxyFastlyAutomation,
ProxyAzureCdnAutomation ProxyAzureCdnAutomation
]} ] if p.enabled}
def create_proxy(pool: Pool, origin: Origin) -> bool: def create_proxy(pool: Pool, origin: Origin) -> bool: