-
Notifications
You must be signed in to change notification settings - Fork 5
/
config.py
151 lines (129 loc) · 4.9 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
"""App settings."""
from getpass import getuser
from typing import List, Optional
from pydantic import BaseSettings, Field, constr
AwsSubnetId = constr(regex=r"^subnet-[a-z0-9]{17}$")
class vedaAppSettings(BaseSettings):
"""Application settings."""
# App name and deployment stage
app_name: Optional[str] = Field(
"veda-backend",
description="Optional app name used to name stack and resources",
)
stage: str = Field(
...,
description=(
"Deployment stage used to name stack and resources, "
"i.e. `dev`, `staging`, `prod`"
),
)
owner: str = Field(
description=" ".join(
[
"Name of primary contact for Cloudformation Stack.",
"Used to tag generated resources",
"Defaults to current username.",
]
),
default_factory=getuser,
)
vpc_id: Optional[str] = Field(
None,
description=(
"Resource identifier of VPC, if none a new VPC with public and private "
"subnets will be provisioned."
),
)
subnet_ids: Optional[List[AwsSubnetId]] = Field( # type: ignore
[],
description="The subnet ids of subnets associated with the VPC to be used for the database and lambda function.",
)
cdk_default_account: Optional[str] = Field(
None,
description="When deploying from a local machine the AWS account id is required to deploy to an exiting VPC",
)
cdk_default_region: Optional[str] = Field(
None,
description="When deploying from a local machine the AWS region id is required to deploy to an exiting VPC",
)
permissions_boundary_policy_name: Optional[str] = Field(
None,
description="Name of IAM policy to define stack permissions boundary",
)
veda_domain_alt_hosted_zone_id: Optional[str] = Field(
None,
description="Route53 zone identifier if using a custom domain name",
)
veda_domain_alt_hosted_zone_name: Optional[str] = Field(
None,
description="Custom domain name, i.e. veda-backend.xyz",
)
bootstrap_qualifier: Optional[str] = Field(
None,
description="Custom bootstrap qualifier override if not using a default installation of AWS CDK Toolkit to synthesize app.",
)
stac_browser_tag: Optional[str] = Field(
"v3.1.0",
description=(
"Tag of the radiant earth stac-browser repo to use to build the app"
"https://github.com/radiantearth/stac-browser/releases."
),
)
cloudfront: Optional[bool] = Field(
False,
description="Boolean if Cloudfront Distribution should be deployed",
)
veda_custom_host: str = Field(
None,
description="Complete url of custom host including subdomain. Used to infer url of stac-api before app synthesis.",
)
veda_stac_root_path: str = Field(
"",
description="STAC API root path. Used to infer url of stac-api before app synthesis.",
)
veda_raster_root_path: str = Field(
"",
description="Raster API root path",
)
veda_domain_create_custom_subdomains: bool = Field(
False,
description=(
"When true and hosted zone config is provided, create a unique subdomain for stac and raster apis. "
"For example <stage>-stac.<hosted_zone_name> and <stage>-raster.<hosted_zone_name>"
),
)
veda_domain_hosted_zone_name: Optional[str] = Field(
None, description="Custom domain name, i.e. veda-backend.xyz"
)
disable_default_apigw_endpoint: Optional[bool] = Field(
False,
description="Boolean to disable default API gateway endpoints for stac, raster, and ingest APIs. Defaults to false.",
)
def cdk_env(self) -> dict:
"""Load a cdk environment dict for stack"""
if self.vpc_id:
return {
"account": self.cdk_default_account,
"region": self.cdk_default_region,
}
else:
return {}
def stage_name(self) -> str:
"""Force lowercase stage name"""
return self.stage.lower()
def get_stac_catalog_url(self) -> Optional[str]:
"""Infer stac catalog url based on whether the app is configured to deploy the catalog to a custom subdomain or to a cloudfront route"""
if self.veda_custom_host and self.veda_stac_root_path:
return f"https://{veda_app_settings.veda_custom_host}{veda_app_settings.veda_stac_root_path}"
if (
self.veda_domain_create_custom_subdomains
and self.veda_domain_hosted_zone_name
):
return (
f"https://{self.stage.lower()}-stac.{self.veda_domain_hosted_zone_name}"
)
return None
class Config:
"""model config."""
env_file = ".env"
veda_app_settings = vedaAppSettings()