forked from harlo/UnveillanceInterface
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconf.py
More file actions
141 lines (111 loc) · 3.32 KB
/
conf.py
File metadata and controls
141 lines (111 loc) · 3.32 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
import os, yaml, json
from lib.Core.conf import *
BASE_DIR = os.path.abspath(os.path.join(__file__, os.pardir))
CONF_ROOT = os.path.join(BASE_DIR, "conf")
MONITOR_ROOT = os.path.join(BASE_DIR, ".monitor")
USER_ROOT = os.path.join(BASE_DIR, ".users")
SHA1_INDEX = True
PERMISSIONS = {
'upload_local' : [],
'upload_global' : []
}
def buildServerURL(port=None):
protocol = "http"
if SERVER_USE_SSL: protocol += "s"
if port is None: port = SERVER_PORT
server_url = "%s://%s" % (protocol, SERVER_HOST)
if port in [80, 443]:
return server_url
else:
return "%s:%d" % (server_url, port)
def buildTaskChannelURL(request, with_status=None):
for p in ["host", "protocol", "remote_ip", "path"]:
if hasattr(request, p):
print "%s : %s" % (p, getattr(request, p))
if with_status is not None:
print "WITH STATUS: ", with_status
if with_status == 0 and TASK_CHANNEL_MASK is not None:
return TASK_CHANNEL_MASK
return "%s://%s%s" % ( \
request.protocol, TASK_CHANNEL_URL, \
(":%d" % TASK_CHANNEL_PORT))
def getConfig(key):
val = None
try:
with open(os.path.join(CONF_ROOT, "local.config.yaml"), 'rb') as C:
config = yaml.load(C.read())
try:
val = config[key]
except Exception as e: pass
del config
except Exception as e: pass
return val
def getSecrets(key, password=None):
val = None
with open(os.path.join(CONF_ROOT, "unveillance.secrets.json"), 'rb') as C:
try:
config = json.loads(C.read())
except Exception as e:
print "ERROR GETTING SECRET:\n%s" % e
if password is not None:
# TODO: might be encrypted at this point, tbd.
print "SHOULD TRY TO DECRYPT?"
try:
val = config[key]
except KeyError as e: pass
del config
return val
with open(os.path.join(CONF_ROOT, "api.settings.yaml"), 'rb') as C:
config = yaml.load(C.read())
NUM_PROCESSES = config['api.num_processes']
DEBUG = config['flags.debug']
WEB_TITLE = config['api.web.title']
API_PORT = getConfig('api.port')
try:
GIT_ANNEX = os.path.join(getConfig('git_annex_dir'), "git-annex")
except Exception as e:
print e, type(e)
pass
try:
PYTHON_HOME = getConfig('python_home')
except Exception as e: pass
try:
with open(os.path.join(CONF_ROOT, "unveillance.secrets.json"), 'rb') as C:
config = json.loads(C.read())
try:
SERVER_HOST = config['server_host']
except KeyError as e: pass
try:
SERVER_PORT = config['server_port']
except KeyError as e: pass
try:
SERVER_USE_SSL = config['server_use_ssl']
except KeyError as e: pass
try:
UV_COOKIE_SECRET = config['web_cookie_secret']
except KeyError as e: pass
try:
ANNEX_DIR = config['annex_local']
except KeyError as e: pass
try:
SSH_ROOT = config['ssh_root']
except KeyError as e: pass
try:
protocol = "http"
if getSecrets('server_message_port') in [443] or getSecrets('server_message_use_ssl'):
protocol += "s"
TASK_CHANNEL_URL = getSecrets('server_host')
TASK_CHANNEL_PORT = getSecrets('server_message_port') if getSecrets('server_message_port') is not None else (getSecrets('server_port') + 1)
except Exception as e:
print "******* TASK CHANNEL ERROR ********"
print e
try:
TASK_CHANNEL_MASK = getSecrets('server_task_channel_mask')
except Exception as e:
TASK_CHANNEL_MASK = None
try:
SHA1_INDEX = config['index.sha1']
except KeyError as e:
pass
del config
except IOError as e: pass