forked from getlantern/lantern
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload_local_config.py
executable file
·63 lines (54 loc) · 1.87 KB
/
upload_local_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
#!/usr/bin/env python
import os
import re
import sys
import boto
from boto.s3.key import Key
HERE = (os.path.dirname(sys.argv[0]) if __name__ == '__main__'
else os.path.dirname(__file__))
# For development/testing purposes, not for end users.
#
# Prerequisites:
# pip install --upgrade boto
#
# Usage:
#
# (1) Save your config.json in the same directory where you have this file (or
# adjust CONFIG_JSON_PATH so it points to your config.json.)
#
# (2) Run this from a directory that is sibling to your too-many-secrets
# checkout (or adjust SECRETS_BASE_DIR so it points to your secrets
# checkout.)
#
# (3) If your configurl is not in ~/.lantern-configurl.txt (unlikely!) adjust
# CONFIGURL_PATH.
CONFIGURL_PATH = os.path.join(os.path.expanduser('~'),
'.lantern-configurl.txt')
CONFIG_JSON_PATH = os.path.join(HERE, 'config.json')
SECRETS_BASE_DIR = os.path.join(HERE, '..', 'too-many-secrets')
def read_aws_credential():
aws_credential_path = os.path.join(SECRETS_BASE_DIR,
'lantern_aws',
'aws_credential')
id_, key = None, None
for line in file(aws_credential_path):
line = line.strip()
m = re.match(r"AWSAccessKeyId=(.*)", line)
if m:
id_ = m.groups()[0]
m = re.match("AWSSecretKey=(.*)", line)
if m:
key = m.groups()[0]
assert id_ and key
return {'aws_access_key_id': id_,
'aws_secret_access_key': key}
def run():
conn = boto.connect_s3(**read_aws_credential())
bucket = conn.get_bucket("lantern-config")
key = Key(bucket)
configurl = file(CONFIGURL_PATH).read().strip()
key.name = "%s/config.json" % configurl
key.set_contents_from_filename(CONFIG_JSON_PATH, replace=True)
key.set_acl('public-read')
if __name__ == '__main__':
run()