forked from markciecior/ConnectPyse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
34 lines (26 loc) · 1022 Bytes
/
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
from os import path
import json
import base64
import sys
sys.path.insert(0, path.dirname(path.abspath(__file__)))
api_file = 'my_api.json'
_api_file = path.join(path.dirname(path.abspath(__file__)), api_file)
try:
with open(_api_file) as fin:
cw_api_settings = json.load(fin)
API_URL = cw_api_settings['API_URL']
_cid = cw_api_settings['COMPANYID']
_pubk = cw_api_settings['PUBLICKEY']
_privk = cw_api_settings['PRIVATEKEY']
_authtoken = cw_api_settings['AUTHTOKEN']
_clientId = cw_api_settings['CLIENTID'] if 'CLIENTID' in cw_api_settings else None
if (_authtoken is not None) and (_authtoken != "xxxxx"):
basic_auth = _authtoken
else:
basic_auth = base64.b64encode("{}+{}:{}".format(_cid, _pubk, _privk).encode('utf-8'))
basic_auth = {'Authorization': 'Basic {}'.format(str(basic_auth, 'utf-8'))}
if (_clientId is not None):
basic_auth['clientId'] = _clientId
except FileNotFoundError as e:
API_URL = ''
basic_auth = {}