forked from MuckRock/squarelet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
initialize_dotenvs.py
executable file
·98 lines (89 loc) · 3.19 KB
/
initialize_dotenvs.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
#!/usr/bin/env python
# This will create your initial .env files
# These are not to be checked in to git, as you may populate them
# with confidential information
# Standard Library
import os
import random
import string
def random_string(n):
return "".join(
random.choice(string.ascii_letters + string.digits) for _ in range(n)
)
CONFIG = [
{
"name": ".django",
"sections": [
{
"name": "General",
"envvars": [
("USE_DOCKER", "yes"),
("DJANGO_SECRET_KEY", lambda: random_string(20)),
("IPYTHONDIR", "/app/.ipython"),
],
},
{
"name": "Redis",
"description": "Redis is used as a celery broker and as a cache backend",
"envvars": [("REDIS_URL", "redis://squarelet_redis:6379/0")],
},
{
"name": "Mailgun",
"url": "https://www.mailgun.com",
"description": "Mailgun is used for sending mail",
"envvars": [("MAILGUN_ACCESS_KEY", "")],
},
{
"name": "Mixpanel",
"url": "https://mixpanel.com",
"description": "Mixpanel is used for analytics",
"envvars": [("MIXPANEL_TOKEN", "")],
},
{
"name": "Stripe",
"url": "https://stripe.com",
"description": "Stripe is used for payment processing",
"envvars": [
("STRIPE_SECRET_KEYS", "sk_muckrock,sk_presspass"),
("STRIPE_PUB_KEYS", "pk_muckrock,pk_presspass"),
("STRIPE_WEBHOOK_SECRETS", "wh_muckrock,wh_presspass"),
],
},
],
},
{
"name": ".postgres",
"sections": [
{
"name": "PostgreSQL",
"envvars": [
("POSTGRES_HOST", "squarelet_postgres"),
("POSTGRES_PORT", "5432"),
("POSTGRES_DB", "squarelet"),
("POSTGRES_USER", lambda: random_string(30)),
("POSTGRES_PASSWORD", lambda: random_string(60)),
],
}
],
},
]
def main():
print("Initializing the dot env environment for Squarelet development")
os.makedirs(".envs/.local/", 0o775)
print("Created the directories")
for file_config in CONFIG:
with open(".envs/.local/{}".format(file_config["name"]), "w") as file_:
for section in file_config["sections"]:
for key in ["name", "url", "description"]:
if key in section:
file_.write("# {}\n".format(section[key]))
file_.write("# {}\n".format("-" * 78))
for var, value in section["envvars"]:
file_.write(
"{}={}\n".format(var, value() if callable(value) else value)
)
file_.write("\n")
print("Created file .envs/.local/{}".format(file_config["name"]))
print("Initialization Complete")
if __name__ == "__main__":
main()