signing-tool 3.6.1rc2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. signing_tool-3.6.1rc2/LICENSE +5 -0
  2. signing_tool-3.6.1rc2/MANIFEST.in +10 -0
  3. signing_tool-3.6.1rc2/PKG-INFO +18 -0
  4. signing_tool-3.6.1rc2/README.md +84 -0
  5. signing_tool-3.6.1rc2/pyproject.toml +36 -0
  6. signing_tool-3.6.1rc2/setup.cfg +4 -0
  7. signing_tool-3.6.1rc2/signing_tool.egg-info/PKG-INFO +18 -0
  8. signing_tool-3.6.1rc2/signing_tool.egg-info/SOURCES.txt +40 -0
  9. signing_tool-3.6.1rc2/signing_tool.egg-info/dependency_links.txt +1 -0
  10. signing_tool-3.6.1rc2/signing_tool.egg-info/entry_points.txt +3 -0
  11. signing_tool-3.6.1rc2/signing_tool.egg-info/requires.txt +12 -0
  12. signing_tool-3.6.1rc2/signing_tool.egg-info/top_level.txt +1 -0
  13. signing_tool-3.6.1rc2/signingtool/__init__.py +0 -0
  14. signing_tool-3.6.1rc2/signingtool/apiconfig.py +35 -0
  15. signing_tool-3.6.1rc2/signingtool/ca.py +121 -0
  16. signing_tool-3.6.1rc2/signingtool/cli.py +20 -0
  17. signing_tool-3.6.1rc2/signingtool/client.py +155 -0
  18. signing_tool-3.6.1rc2/signingtool/config_init.py +77 -0
  19. signing_tool-3.6.1rc2/signingtool/encrypt.py +91 -0
  20. signing_tool-3.6.1rc2/signingtool/escrow.py +167 -0
  21. signing_tool-3.6.1rc2/signingtool/fusemap.py +90 -0
  22. signing_tool-3.6.1rc2/signingtool/group.py +330 -0
  23. signing_tool-3.6.1rc2/signingtool/handler.py +323 -0
  24. signing_tool-3.6.1rc2/signingtool/metadata.py +52 -0
  25. signing_tool-3.6.1rc2/signingtool/parser_ca.py +74 -0
  26. signing_tool-3.6.1rc2/signingtool/parser_client.py +74 -0
  27. signing_tool-3.6.1rc2/signingtool/parser_escrow.py +53 -0
  28. signing_tool-3.6.1rc2/signingtool/parser_groups.py +47 -0
  29. signing_tool-3.6.1rc2/signingtool/parser_imagesigning.py +216 -0
  30. signing_tool-3.6.1rc2/signingtool/parser_product.py +57 -0
  31. signing_tool-3.6.1rc2/signingtool/parser_production.py +46 -0
  32. signing_tool-3.6.1rc2/signingtool/parser_profile.py +59 -0
  33. signing_tool-3.6.1rc2/signingtool/parser_secretsfusemap.py +90 -0
  34. signing_tool-3.6.1rc2/signingtool/parsers.py +210 -0
  35. signing_tool-3.6.1rc2/signingtool/product.py +354 -0
  36. signing_tool-3.6.1rc2/signingtool/production.py +81 -0
  37. signing_tool-3.6.1rc2/signingtool/profile.py +113 -0
  38. signing_tool-3.6.1rc2/signingtool/secret.py +252 -0
  39. signing_tool-3.6.1rc2/signingtool/sign.py +341 -0
  40. signing_tool-3.6.1rc2/signingtool/state.py +38 -0
  41. signing_tool-3.6.1rc2/signingtool/version.py +24 -0
  42. signing_tool-3.6.1rc2/signingtool/version.py.bak2 +24 -0
@@ -0,0 +1,5 @@
1
+ Copyright (c) 2026 Laavat Oy
2
+
3
+ All rights reserved.
4
+
5
+ This software is the proprietary work of Laavat Oy. Use, reproduction, or distribution of this software, in whole or in part, is prohibited without the express prior written permission of Laavat Oy.
@@ -0,0 +1,10 @@
1
+ include README.md
2
+ include LICENSE
3
+ include ../RELEASE-NOTES.md
4
+ recursive-include LICENSES *
5
+ graft signingtool
6
+ global-exclude __pycache__
7
+ global-exclude *.py[cod]
8
+ global-exclude *.so
9
+ global-exclude *.dylib
10
+ global-exclude *.pyd
@@ -0,0 +1,18 @@
1
+ Metadata-Version: 2.4
2
+ Name: signing-tool
3
+ Version: 3.6.1rc2
4
+ Summary: Laavat Signing Solution CLI Tool
5
+ Requires-Python: >=3.8
6
+ License-File: LICENSE
7
+ Requires-Dist: certifi>=2017.4.17
8
+ Requires-Dist: python-dateutil>=2.1
9
+ Requires-Dist: six>=1.10
10
+ Requires-Dist: urllib3>=1.23
11
+ Requires-Dist: requests>=2.25.1
12
+ Requires-Dist: jwcrypto>=1.0
13
+ Requires-Dist: configparser>=5.0.2
14
+ Requires-Dist: cryptography>=3.4
15
+ Provides-Extra: dev
16
+ Requires-Dist: autopep8>=1.5.7; extra == "dev"
17
+ Requires-Dist: pycodestyle>=2.7.0; extra == "dev"
18
+ Dynamic: license-file
@@ -0,0 +1,84 @@
1
+ # Laavat Signing Solution CLI Tool
2
+
3
+ > ⚠️ **Reference Implementation Only** — This is a reference implementation and should **not be used in production**. Security improvements are planned before this tool is productized. Use this for evaluation and development purposes only.
4
+
5
+ The `signing-tool` package provides the Laavat Signing Solution command-line client.
6
+ It supports client registration, product management, image signing, secrets management, and more via the SaaS API.
7
+
8
+ ## Installation
9
+
10
+ Install from PyPI when released:
11
+
12
+ ```bash
13
+ pip install signing-tool
14
+ ```
15
+
16
+ Install from source during development:
17
+
18
+ ```bash
19
+ cd clients/python3
20
+ python3 -m pip install .
21
+ ```
22
+
23
+ ## Quick Start
24
+
25
+ Display help:
26
+
27
+ ```bash
28
+ signing-tool --help
29
+ ```
30
+
31
+ ### Recommended usage
32
+
33
+ Use a configuration file to keep credentials out of command history and logs. Create the file with `config-init`, then run the CLI using the `-n` option.
34
+
35
+ ```bash
36
+ config-init -n test.ini -t "$TOKEN" -s -a https://app.laavat.io/<CustomerName>/api/v1
37
+ signing-tool -n test.ini product getall
38
+ ```
39
+
40
+ ### Alternative usage
41
+
42
+ You can also pass settings directly on the command line, but this is less secure because tokens may become visible in shell history or process listings.
43
+
44
+ ```bash
45
+ signing-tool -c -t "$TOKEN" -a https://app.laavat.io/<CustomerName>/api/v1 product getall
46
+ ```
47
+
48
+ ## Configuration Options
49
+
50
+ Option 1: create an ini config file using `config-init`:
51
+
52
+ ```bash
53
+ config-init -n test.ini -t "$TOKEN" -s -a https://app.laavat.io/<CustomerName>/api/v1
54
+ signing-tool -n test.ini product getall
55
+ ```
56
+
57
+ Option 2: pass settings directly on the command line (not recommended for secrets):
58
+
59
+ ```bash
60
+ signing-tool -c -t "$TOKEN" -a https://app.laavat.io/<CustomerName>/api/v1 product getall
61
+ ```
62
+
63
+ ## Example Signing Commands
64
+
65
+ HAB image signing with config file:
66
+
67
+ ```bash
68
+ signing-tool -n test.ini imagesigning add SignHABIMG -P <product-id> --operid <operator-id> -p <payload>
69
+ ```
70
+
71
+ OCI signing with token and API address:
72
+
73
+ ```bash
74
+ signing-tool -c -t "$TOKEN" -a https://app.laavat.io/<CustomerName>/api/v1 imagesigning add SignOCI -P <product-id> --operid <operator-id> -A <artifact>
75
+ ```
76
+
77
+ ## Requirements
78
+
79
+ - Python 3.8 or newer
80
+
81
+ ## Packaging
82
+
83
+ This package is configured for PyPI distribution using `pyproject.toml` and `setuptools`.
84
+ Read the `pyproject.toml` file for package metadata and published package configuration.
@@ -0,0 +1,36 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "signing-tool"
7
+ dynamic = ["version"]
8
+ description = "Laavat Signing Solution CLI Tool"
9
+ requires-python = ">=3.8"
10
+ dependencies = [
11
+ "certifi>=2017.4.17",
12
+ "python-dateutil>=2.1",
13
+ "six>=1.10",
14
+ "urllib3>=1.23",
15
+ "requests>=2.25.1",
16
+ "jwcrypto>=1.0",
17
+ "configparser>=5.0.2",
18
+ "cryptography>=3.4",
19
+ ]
20
+
21
+ [project.optional-dependencies]
22
+ dev = [
23
+ "autopep8>=1.5.7",
24
+ "pycodestyle>=2.7.0",
25
+ ]
26
+
27
+ [project.scripts]
28
+ signing-tool = "signingtool.cli:main"
29
+ config-init = "signingtool.config_init:main"
30
+
31
+ [tool.setuptools.packages.find]
32
+ where = ["."]
33
+ include = ["signingtool*"]
34
+
35
+ [tool.setuptools.dynamic]
36
+ version = {attr = "signingtool.version.__version__"}
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,18 @@
1
+ Metadata-Version: 2.4
2
+ Name: signing-tool
3
+ Version: 3.6.1rc2
4
+ Summary: Laavat Signing Solution CLI Tool
5
+ Requires-Python: >=3.8
6
+ License-File: LICENSE
7
+ Requires-Dist: certifi>=2017.4.17
8
+ Requires-Dist: python-dateutil>=2.1
9
+ Requires-Dist: six>=1.10
10
+ Requires-Dist: urllib3>=1.23
11
+ Requires-Dist: requests>=2.25.1
12
+ Requires-Dist: jwcrypto>=1.0
13
+ Requires-Dist: configparser>=5.0.2
14
+ Requires-Dist: cryptography>=3.4
15
+ Provides-Extra: dev
16
+ Requires-Dist: autopep8>=1.5.7; extra == "dev"
17
+ Requires-Dist: pycodestyle>=2.7.0; extra == "dev"
18
+ Dynamic: license-file
@@ -0,0 +1,40 @@
1
+ LICENSE
2
+ MANIFEST.in
3
+ README.md
4
+ pyproject.toml
5
+ signing_tool.egg-info/PKG-INFO
6
+ signing_tool.egg-info/SOURCES.txt
7
+ signing_tool.egg-info/dependency_links.txt
8
+ signing_tool.egg-info/entry_points.txt
9
+ signing_tool.egg-info/requires.txt
10
+ signing_tool.egg-info/top_level.txt
11
+ signingtool/__init__.py
12
+ signingtool/apiconfig.py
13
+ signingtool/ca.py
14
+ signingtool/cli.py
15
+ signingtool/client.py
16
+ signingtool/config_init.py
17
+ signingtool/encrypt.py
18
+ signingtool/escrow.py
19
+ signingtool/fusemap.py
20
+ signingtool/group.py
21
+ signingtool/handler.py
22
+ signingtool/metadata.py
23
+ signingtool/parser_ca.py
24
+ signingtool/parser_client.py
25
+ signingtool/parser_escrow.py
26
+ signingtool/parser_groups.py
27
+ signingtool/parser_imagesigning.py
28
+ signingtool/parser_product.py
29
+ signingtool/parser_production.py
30
+ signingtool/parser_profile.py
31
+ signingtool/parser_secretsfusemap.py
32
+ signingtool/parsers.py
33
+ signingtool/product.py
34
+ signingtool/production.py
35
+ signingtool/profile.py
36
+ signingtool/secret.py
37
+ signingtool/sign.py
38
+ signingtool/state.py
39
+ signingtool/version.py
40
+ signingtool/version.py.bak2
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ config-init = signingtool.config_init:main
3
+ signing-tool = signingtool.cli:main
@@ -0,0 +1,12 @@
1
+ certifi>=2017.4.17
2
+ python-dateutil>=2.1
3
+ six>=1.10
4
+ urllib3>=1.23
5
+ requests>=2.25.1
6
+ jwcrypto>=1.0
7
+ configparser>=5.0.2
8
+ cryptography>=3.4
9
+
10
+ [dev]
11
+ autopep8>=1.5.7
12
+ pycodestyle>=2.7.0
@@ -0,0 +1 @@
1
+ signingtool
File without changes
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ from __future__ import print_function
5
+
6
+ import configparser
7
+
8
+
9
+ class APIConfig:
10
+ def __init__(self, skipssl=True, address="", token=""):
11
+ self.skipssl = skipssl
12
+ self.address = address
13
+ self.token = token
14
+
15
+ def ParseFromFile(self, fn: str):
16
+ config = configparser.ConfigParser()
17
+ config.read(fn)
18
+
19
+ self.skipssl = config.getboolean("service", "skipssl")
20
+ self.address = config.get("service", "url")
21
+ self.token = config.get("service", "token")
22
+
23
+ def ParseFromCmdLine(self, args: "list[str]"):
24
+ pass
25
+
26
+
27
+ def GetAPIConfig(args) -> APIConfig:
28
+ apiconfig = APIConfig()
29
+
30
+ if args.c:
31
+ apiconfig = APIConfig(args.skipssl, args.a, args.t)
32
+ else:
33
+ apiconfig.ParseFromFile(args.n)
34
+
35
+ return apiconfig
@@ -0,0 +1,121 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ from __future__ import print_function
5
+
6
+ import base64
7
+ import json
8
+ import os
9
+ from pprint import pprint
10
+
11
+ import SigningService
12
+ from SigningService.rest import ApiException
13
+
14
+ from signingtool.apiconfig import APIConfig
15
+ from signingtool.state import stateEnumToString
16
+
17
+
18
+ def getca(apiconfig: APIConfig, caId: str, page: int):
19
+ # Configure OAuth2 access token for authorization:
20
+ configuration = SigningService.Configuration()
21
+ if apiconfig.skipssl:
22
+ configuration.verify_ssl = False
23
+ configuration.host = apiconfig.address
24
+ configuration.access_token = apiconfig.token
25
+
26
+ api_instance = SigningService.PkiApi(
27
+ SigningService.ApiClient(configuration))
28
+
29
+ try:
30
+ result = ""
31
+
32
+ if caId:
33
+ result = api_instance.pki_ca_get_by_id(id=caId)
34
+ else:
35
+ pg = 0
36
+ if page:
37
+ pg = page
38
+ result = api_instance.pki_cas_get_all(page=pg)
39
+ print(json.dumps(result.to_dict(), indent=4, sort_keys=True))
40
+ except ApiException as e:
41
+ print("Exception when calling PKIApi: %s\n" % e)
42
+ except Exception as e:
43
+ print(f"Exception: {type(e).__name__}: {e}\n")
44
+
45
+ return
46
+
47
+
48
+ def getcsr(apiconfig: APIConfig, caId: str, outputFn: str):
49
+ # Configure OAuth2 access token for authorization:
50
+ configuration = SigningService.Configuration()
51
+ if apiconfig.skipssl:
52
+ configuration.verify_ssl = False
53
+ configuration.host = apiconfig.address
54
+ configuration.access_token = apiconfig.token
55
+
56
+ api_instance = SigningService.PkiApi(
57
+ SigningService.ApiClient(configuration))
58
+
59
+ try:
60
+ if outputFn:
61
+ if os.path.exists(outputFn):
62
+ print("Error: File already exists: %s\n" % outputFn)
63
+ else:
64
+ result = api_instance.pki_ca_get_by_id(id=caId)
65
+ csr = result.to_dict().get("csr")
66
+ with open(outputFn, "wb", 600) as f:
67
+ f.write(base64.decodebytes(bytes(csr, "ascii")))
68
+ print("Payload written to file: {}".format(outputFn))
69
+ except ApiException as e:
70
+ print("Exception when calling PKIApi: %s\n" % e)
71
+ except Exception as e:
72
+ print(f"Exception: {type(e).__name__}: {e}\n")
73
+
74
+ return
75
+
76
+
77
+ def uploadchain(apiconfig: APIConfig, caId: str, chainFn: str):
78
+ # Configure OAuth2 access token for authorization:
79
+ configuration = SigningService.Configuration()
80
+ if apiconfig.skipssl:
81
+ configuration.verify_ssl = False
82
+ configuration.host = apiconfig.address
83
+ configuration.access_token = apiconfig.token
84
+
85
+ api_instance = SigningService.PkiApi(
86
+ SigningService.ApiClient(configuration))
87
+
88
+ try:
89
+ chain = base64.encodebytes(open(chainFn, "rb").read()).decode("ascii")
90
+ patch = SigningService.PatchCa(chain=chain)
91
+ result = api_instance.ca_ca_patch_add(id=caId, body=patch)
92
+ print(result)
93
+ print("Chain upload")
94
+ except ApiException as e:
95
+ print("Exception when calling PKIApi: %s\n" % e)
96
+ except Exception as e:
97
+ print(f"Exception: {type(e).__name__}: {e}\n")
98
+
99
+ return
100
+
101
+
102
+ def getcrl(apiconfig: APIConfig, caId: str):
103
+ # Configure OAuth2 access token for authorization:
104
+ configuration = SigningService.Configuration()
105
+ if apiconfig.skipssl:
106
+ configuration.verify_ssl = False
107
+ configuration.host = apiconfig.address
108
+ configuration.access_token = apiconfig.token
109
+
110
+ api_instance = SigningService.PkiApi(
111
+ SigningService.ApiClient(configuration))
112
+
113
+ try:
114
+ result = api_instance.ca_getcrl(id=caId)
115
+ print(result.crl)
116
+ except ApiException as e:
117
+ print("Exception when calling PKIApi: %s\n" % e)
118
+ except Exception as e:
119
+ print(f"Exception: {type(e).__name__}: {e}\n")
120
+
121
+ return
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ from __future__ import print_function
5
+
6
+ import sys
7
+ from signingtool.parsers import ParseArgs
8
+
9
+
10
+ def main():
11
+ if len(sys.argv) == 1:
12
+ # No arguments provided, show help by adding -h
13
+ sys.argv.append('-h')
14
+
15
+ parser, args = ParseArgs()
16
+ args.func(args)
17
+
18
+
19
+ if __name__ == "__main__":
20
+ main()
@@ -0,0 +1,155 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ from __future__ import print_function
5
+
6
+ import base64
7
+ import json
8
+ import os
9
+ from pprint import pprint
10
+
11
+ import SigningService
12
+ from SigningService.rest import ApiException
13
+
14
+ from signingtool.apiconfig import APIConfig
15
+ from signingtool.state import stateEnumToString
16
+
17
+
18
+ def addclient(
19
+ apiconfig: APIConfig,
20
+ name: str,
21
+ desc: str,
22
+ pubKeyFn: str,
23
+ user: str,
24
+ productId: str,
25
+ clientType: str,
26
+ certFn: str,
27
+ ):
28
+ # Configure OAuth2 access token for authorization:
29
+ configuration = SigningService.Configuration()
30
+ if apiconfig.skipssl:
31
+ configuration.verify_ssl = False
32
+ configuration.host = apiconfig.address
33
+ configuration.access_token = apiconfig.token
34
+
35
+ pId = productId
36
+
37
+ api_instance = SigningService.RegistrationsClientsApi(
38
+ SigningService.ApiClient(configuration)
39
+ )
40
+
41
+ try:
42
+ pubkey = ""
43
+ if pubKeyFn:
44
+ pubkey = base64.encodebytes(open(pubKeyFn, "rb").read()).decode("ascii")
45
+ cert = ""
46
+ if certFn:
47
+ cert = base64.encodebytes(open(certFn, "rb").read()).decode("ascii")
48
+
49
+ req = SigningService.ClientRequest(
50
+ name=name,
51
+ description=desc,
52
+ encryption_public_key=pubkey,
53
+ client_user=user,
54
+ id_product=pId,
55
+ client_type=clientType,
56
+ client_certificate=cert,
57
+ )
58
+ result = api_instance.registrations_clients_post_add(req)
59
+ print(json.dumps(result.to_dict(), indent=4, sort_keys=True))
60
+ print(
61
+ "Client Add request sent. Request ID: {} state: {}".format(
62
+ result.to_dict()["id"], stateEnumToString(result.to_dict()["state"])
63
+ )
64
+ )
65
+
66
+ except ApiException as e:
67
+ print("Exception when calling Api: %s\n" % e)
68
+ except Exception as e:
69
+ print(f"Exception: {type(e).__name__}: {e}\n")
70
+
71
+ return
72
+
73
+
74
+ def approveclient(apiconfig: APIConfig, rId: str):
75
+ # Configure OAuth2 access token for authorization:
76
+ configuration = SigningService.Configuration()
77
+ if apiconfig.skipssl:
78
+ configuration.verify_ssl = False
79
+ configuration.host = apiconfig.address
80
+ configuration.access_token = apiconfig.token
81
+
82
+ api_instance = SigningService.RegistrationsClientsApi(
83
+ SigningService.ApiClient(configuration)
84
+ )
85
+ try:
86
+ req = SigningService.Approval(request_id=rId, decision="APPROVE")
87
+ result = api_instance.registrations_clients_post_approve(req)
88
+ # TODO: we should probably check if it actually succeeded but the result object
89
+ # has nothing. Might require an api change
90
+ print("Client approved")
91
+ except ApiException as e:
92
+ print("Exception when calling Api: %s\n" % e)
93
+ except Exception as e:
94
+ print(f"Exception: {type(e).__name__}: {e}\n")
95
+ return
96
+
97
+
98
+ def getclient(apiconfig: APIConfig, clientId: str, page: int):
99
+ # Configure OAuth2 access token for authorization:
100
+ configuration = SigningService.Configuration()
101
+ if apiconfig.skipssl:
102
+ configuration.verify_ssl = False
103
+ configuration.host = apiconfig.address
104
+ configuration.access_token = apiconfig.token
105
+
106
+ api_instance = SigningService.RegistrationsClientsApi(
107
+ SigningService.ApiClient(configuration)
108
+ )
109
+
110
+ try:
111
+ result = ""
112
+ if clientId:
113
+ result = api_instance.registrations_clients_get_clientbyid(clientId)
114
+ else:
115
+ pg = 0
116
+ if page:
117
+ pg = page
118
+ result = api_instance.registrations_clients_get_all(page=pg)
119
+
120
+ print(json.dumps(result.to_dict(), indent=4, sort_keys=True))
121
+ except ApiException as e:
122
+ print("Exception when calling Api: %s\n" % e)
123
+ except Exception as e:
124
+ print(f"Exception: {type(e).__name__}: {e}\n")
125
+ return
126
+
127
+
128
+ def getcapproval(apiconfig: APIConfig, approvalId: str, page: int):
129
+ # Configure OAuth2 access token for authorization:
130
+ configuration = SigningService.Configuration()
131
+ if apiconfig.skipssl:
132
+ configuration.verify_ssl = False
133
+ configuration.host = apiconfig.address
134
+ configuration.access_token = apiconfig.token
135
+
136
+ api_instance = SigningService.RegistrationsClientsApi(
137
+ SigningService.ApiClient(configuration)
138
+ )
139
+
140
+ try:
141
+ result = ""
142
+ if approvalId:
143
+ result = api_instance.registrations_clients_get_approvalbyid(approvalId)
144
+ else:
145
+ pg = 0
146
+ if page:
147
+ pg = page
148
+ result = api_instance.registrations_clients_get_approvals(page=pg)
149
+
150
+ print(json.dumps(result.to_dict(), indent=4, sort_keys=True))
151
+ except ApiException as e:
152
+ print("Exception when calling Api: %s\n" % e)
153
+ except Exception as e:
154
+ print(f"Exception: {type(e).__name__}: {e}\n")
155
+ return
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ from __future__ import print_function
5
+
6
+ import configparser
7
+ import getopt
8
+ import os
9
+ import sys
10
+
11
+
12
+ def generateCfg(config_file: str, token: str, skipTLSVerification: bool, address: str):
13
+
14
+ try:
15
+ if not os.path.isfile(config_file):
16
+ # Create the configuration file as it doesn't exist yet
17
+ cfgfile = open(config_file, "w")
18
+
19
+ # Add content to the file
20
+ Config = configparser.ConfigParser()
21
+ Config.add_section("service")
22
+ Config.set("service", "url", address)
23
+ Config.set("service", "token", token)
24
+ Config.set("service", "skipSSL", str(skipTLSVerification))
25
+ Config.write(cfgfile)
26
+ cfgfile.close()
27
+ print("Config file written")
28
+ else:
29
+ print("ERROR: File already exists")
30
+
31
+ except Exception as e:
32
+ print("Exception when calling create config file: %s\n" % e)
33
+
34
+
35
+ def main():
36
+ configfile_name = ""
37
+ skipTLSVerification = False
38
+ address = "https://localhost/api/v1"
39
+
40
+ options, remainder = getopt.getopt(
41
+ sys.argv[1:],
42
+ "n:t:sa:",
43
+ [
44
+ "filename=",
45
+ "token=",
46
+ "skipTlsVerification",
47
+ "address=",
48
+ ],
49
+ )
50
+
51
+ if len(sys.argv) < 7:
52
+ print(
53
+ "Usage: config-init -n filename -t token -s -a address",
54
+ file=sys.stderr,
55
+ )
56
+ sys.exit()
57
+
58
+ for opt, arg in options:
59
+ if opt in ("-n", "--filename"):
60
+ configfile_name = arg
61
+ if opt in ("-t", "--token"):
62
+ token = arg
63
+ elif opt in ("-s", "--skipTlsVerification"):
64
+ skipTLSVerification = True
65
+ elif opt in ("-a", "--address"):
66
+ address = arg
67
+
68
+ generateCfg(
69
+ configfile_name,
70
+ token,
71
+ skipTLSVerification,
72
+ address,
73
+ )
74
+
75
+
76
+ if __name__ == "__main__":
77
+ main()