summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkali kaneko (leap communications) <kali@leap.se>2020-08-24 21:25:33 +0200
committerkali kaneko (leap communications) <kali@leap.se>2020-09-08 19:58:24 +0200
commitc2871f4aece61b939e0e6c8d7a94677fb055620a (patch)
treeee07f959cbfeb6cacbddf45ae0b1873a743838bb
parentfb89df3ee609e9f3e63e0679b3635516603092b5 (diff)
[feat] generate providers.json
-rw-r--r--Makefile5
-rw-r--r--branding/README.rst9
-rw-r--r--branding/config/vendor.conf3
-rw-r--r--branding/scripts/gen-providers-json.py70
-rwxr-xr-xbranding/scripts/vendorize.py2
5 files changed, 83 insertions, 6 deletions
diff --git a/Makefile b/Makefile
index 4722146..4967d47 100644
--- a/Makefile
+++ b/Makefile
@@ -131,6 +131,11 @@ build_all_providers:
# packaging templates
#########################################################################
+vendor: gen_providers_json
+
+gen_providers_json:
+ @python3 branding/scripts/gen-providers-json.py branding/config/vendor.conf gui/providers/providers.json
+
prepare: prepare_templates gen_pkg_win gen_pkg_osx gen_pkg_snap gen_pkg_deb prepare_done
prepare_templates: generate relink_default tgz
diff --git a/branding/README.rst b/branding/README.rst
index 87d8085..7f2f16a 100644
--- a/branding/README.rst
+++ b/branding/README.rst
@@ -29,15 +29,14 @@ before the build. If you want to skip this check, pass `SKIP_CACHECK=yes`
Run::
- PROVIDER=example make prepare
+ PROVIDER=example make vendor
-You can also specify a custom config file::
+Then you can build the binary::
- PROVIDER=example PROVIDER_CONFIG=/path/to/vendor.conf make prepare
+ ./build.sh
-Then you need to build the package::
- make build
+* The following does not work yet! in progress ------------------
Then you can build all the packages::
diff --git a/branding/config/vendor.conf b/branding/config/vendor.conf
index 0992128..3657c2b 100644
--- a/branding/config/vendor.conf
+++ b/branding/config/vendor.conf
@@ -1,6 +1,7 @@
[default]
provider = demolib
+bitmask-providers = [riseup, calyx]
[riseup]
@@ -42,7 +43,7 @@ helpURL = https://calyx.net/support
geolocationAPI = https://api.black.riseup.net:9001/json
askForDonations = false
-donateURL = http://example.org
+donateURL =
[demo]
diff --git a/branding/scripts/gen-providers-json.py b/branding/scripts/gen-providers-json.py
new file mode 100644
index 0000000..b57965b
--- /dev/null
+++ b/branding/scripts/gen-providers-json.py
@@ -0,0 +1,70 @@
+#!/usr/bin/env python3
+import configparser
+import json
+import os
+import sys
+
+
+from provider import getDefaultProvider
+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 = {}
+ defaultProvider = getDefaultProvider(config)
+ providers['default'] = defaultProvider
+ providerData = getProviderData(defaultProvider, config)
+ addCaData(providerData, configPath)
+
+ providers[defaultProvider] = 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 + '-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 writeOutput(data, infile, outfile):
+
+ with open(infile) as infile:
+ s = Template(infile.read())
+
+ with open(outfile, 'w') as outf:
+ outf.write(s.substitute(data))
+
+def bail(msg=None):
+ if not msg:
+ print("ERROR: not enough arguments!")
+ print('Usage: {scriptname}.py <config> <output>'.format(
+ scriptname=SCRIPT_NAME))
+ else:
+ print(msg)
+ sys.exit(1)
+
+if __name__ == "__main__":
+ print("[+] Generating providers.json...")
+ if len(sys.argv) != 3:
+ bail()
+ # TODO get BITMASK_BRANDING folder - get config from there, if possible.
+ env_provider_conf = os.environ.get('PROVIDER_CONFIG')
+ if env_provider_conf:
+ if os.path.isfile(env_provider_conf):
+ print("[+] Overriding provider config per "
+ "PROVIDER_CONFIG variable")
+ configfile = env_provider_conf
+ generateProvidersJSON(sys.argv[1], sys.argv[2])
diff --git a/branding/scripts/vendorize.py b/branding/scripts/vendorize.py
index ba248b0..28c5d2a 100755
--- a/branding/scripts/vendorize.py
+++ b/branding/scripts/vendorize.py
@@ -1,5 +1,7 @@
#!/usr/bin/env python3
+# TODO: to be deprecated! use gen-providers-json.py instead
+
import os
import sys