forked from duck-dynasty/duckbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
42 lines (32 loc) · 1.67 KB
/
app.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
import json
import os
from typing import List
import boto3
from aws_cdk import core
from duckdeploy.secret import Secret
from duckdeploy.stack import DuckBotStack
SECRETS = [
Secret(environment_name="DISCORD_TOKEN", parameter_name="/duckbot/token/discord"),
Secret(environment_name="OPENWEATHER_TOKEN", parameter_name="/duckbot/token/openweather"),
Secret(environment_name="BOT_GITHUB_TOKEN", parameter_name="/duckbot/token/github"),
Secret(environment_name="WOLFRAM_ALPHA_TOKEN", parameter_name="/duckbot/token/wolfram-alpha"),
Secret(environment_name="OXFORD_DICTIONARY_ID", parameter_name="/duckbot/token/oxford-dictionary/id"),
Secret(environment_name="OXFORD_DICTIONARY_KEY", parameter_name="/duckbot/token/oxford-dictionary/key"),
Secret(environment_name="ANTHROPIC_API_KEY", parameter_name="/duckbot/token/anthropic-api/key"),
]
def validate_secrets_present_in_environment(secrets: List[Secret]):
missing_values = [x.environment_name for x in secrets if not os.getenv(x.environment_name)]
if missing_values:
raise EnvironmentError(f"missing environment values for secrets: {missing_values}")
def publish_secrets(secrets: List[Secret]):
validate_secrets_present_in_environment(secrets)
ssm_client = boto3.client("ssm")
for s in secrets:
ssm_client.put_parameter(Name=s.parameter_name, Value=os.getenv(s.environment_name), Type="SecureString", Overwrite=True)
if __name__ == "__main__":
app = core.App()
write_secrets = app.node.try_get_context("write_secrets")
if write_secrets and json.loads(write_secrets.lower()):
publish_secrets(SECRETS)
DuckBotStack(app, "duckbot", secrets=SECRETS)
app.synth()