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
|
#!/usr/bin/env python3
import configparser
import json
import os
import sys
from provider import getDefaultProviders
from provider import getProviderData
OUTFILE = 'providers.json'
SCRIPT_NAME = 'gen-providers-json'
def generateProvidersJSON(configPath, outputJSONPath):
print("output:", outputJSONPath)
config = configparser.ConfigParser()
config.read(configPath)
# TODO as a first step, we just get the defaultProvider.
# For multi-provider, just add more providers to the dict
providers = {}
defaultProviders = getDefaultProviders(config)
providers['default'] = defaultProviders[0]
providers['providers'] = []
for p in defaultProviders:
providerData = getProviderData(p, config)
addCaData(providerData, configPath)
providers['providers'].append(providerData)
with open(outputJSONPath, 'w', encoding='utf-8') as f:
json.dump(providers, f, ensure_ascii=False, indent=4)
def addCaData(data, configfile):
provider = data.get('name').lower()
folder, f = os.path.split(configfile)
caFile = os.path.join(folder, provider, provider + '-ca.crt')
if not os.path.isfile(caFile):
bail('[!] Cannot find CA file in {path}'.format(path=caFile))
with open(caFile) as ca:
data['caCertString'] = ca.read().strip()
def bail(msg=None):
if not msg:
print("ERROR: not enough arguments!")
print('Usage: {scriptname}.py <output>'.format(
scriptname=SCRIPT_NAME))
else:
print(msg)
sys.exit(1)
if __name__ == "__main__":
print("[+] Generating providers.json...")
if len(sys.argv) != 2:
bail()
VENDOR_PATH = os.environ.get('VENDOR_PATH')
conf = os.path.join(VENDOR_PATH, 'vendor.conf')
output = sys.argv[1]
generateProvidersJSON(conf, output)
|