This repository has been archived by the owner on Mar 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tail_constants.py
170 lines (141 loc) · 4.61 KB
/
tail_constants.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/usr/bin/env python
import enum
import os
import sys
DEFAULT_EXECUTOR = None
EVENT_LOOP = None
JINJA2_ENV = None
class DatabaseDeploymentType(enum.Enum):
NOOP = 'noop'
MAP = 'map'
"""
RDS: postgresql
- 20gb volume
- 1x t2.micro
"""
RDS = 'rds'
"""
DynamodbDB
"""
DYNAMODB = 'dynamodb'
class CacheDeploymentType(enum.Enum):
NOOP = 'noop'
MAP = 'map'
"""
Elasticache: REDIS
- 1x t2.medium
"""
REDIS = 'redis'
class DeploymentType(enum.Enum):
NOOP = 'noop'
MAP = 'map'
"""
t2.micro for Bastion Service
- 8gb volume
- ubuntu-18.04 LTS ami
- route53
-- bastion.$DEPLOYMENT.$STAGE
t2.micro for everything else
- 8gb volume
- 20gb volume
- ubuntu-18.04 LTS ami
"""
TURTLE = 'turtle'
"""
Bastion Service omitted
t2.micro for everything
- 8gb volume
- ubuntu-18.04 LTS ami
t2.micro for everything else
- 8gb volume
- 20gb volume
- ubuntu-18.04 LTS ami
ALB
- route53
"""
FORWARD_ARRAY = 'forward-array'
class FocalType(enum.Enum):
NOOP = 'noop'
MAP = 'map'
# Align with DeploymentType
TURTLE = 'turtle'
FORWARD_ARRAY = 'forward-array'
__all__ = [
'DEPLOYMENT', 'STAGE', 'VERSION',
'VALID_DEPLOYMENTS', 'ENV_VAR_NAMES', 'ENV_VARS',
'JINJA2_ENV', 'EVENT_LOOP', 'DeploymentType',
'DEPLOYMENT_TYPE', 'CLUSTER_PREFIX']
DEPLOYMENT = os.environ['DEPLOYMENT'].upper()
STAGE = os.environ['STAGE']
VERSION = os.environ['VERSION']
DNS_NAME = os.environ['DNS_NAME']
RESOURCE_NAME = os.environ['RESOURCE_NAME']
VALID_DEPLOYMENTS = ['PLEIADES']
ENV_VAR_NAMES = os.environ['ENV_VAR_NAMES'].split(' ')
# ENV_VAR_NAMES = [
# 'SSH_KEY_PATH', 'AWS_KEY_PATH',
# 'WWW_DEBUG', 'WWW_PORT', 'WWW_HOST', 'WWW_SECRET', 'WWW_WORKERS', 'WWW_SALT',
# 'SENTRY_KEY',
# 'PSQL_POOL',
# 'PSQL__DBNAME', 'PSQL__USERNAME', 'PSQL__PASSWORD',
# 'REDIS_POOL',
# 'REDIS_AUTH_TOKEN',
# 'PAYPAL_ACCESS', 'PAYPAL_SECRET', 'PAYPAL_URI_BASE',
# 'DOCUMENT_DIR',
# 'SERVICE_URI_BASE',
# ]
assert DEPLOYMENT in VALID_DEPLOYMENTS, f'Deployment[{DEPLOYMENT}] is not a valid deployment[{".".join(VALID_DEPLOYMENTS)}].'
ENV_VARS = {}
env_vars_found = []
for env_var in ENV_VAR_NAMES:
env_var_name = '__'.join([DEPLOYMENT, env_var])
value = os.environ.get(env_var_name, None)
if value is None:
raise NotImplementedError(f'Unable to load ENVVar[{env_var_name}]')
if env_var in ENV_VARS.keys():
raise NotImplementedError(f'Duplicate ENVVar[{env_var}]')
ENV_VARS[env_var] = value
# Validate SSH Key Existance
assert os.path.exists(ENV_VARS['SSH_KEY_PATH']), f'Missing SSH_KEY_PATH[{ENV_VARS["SSH_KEY_PATH"]}]'
assert os.path.exists(ENV_VARS['AWS_KEY_PATH']), f'Missing AWS_KEY_PATH[{ENV_VARS["AWS_KEY_PATH"]}]'
# Build PSQL_POOL URI
# Patch the ENVVar to lower-case for Dockerfile and Docker Image Generation
# UPPERCase is for user consistency
DEPLOYMENT = DEPLOYMENT.lower()
# Constructs
CLUSTER_PREFIX = f'{DEPLOYMENT}-{STAGE}'
RESOURCE_PREFIX = f'{DEPLOYMENT}-{STAGE}-{RESOURCE_NAME}-{"-".join(DNS_NAME.split("."))}'
CLUSTER_DNS_NAME = '-'.join
CLUSTER_FOCAL = f'{CLUSTER_PREFIX}-focal-{RESOURCE_NAME}-{"-".join(DNS_NAME.split("."))}'
CLUSTER_BUILD = f'{CLUSTER_PREFIX}-build-{RESOURCE_NAME}-{"-".join(DNS_NAME.split("."))}'
CLUSTER_OPS = f'{CLUSTER_PREFIX}-ops-{RESOURCE_NAME}-{"-".join(DNS_NAME.split("."))}'
CLUSTER_WEBSERVICE = f'{CLUSTER_PREFIX}-webservice-{RESOURCE_NAME}-{"-".join(DNS_NAME.split("."))}'
if 'production' == STAGE:
FOCAL_DNS_NAME = f'{DEPLOYMENT}.{RESOURCE_NAME}.{DNS_NAME}'
TURTLE_ARRAY_DNS = f'turtle.{DEPLOYMENT}.{DNS_NAME}'
FORWARD_ARRAY_DNS = f'forward.{DEPLOYMENT}.{DNS_NAME}'
else:
FOCAL_DNS_NAME = f'{STAGE}.{DEPLOYMENT}.{RESOURCE_NAME}.{DNS_NAME}'
TURTLE_ARRAY_DNS = f'turtle.{STAGE}.{DEPLOYMENT}.{DNS_NAME}'
FORWARD_ARRAY_DNS = f'forward.{STAGE}.{DEPLOYMENT}.{DNS_NAME}'
REQUIRED_VPC_SUBNET_ZONES = ['us-east-1a', 'us-east-1b', 'us-east-1c', 'us-east-1d', 'us-east-1e', 'us-east-1f']
NET_MASKS = {'8': 256 ** 3, '16': 256 ** 2, '24': 256}
AWS_KEY_NAME = 'blank'
SSH_TIMEOUT = 10
INTERNAL_PORTS = [22, 443, int(ENV_VARS['WWW_PORT'])]
RDS_PORTS = [5432]
REDIS_PORTS = [6379]
EXPECTED_PORT=INTERNAL_PORTS[0]
BASTION_PORTS=[22, 443]
BASTION__LETS_ENCRYPT_PORTS = [80]
FORWARD_ARRAY_PORTS = [80, 443]
TURTLE_ARRAY_PORTS = [int(ENV_VARS['WWW_PORT'])]
INTERNAL_HTTP_PORT = int(ENV_VARS['WWW_PORT'])
EXPECTED_USERNAME='ubuntu'
SERVICE_INSTALL_DELAY = 1
SSH_TAG_LINE = '# Generated by quine'
SSH_CONFIG_PATH = os.path.join(os.path.expanduser('~'), '.ssh/config')
#SSH_CONFIG_PATH = os.path.join(os.path.expanduser('~'), '.ssh/config_test')
SSH_KNOWN_HOSTS_PATH = os.path.join(os.path.expanduser('~'), '.ssh/known_hosts')
POLL_DELAY: int = 10
ENCODING = 'utf-8'