ci: add flake8
This commit is contained in:
parent
014596d271
commit
dd501a6e4e
32 changed files with 170 additions and 171 deletions
|
@ -83,8 +83,8 @@ class ProxyAutomation(TerraformAutomation):
|
|||
|
||||
def deprecate_orphaned_proxies(self) -> None:
|
||||
proxies = Proxy.query.filter(
|
||||
Proxy.deprecated == None,
|
||||
Proxy.destroyed == None,
|
||||
Proxy.deprecated.is_(None),
|
||||
Proxy.destroyed.is_(None),
|
||||
Proxy.provider == self.provider
|
||||
).all()
|
||||
for proxy in proxies:
|
||||
|
@ -95,7 +95,7 @@ class ProxyAutomation(TerraformAutomation):
|
|||
def destroy_expired_proxies(self) -> None:
|
||||
cutoff = datetime.datetime.utcnow() - datetime.timedelta(days=3)
|
||||
proxies = Proxy.query.filter(
|
||||
Proxy.destroyed == None,
|
||||
Proxy.destroyed.is_(None),
|
||||
Proxy.provider == self.provider,
|
||||
Proxy.deprecated < cutoff
|
||||
).all()
|
||||
|
@ -123,7 +123,7 @@ class ProxyAutomation(TerraformAutomation):
|
|||
groups=Group.query.all(),
|
||||
proxies=Proxy.query.filter(
|
||||
Proxy.provider == self.provider,
|
||||
Proxy.destroyed == None
|
||||
Proxy.destroyed.is_(None)
|
||||
).all(),
|
||||
subgroups=self.get_subgroups(),
|
||||
global_namespace=app.config['GLOBAL_NAMESPACE'],
|
||||
|
|
|
@ -31,21 +31,20 @@ class ProxyAzureCdnAutomation(ProxyAutomation):
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
provider "azurerm" {
|
||||
features {}
|
||||
|
||||
client_id = "{{ azure_client_id }}"
|
||||
client_secret = "{{ azure_client_secret }}"
|
||||
subscription_id = "{{ azure_subscription_id }}"
|
||||
tenant_id = "{{ azure_tenant_id }}"
|
||||
skip_provider_registration = true
|
||||
}
|
||||
|
||||
|
||||
data "azurerm_resource_group" "this" {
|
||||
name = "{{ azure_resource_group_name }}"
|
||||
}
|
||||
|
||||
|
||||
resource "azurerm_storage_account" "this" {
|
||||
name = "{{ azure_storage_account_name }}"
|
||||
resource_group_name = data.azurerm_resource_group.this.name
|
||||
|
@ -53,7 +52,7 @@ class ProxyAzureCdnAutomation(ProxyAutomation):
|
|||
account_tier = "Standard"
|
||||
account_replication_type = "RAGRS"
|
||||
}
|
||||
|
||||
|
||||
{% for group in groups %}
|
||||
module "label_{{ group.id }}" {
|
||||
source = "cloudposse/label/null"
|
||||
|
@ -62,49 +61,48 @@ class ProxyAzureCdnAutomation(ProxyAutomation):
|
|||
tenant = "{{ group.group_name }}"
|
||||
label_order = ["namespace", "tenant", "name", "attributes"]
|
||||
}
|
||||
|
||||
|
||||
{% for subgroup in subgroups[group.id] %}
|
||||
resource "azurerm_cdn_profile" "profile_{{ group.id }}_{{ subgroup }}" {
|
||||
name = "${module.label_{{ group.id }}.id}-sub{{ subgroup }}"
|
||||
location = "{{ azure_location }}"
|
||||
resource_group_name = data.azurerm_resource_group.this.name
|
||||
sku = "Standard_Microsoft"
|
||||
|
||||
tags = module.label_{{ group.id }}.tags
|
||||
tags = module.label_{{ group.id }}.tags
|
||||
}
|
||||
|
||||
|
||||
resource "azurerm_monitor_diagnostic_setting" "profile_diagnostic_{{ group.id }}_{{ subgroup }}" {
|
||||
name = "cdn-diagnostics"
|
||||
target_resource_id = azurerm_cdn_profile.profile_{{ group.id }}_{{ subgroup }}.id
|
||||
storage_account_id = azurerm_storage_account.this.id
|
||||
|
||||
|
||||
log {
|
||||
category = "AzureCDNAccessLog"
|
||||
enabled = true
|
||||
|
||||
|
||||
retention_policy {
|
||||
enabled = true
|
||||
days = 90
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
metric {
|
||||
category = "AllMetrics"
|
||||
enabled = true
|
||||
|
||||
|
||||
retention_policy {
|
||||
enabled = true
|
||||
days = 90
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
resource "azurerm_monitor_metric_alert" "response_alert_{{ group.id }}_{{ subgroup }}" {
|
||||
name = "bandwidth-out-high-${module.label_{{ group.id }}.id}-sub{{ subgroup }}"
|
||||
resource_group_name = data.azurerm_resource_group.this.name
|
||||
scopes = [azurerm_cdn_profile.profile_{{ group.id }}_{{ subgroup }}.id]
|
||||
description = "Action will be triggered when response size is too high."
|
||||
|
||||
|
||||
criteria {
|
||||
metric_namespace = "Microsoft.Cdn/profiles"
|
||||
metric_name = "ResponseSize"
|
||||
|
@ -112,26 +110,26 @@ class ProxyAzureCdnAutomation(ProxyAutomation):
|
|||
operator = "GreaterThan"
|
||||
threshold = 21474836481
|
||||
}
|
||||
|
||||
|
||||
window_size = "PT1H"
|
||||
}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
|
||||
|
||||
{% for proxy in proxies %}
|
||||
resource "azurerm_cdn_endpoint" "endpoint_{{ proxy.id }}" {
|
||||
name = "{{ proxy.slug }}"
|
||||
profile_name = azurerm_cdn_profile.profile_{{ proxy.origin.group.id }}_{{ proxy.psg }}.name
|
||||
location = "{{ azure_location }}"
|
||||
resource_group_name = data.azurerm_resource_group.this.name
|
||||
|
||||
|
||||
origin_host_header = "{{ proxy.origin.domain_name }}"
|
||||
|
||||
|
||||
origin {
|
||||
name = "upstream"
|
||||
host_name = "{{ proxy.origin.domain_name }}"
|
||||
}
|
||||
|
||||
|
||||
global_delivery_rule {
|
||||
modify_request_header_action {
|
||||
action = "Append"
|
||||
|
@ -140,16 +138,16 @@ class ProxyAzureCdnAutomation(ProxyAutomation):
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
resource "azurerm_monitor_diagnostic_setting" "diagnostic_{{ proxy.id }}" {
|
||||
name = "cdn-diagnostics"
|
||||
target_resource_id = azurerm_cdn_endpoint.endpoint_{{ proxy.id }}.id
|
||||
storage_account_id = azurerm_storage_account.this.id
|
||||
|
||||
|
||||
log {
|
||||
category = "CoreAnalytics"
|
||||
enabled = true
|
||||
|
||||
|
||||
retention_policy {
|
||||
enabled = true
|
||||
days = 90
|
||||
|
@ -162,7 +160,7 @@ class ProxyAzureCdnAutomation(ProxyAutomation):
|
|||
def import_state(self, state: Optional[Any]) -> None:
|
||||
proxies = Proxy.query.filter(
|
||||
Proxy.provider == self.provider,
|
||||
Proxy.destroyed == None
|
||||
Proxy.destroyed.is_(None)
|
||||
).all()
|
||||
for proxy in proxies:
|
||||
proxy.url = f"https://{proxy.slug}.azureedge.net"
|
||||
|
|
|
@ -24,13 +24,13 @@ class ProxyCloudfrontAutomation(ProxyAutomation):
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
provider "aws" {
|
||||
access_key = "{{ aws_access_key }}"
|
||||
secret_key = "{{ aws_secret_key }}"
|
||||
region = "us-east-2"
|
||||
}
|
||||
|
||||
|
||||
{% for group in groups %}
|
||||
module "label_{{ group.id }}" {
|
||||
source = "cloudposse/label/null"
|
||||
|
@ -39,7 +39,7 @@ class ProxyCloudfrontAutomation(ProxyAutomation):
|
|||
tenant = "{{ group.group_name }}"
|
||||
label_order = ["namespace", "tenant", "name", "attributes"]
|
||||
}
|
||||
|
||||
|
||||
module "log_bucket_{{ group.id }}" {
|
||||
source = "cloudposse/s3-log-storage/aws"
|
||||
version = "0.28.0"
|
||||
|
@ -51,12 +51,12 @@ class ProxyCloudfrontAutomation(ProxyAutomation):
|
|||
glacier_transition_days = 60
|
||||
expiration_days = 90
|
||||
}
|
||||
|
||||
|
||||
resource "aws_sns_topic" "alarms_{{ group.id }}" {
|
||||
name = "${module.label_{{ group.id }}.id}-cloudfront-alarms"
|
||||
}
|
||||
{% endfor %}
|
||||
|
||||
|
||||
{% for proxy in proxies %}
|
||||
module "cloudfront_{{ proxy.id }}" {
|
||||
source = "sr2c/bc-proxy/aws"
|
||||
|
|
|
@ -61,7 +61,7 @@ module "log_bucket_{{ group.id }}" {
|
|||
{% if group.id == 3 %}
|
||||
resource "fastly_service_vcl" "service_{{ group.id }}" {
|
||||
name = module.label_{{ group.id }}.id
|
||||
|
||||
|
||||
{% for origin in group.origins %}
|
||||
{% for proxy in origin.proxies %}
|
||||
{% if proxy.destroyed == None and proxy.provider == "fastly" %}
|
||||
|
@ -71,7 +71,7 @@ resource "fastly_service_vcl" "service_{{ group.id }}" {
|
|||
}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
|
||||
backend {
|
||||
address = "{{ origin.domain_name }}"
|
||||
name = "{{ origin.description }}"
|
||||
|
@ -110,7 +110,7 @@ def create_missing_proxies():
|
|||
def destroy_expired_proxies():
|
||||
cutoff = datetime.datetime.utcnow() - datetime.timedelta(days=3)
|
||||
proxies = Proxy.query.filter(
|
||||
Proxy.destroyed == None,
|
||||
Proxy.destroyed.is_(None),
|
||||
Proxy.provider == "fastly",
|
||||
Proxy.deprecated < cutoff
|
||||
).all()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue