Repository navigation
Expand file tree
/
Copy pathconfig.py
More file actions
207 lines (180 loc) · 6.29 KB
/
Copy pathconfig.py
File metadata and controls
207 lines (180 loc) · 6.29 KB
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
"""App settings."""
from getpass import getuser
from pydantic import Field, computed_field, constr, field_validator
from pydantic_settings import BaseSettings
AwsSubnetId = constr(pattern=r"^subnet-[a-z0-9]{17}$")
class vedaAppSettings(BaseSettings):
"""Application settings."""
# App name and deployment stage
app_name: str | None = 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: str | None = Field(
None,
description=(
"Resource identifier of VPC, if none a new VPC with public and private "
"subnets will be provisioned."
),
)
subnet_ids: list[AwsSubnetId] | None = 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: str | None = Field(
None,
description=(
"When deploying from a local machine the AWS account id is required "
"to deploy to an exiting VPC"
),
)
cdk_default_region: str | None = 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: str | None = Field(
None,
description="Name of IAM policy to define stack permissions boundary",
)
veda_domain_alt_hosted_zone_id: str | None = Field(
None,
description="Route53 zone identifier if using a custom domain name",
)
veda_domain_alt_hosted_zone_name: str | None = Field(
None,
description="Custom domain name, i.e. veda-backend.xyz",
)
bootstrap_qualifier: str | None = Field(
None,
description=(
"Custom bootstrap qualifier override if not using a default installation "
"of AWS CDK Toolkit to synthesize app."
),
)
stac_browser_tag: str = Field(
"v3.2.0",
description=(
"Tag of the radiant earth stac-browser repo to use to build the app"
"https://github.com/radiantearth/stac-browser/releases."
),
)
stac_browser_path_prefix: str | None = Field(
None,
description=(
"If you don't deploy the STAC Browser instance at the root path"
" of your (sub) domain, then you need to set the path prefix when building "
"(or running) STAC Browser. e.g. '/browser/' will enable the STAC Browser "
"to be built in a way that it can be hosted at https://example.com/browser"
),
)
stac_browser_s3_prefix: str | None = Field(
None,
description=(
"S3 prefix to use for the STAC Browser static assets. "
"If not set, the assets will be placed at the root of the bucket."
),
)
cloudfront: bool | None = Field(
False,
description="Boolean if Cloudfront Distribution should be deployed",
)
veda_custom_host: str | None = 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: str | None = Field(
None, description="Custom domain name, i.e. veda-backend.xyz"
)
disable_default_apigw_endpoint: bool | None = 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,
}
return {}
@field_validator("stage")
@classmethod
def stage_name(cls, v: str) -> str:
"""Force lowercase stage name"""
return v.lower()
@computed_field # type: ignore[prop-decorator]
@property
def stac_catalog_url(self) -> str | None:
"""
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://{self.veda_custom_host}{self.veda_stac_root_path}"
if (
self.veda_domain_create_custom_subdomains
and self.veda_domain_hosted_zone_name
):
return f"https://{self.stage}-stac.{self.veda_domain_hosted_zone_name}"
return None
@property
def stac_browser_stack_name(self) -> str:
"""Infer stac browser stack name based on app name and stage"""
return f"{self.app_name}-stac-browser-{self.stage}"
@property
def veda_backend_stack_name(self) -> str:
"""Infer veda backend stack name based on app name and stage"""
return f"{self.app_name}-{self.stage}"
class Config:
"""model config."""
env_file = ".env"
extra = "ignore"
veda_app_settings = vedaAppSettings()