brickvar 0.0.1__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.
- brickvar-0.0.1/LICENSE +202 -0
- brickvar-0.0.1/PKG-INFO +93 -0
- brickvar-0.0.1/README.md +65 -0
- brickvar-0.0.1/pyproject.toml +44 -0
- brickvar-0.0.1/setup.cfg +4 -0
- brickvar-0.0.1/src/brickvar/__init__.py +6 -0
- brickvar-0.0.1/src/brickvar/config.py +94 -0
- brickvar-0.0.1/src/brickvar.egg-info/PKG-INFO +93 -0
- brickvar-0.0.1/src/brickvar.egg-info/SOURCES.txt +11 -0
- brickvar-0.0.1/src/brickvar.egg-info/dependency_links.txt +1 -0
- brickvar-0.0.1/src/brickvar.egg-info/requires.txt +9 -0
- brickvar-0.0.1/src/brickvar.egg-info/top_level.txt +1 -0
- brickvar-0.0.1/tests/test_config.py +169 -0
brickvar-0.0.1/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 Amida Technology Solutions
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
brickvar-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: brickvar
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Resolve Databricks config variables from literals, environment variables, and Azure Key Vault secrets, and substitute them into JSON config files.
|
|
5
|
+
Author-email: Afsin Ustundag <afsin@amida.com>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/amida-tech/brickvar
|
|
8
|
+
Project-URL: Repository, https://github.com/amida-tech/brickvar
|
|
9
|
+
Project-URL: Issues, https://github.com/amida-tech/brickvar/issues
|
|
10
|
+
Keywords: databricks,config,configuration,secrets,azure,key-vault
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
16
|
+
Requires-Python: >=3.9
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Provides-Extra: dev
|
|
20
|
+
Requires-Dist: pytest; extra == "dev"
|
|
21
|
+
Requires-Dist: pytest-mock; extra == "dev"
|
|
22
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
23
|
+
Requires-Dist: black; extra == "dev"
|
|
24
|
+
Requires-Dist: pylint; extra == "dev"
|
|
25
|
+
Requires-Dist: build; extra == "dev"
|
|
26
|
+
Requires-Dist: twine; extra == "dev"
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+
# brickvar
|
|
30
|
+
|
|
31
|
+
Resolve configuration variables for Databricks jobs from literals, environment
|
|
32
|
+
variables, and Azure Key Vault secrets, and substitute them into JSON config files.
|
|
33
|
+
|
|
34
|
+
`brickvar` reads a JSON "variables" file in which each entry is one of:
|
|
35
|
+
|
|
36
|
+
- a **literal** string (which may reference other variables with `${VAR}`),
|
|
37
|
+
- an **environment variable** reference — `{"env": "NAME"}`, or
|
|
38
|
+
- a **Databricks / Azure Key Vault secret** — `{"scope": ..., "key": ..., "base"?: ...}`,
|
|
39
|
+
read through the Databricks `dbutils.secrets` API.
|
|
40
|
+
|
|
41
|
+
Resolution is two-pass, so a secret's `scope`/`key` can themselves reference
|
|
42
|
+
already-resolved literal or environment values. It can also substitute `${VAR}`
|
|
43
|
+
placeholders into any JSON file, leaving unknown placeholders intact.
|
|
44
|
+
|
|
45
|
+
## Install
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pip install brickvar
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Usage
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
from brickvar import ConfigManager
|
|
55
|
+
|
|
56
|
+
# dbutils is provided by the Databricks runtime; required only when a
|
|
57
|
+
# variables file contains Key Vault secret entries.
|
|
58
|
+
cfg = ConfigManager(dbutils=dbutils)
|
|
59
|
+
|
|
60
|
+
# Resolve a variables file to a dict.
|
|
61
|
+
variables = cfg.read_variables("variables.json")
|
|
62
|
+
|
|
63
|
+
# Read a JSON file and substitute its ${VAR} placeholders from a variables file.
|
|
64
|
+
spec = cfg.read_json("spec.json", "variables.json")
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Example `variables.json`:
|
|
68
|
+
|
|
69
|
+
```json
|
|
70
|
+
{
|
|
71
|
+
"SECRET_SCOPE": { "env": "SECRET_SCOPE" },
|
|
72
|
+
"HOST": "example.documents.azure.us",
|
|
73
|
+
"CLIENT_ID": { "scope": "${SECRET_SCOPE}", "key": "SP-CLIENT-ID" },
|
|
74
|
+
"STORAGE": { "scope": "kv", "key": "ACCOUNT", "base": "abfss://data@{}/curated" }
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
- `HOST` is a literal.
|
|
79
|
+
- `SECRET_SCOPE` comes from the `SECRET_SCOPE` environment variable.
|
|
80
|
+
- `CLIENT_ID` is a secret whose scope is filled from the resolved `SECRET_SCOPE`.
|
|
81
|
+
- `STORAGE` is a secret wrapped by its `base` format string.
|
|
82
|
+
|
|
83
|
+
## Development
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
python -m venv venv && source venv/bin/activate
|
|
87
|
+
pip install -e ".[dev]"
|
|
88
|
+
pytest
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## License
|
|
92
|
+
|
|
93
|
+
[Apache-2.0](LICENSE)
|
brickvar-0.0.1/README.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# brickvar
|
|
2
|
+
|
|
3
|
+
Resolve configuration variables for Databricks jobs from literals, environment
|
|
4
|
+
variables, and Azure Key Vault secrets, and substitute them into JSON config files.
|
|
5
|
+
|
|
6
|
+
`brickvar` reads a JSON "variables" file in which each entry is one of:
|
|
7
|
+
|
|
8
|
+
- a **literal** string (which may reference other variables with `${VAR}`),
|
|
9
|
+
- an **environment variable** reference — `{"env": "NAME"}`, or
|
|
10
|
+
- a **Databricks / Azure Key Vault secret** — `{"scope": ..., "key": ..., "base"?: ...}`,
|
|
11
|
+
read through the Databricks `dbutils.secrets` API.
|
|
12
|
+
|
|
13
|
+
Resolution is two-pass, so a secret's `scope`/`key` can themselves reference
|
|
14
|
+
already-resolved literal or environment values. It can also substitute `${VAR}`
|
|
15
|
+
placeholders into any JSON file, leaving unknown placeholders intact.
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pip install brickvar
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
from brickvar import ConfigManager
|
|
27
|
+
|
|
28
|
+
# dbutils is provided by the Databricks runtime; required only when a
|
|
29
|
+
# variables file contains Key Vault secret entries.
|
|
30
|
+
cfg = ConfigManager(dbutils=dbutils)
|
|
31
|
+
|
|
32
|
+
# Resolve a variables file to a dict.
|
|
33
|
+
variables = cfg.read_variables("variables.json")
|
|
34
|
+
|
|
35
|
+
# Read a JSON file and substitute its ${VAR} placeholders from a variables file.
|
|
36
|
+
spec = cfg.read_json("spec.json", "variables.json")
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Example `variables.json`:
|
|
40
|
+
|
|
41
|
+
```json
|
|
42
|
+
{
|
|
43
|
+
"SECRET_SCOPE": { "env": "SECRET_SCOPE" },
|
|
44
|
+
"HOST": "example.documents.azure.us",
|
|
45
|
+
"CLIENT_ID": { "scope": "${SECRET_SCOPE}", "key": "SP-CLIENT-ID" },
|
|
46
|
+
"STORAGE": { "scope": "kv", "key": "ACCOUNT", "base": "abfss://data@{}/curated" }
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
- `HOST` is a literal.
|
|
51
|
+
- `SECRET_SCOPE` comes from the `SECRET_SCOPE` environment variable.
|
|
52
|
+
- `CLIENT_ID` is a secret whose scope is filled from the resolved `SECRET_SCOPE`.
|
|
53
|
+
- `STORAGE` is a secret wrapped by its `base` format string.
|
|
54
|
+
|
|
55
|
+
## Development
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
python -m venv venv && source venv/bin/activate
|
|
59
|
+
pip install -e ".[dev]"
|
|
60
|
+
pytest
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## License
|
|
64
|
+
|
|
65
|
+
[Apache-2.0](LICENSE)
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "brickvar"
|
|
7
|
+
version = "0.0.1"
|
|
8
|
+
description = "Resolve Databricks config variables from literals, environment variables, and Azure Key Vault secrets, and substitute them into JSON config files."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = "Apache-2.0"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [{ name = "Afsin Ustundag", email = "afsin@amida.com" }]
|
|
14
|
+
keywords = ["databricks", "config", "configuration", "secrets", "azure", "key-vault"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 3 - Alpha",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Operating System :: OS Independent",
|
|
20
|
+
"Topic :: Software Development :: Libraries",
|
|
21
|
+
]
|
|
22
|
+
# No runtime dependencies: dbutils is supplied by the Databricks host at call time.
|
|
23
|
+
dependencies = []
|
|
24
|
+
|
|
25
|
+
[project.optional-dependencies]
|
|
26
|
+
dev = ["pytest", "pytest-mock", "pytest-cov", "black", "pylint", "build", "twine"]
|
|
27
|
+
|
|
28
|
+
[project.urls]
|
|
29
|
+
Homepage = "https://github.com/amida-tech/brickvar"
|
|
30
|
+
Repository = "https://github.com/amida-tech/brickvar"
|
|
31
|
+
Issues = "https://github.com/amida-tech/brickvar/issues"
|
|
32
|
+
|
|
33
|
+
[tool.setuptools.packages.find]
|
|
34
|
+
where = ["src"]
|
|
35
|
+
|
|
36
|
+
[tool.black]
|
|
37
|
+
line-length = 120
|
|
38
|
+
target-version = ["py39"]
|
|
39
|
+
|
|
40
|
+
[tool.pylint.format]
|
|
41
|
+
max-line-length = 120
|
|
42
|
+
|
|
43
|
+
[tool.pytest.ini_options]
|
|
44
|
+
testpaths = ["tests"]
|
brickvar-0.0.1/setup.cfg
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"""Read JSON config files and resolve their variables.
|
|
2
|
+
|
|
3
|
+
Variables come from literals, environment variables, and Azure Key Vault secrets
|
|
4
|
+
(read through the Databricks ``dbutils.secrets`` API), and are substituted into the
|
|
5
|
+
``${VAR}`` placeholders of arbitrary JSON files.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import os
|
|
9
|
+
import json
|
|
10
|
+
import logging
|
|
11
|
+
from string import Template
|
|
12
|
+
|
|
13
|
+
logger = logging.getLogger(__name__)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def unresolved_variables(content, provided):
|
|
17
|
+
"""Variable names referenced as $name/${name} in content that provided does not supply."""
|
|
18
|
+
referenced = {match.group("named") or match.group("braced") for match in Template.pattern.finditer(content)}
|
|
19
|
+
referenced.discard(None) # escaped ($$) and invalid ($) matches contribute None
|
|
20
|
+
return sorted(referenced - set(provided))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class ConfigManager: # pylint: disable=too-few-public-methods
|
|
24
|
+
"""Reads JSON files and substitutes their ${VAR} placeholders from a variables file."""
|
|
25
|
+
|
|
26
|
+
def __init__(self, dbutils=None):
|
|
27
|
+
"""Initialize ConfigManager with the Databricks utilities used to read secrets.
|
|
28
|
+
|
|
29
|
+
``dbutils`` is only required when a variables file contains Key Vault secret
|
|
30
|
+
entries; literal- and environment-only files resolve without it.
|
|
31
|
+
"""
|
|
32
|
+
self.dbutils = dbutils
|
|
33
|
+
|
|
34
|
+
def read_variables(self, filepath: str) -> dict:
|
|
35
|
+
"""Read configuration variables from a JSON file.
|
|
36
|
+
|
|
37
|
+
Each entry maps a name to a value given in one of three forms: a literal string; an
|
|
38
|
+
environment-variable reference ``{"env": "NAME"}`` resolved from os.environ; or an Azure
|
|
39
|
+
Key Vault secret ``{"scope": ..., "key": ..., "base"?: ...}`` read via dbutils.
|
|
40
|
+
|
|
41
|
+
Resolution is two-pass so entries can reference each other: the first pass resolves the
|
|
42
|
+
literal and environment values, and the second resolves the secrets, substituting any
|
|
43
|
+
``${VAR}`` in their scope/key/base from the already-resolved first-pass values (e.g. a
|
|
44
|
+
secret whose scope comes from an environment variable). Unknown ``${VAR}`` are left intact,
|
|
45
|
+
so plain literal scopes are unaffected.
|
|
46
|
+
"""
|
|
47
|
+
with open(filepath, encoding="utf-8") as f:
|
|
48
|
+
content = json.load(f)
|
|
49
|
+
result = {}
|
|
50
|
+
|
|
51
|
+
# First pass: literal and environment values, which secret entries may reference.
|
|
52
|
+
for var_name, var_spec in content.items():
|
|
53
|
+
if isinstance(var_spec, str):
|
|
54
|
+
result[var_name] = Template(var_spec).safe_substitute(**result)
|
|
55
|
+
elif isinstance(var_spec, dict) and "env" in var_spec:
|
|
56
|
+
extra = set(var_spec) - {"env"}
|
|
57
|
+
if extra:
|
|
58
|
+
logger.error("Variable %r: env entry has unexpected key(s): %s", var_name, ", ".join(sorted(extra)))
|
|
59
|
+
result[var_name] = os.environ[var_spec["env"]]
|
|
60
|
+
|
|
61
|
+
# Second pass: Key Vault secrets, whose scope/key/base may reference first-pass values.
|
|
62
|
+
for var_name, var_spec in content.items():
|
|
63
|
+
if not isinstance(var_spec, dict) or "env" in var_spec:
|
|
64
|
+
continue
|
|
65
|
+
extra = set(var_spec) - {"scope", "key", "base"}
|
|
66
|
+
if extra:
|
|
67
|
+
logger.error("Variable %r: secret entry has unexpected key(s): %s", var_name, ", ".join(sorted(extra)))
|
|
68
|
+
if ("scope" in var_spec) != ("key" in var_spec):
|
|
69
|
+
logger.error("Variable %r: secret entry needs both 'scope' and 'key'; one is missing", var_name)
|
|
70
|
+
scope = var_spec.get("scope")
|
|
71
|
+
key = var_spec.get("key")
|
|
72
|
+
if scope and key:
|
|
73
|
+
value = self.dbutils.secrets.get(
|
|
74
|
+
Template(scope).safe_substitute(**result),
|
|
75
|
+
Template(key).safe_substitute(**result),
|
|
76
|
+
)
|
|
77
|
+
base = var_spec.get("base")
|
|
78
|
+
result[var_name] = base.format(value) if base else value
|
|
79
|
+
return result
|
|
80
|
+
|
|
81
|
+
def read_json(self, filepath: str, var_filepath: str = None) -> dict:
|
|
82
|
+
"""Read a JSON file, substituting ${VAR} placeholders from var_filepath when given.
|
|
83
|
+
|
|
84
|
+
Any placeholder the variables file does not supply is left intact and logged as a warning.
|
|
85
|
+
"""
|
|
86
|
+
with open(filepath, encoding="utf-8") as f:
|
|
87
|
+
content = f.read()
|
|
88
|
+
if var_filepath is not None:
|
|
89
|
+
variables = self.read_variables(var_filepath)
|
|
90
|
+
unresolved = unresolved_variables(content, variables)
|
|
91
|
+
if unresolved:
|
|
92
|
+
logger.warning("Unresolved variable(s) in %s: %s", filepath, ", ".join(unresolved))
|
|
93
|
+
content = Template(content).safe_substitute(**variables)
|
|
94
|
+
return json.loads(content)
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: brickvar
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Resolve Databricks config variables from literals, environment variables, and Azure Key Vault secrets, and substitute them into JSON config files.
|
|
5
|
+
Author-email: Afsin Ustundag <afsin@amida.com>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/amida-tech/brickvar
|
|
8
|
+
Project-URL: Repository, https://github.com/amida-tech/brickvar
|
|
9
|
+
Project-URL: Issues, https://github.com/amida-tech/brickvar/issues
|
|
10
|
+
Keywords: databricks,config,configuration,secrets,azure,key-vault
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
16
|
+
Requires-Python: >=3.9
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Provides-Extra: dev
|
|
20
|
+
Requires-Dist: pytest; extra == "dev"
|
|
21
|
+
Requires-Dist: pytest-mock; extra == "dev"
|
|
22
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
23
|
+
Requires-Dist: black; extra == "dev"
|
|
24
|
+
Requires-Dist: pylint; extra == "dev"
|
|
25
|
+
Requires-Dist: build; extra == "dev"
|
|
26
|
+
Requires-Dist: twine; extra == "dev"
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+
# brickvar
|
|
30
|
+
|
|
31
|
+
Resolve configuration variables for Databricks jobs from literals, environment
|
|
32
|
+
variables, and Azure Key Vault secrets, and substitute them into JSON config files.
|
|
33
|
+
|
|
34
|
+
`brickvar` reads a JSON "variables" file in which each entry is one of:
|
|
35
|
+
|
|
36
|
+
- a **literal** string (which may reference other variables with `${VAR}`),
|
|
37
|
+
- an **environment variable** reference — `{"env": "NAME"}`, or
|
|
38
|
+
- a **Databricks / Azure Key Vault secret** — `{"scope": ..., "key": ..., "base"?: ...}`,
|
|
39
|
+
read through the Databricks `dbutils.secrets` API.
|
|
40
|
+
|
|
41
|
+
Resolution is two-pass, so a secret's `scope`/`key` can themselves reference
|
|
42
|
+
already-resolved literal or environment values. It can also substitute `${VAR}`
|
|
43
|
+
placeholders into any JSON file, leaving unknown placeholders intact.
|
|
44
|
+
|
|
45
|
+
## Install
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pip install brickvar
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Usage
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
from brickvar import ConfigManager
|
|
55
|
+
|
|
56
|
+
# dbutils is provided by the Databricks runtime; required only when a
|
|
57
|
+
# variables file contains Key Vault secret entries.
|
|
58
|
+
cfg = ConfigManager(dbutils=dbutils)
|
|
59
|
+
|
|
60
|
+
# Resolve a variables file to a dict.
|
|
61
|
+
variables = cfg.read_variables("variables.json")
|
|
62
|
+
|
|
63
|
+
# Read a JSON file and substitute its ${VAR} placeholders from a variables file.
|
|
64
|
+
spec = cfg.read_json("spec.json", "variables.json")
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Example `variables.json`:
|
|
68
|
+
|
|
69
|
+
```json
|
|
70
|
+
{
|
|
71
|
+
"SECRET_SCOPE": { "env": "SECRET_SCOPE" },
|
|
72
|
+
"HOST": "example.documents.azure.us",
|
|
73
|
+
"CLIENT_ID": { "scope": "${SECRET_SCOPE}", "key": "SP-CLIENT-ID" },
|
|
74
|
+
"STORAGE": { "scope": "kv", "key": "ACCOUNT", "base": "abfss://data@{}/curated" }
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
- `HOST` is a literal.
|
|
79
|
+
- `SECRET_SCOPE` comes from the `SECRET_SCOPE` environment variable.
|
|
80
|
+
- `CLIENT_ID` is a secret whose scope is filled from the resolved `SECRET_SCOPE`.
|
|
81
|
+
- `STORAGE` is a secret wrapped by its `base` format string.
|
|
82
|
+
|
|
83
|
+
## Development
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
python -m venv venv && source venv/bin/activate
|
|
87
|
+
pip install -e ".[dev]"
|
|
88
|
+
pytest
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## License
|
|
92
|
+
|
|
93
|
+
[Apache-2.0](LICENSE)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/brickvar/__init__.py
|
|
5
|
+
src/brickvar/config.py
|
|
6
|
+
src/brickvar.egg-info/PKG-INFO
|
|
7
|
+
src/brickvar.egg-info/SOURCES.txt
|
|
8
|
+
src/brickvar.egg-info/dependency_links.txt
|
|
9
|
+
src/brickvar.egg-info/requires.txt
|
|
10
|
+
src/brickvar.egg-info/top_level.txt
|
|
11
|
+
tests/test_config.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
brickvar
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"""Tests for brickvar.config.ConfigManager."""
|
|
2
|
+
|
|
3
|
+
from brickvar import ConfigManager
|
|
4
|
+
from brickvar.config import unresolved_variables
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def test_read_variables_literal_and_cross_reference(mock_dbutils, write_json):
|
|
8
|
+
"""Literal entries resolve as-is, and a later literal may reference an earlier one."""
|
|
9
|
+
var_path = write_json("vars.json", {"BASE": "root", "CHILD": "${BASE}/child"})
|
|
10
|
+
|
|
11
|
+
result = ConfigManager(dbutils=mock_dbutils).read_variables(var_path)
|
|
12
|
+
|
|
13
|
+
assert result == {"BASE": "root", "CHILD": "root/child"}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def test_read_variables_from_environment(mock_dbutils, monkeypatch, write_json):
|
|
17
|
+
"""An {"env": NAME} entry resolves from an environment variable."""
|
|
18
|
+
monkeypatch.setenv("VASRD_PATH", "abfss://vasrd@account/current")
|
|
19
|
+
var_path = write_json("vars.json", {"VASRD_PATH": {"env": "VASRD_PATH"}})
|
|
20
|
+
|
|
21
|
+
result = ConfigManager(dbutils=mock_dbutils).read_variables(var_path)
|
|
22
|
+
|
|
23
|
+
assert result == {"VASRD_PATH": "abfss://vasrd@account/current"}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def test_read_variables_secret_with_base(mock_dbutils, write_json):
|
|
27
|
+
"""A secret entry reads via dbutils and applies the optional base format string."""
|
|
28
|
+
var_path = write_json(
|
|
29
|
+
"vars.json",
|
|
30
|
+
{
|
|
31
|
+
"PLAIN": {"scope": "s", "key": "k"},
|
|
32
|
+
"WRAPPED": {"scope": "s", "key": "k", "base": "abfss://ci@{}/zero"},
|
|
33
|
+
},
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
result = ConfigManager(dbutils=mock_dbutils).read_variables(var_path)
|
|
37
|
+
|
|
38
|
+
mock_dbutils.secrets.get.assert_any_call("s", "k")
|
|
39
|
+
assert result["PLAIN"] == "s_k_value"
|
|
40
|
+
assert result["WRAPPED"] == "abfss://ci@s_k_value/zero"
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def test_read_variables_secret_scope_from_environment(mock_dbutils, monkeypatch, write_json):
|
|
44
|
+
"""A secret entry's scope can reference an env-backed variable (two-pass resolution).
|
|
45
|
+
|
|
46
|
+
SCOPE is declared after the secret that uses it, confirming resolution is order-independent.
|
|
47
|
+
"""
|
|
48
|
+
monkeypatch.setenv("SECRET_SCOPE", "NeoSecretScope")
|
|
49
|
+
var_path = write_json(
|
|
50
|
+
"vars.json",
|
|
51
|
+
{
|
|
52
|
+
"URL": {"scope": "${SCOPE}", "key": "STORAGE-URL"},
|
|
53
|
+
"SCOPE": {"env": "SECRET_SCOPE"},
|
|
54
|
+
},
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
result = ConfigManager(dbutils=mock_dbutils).read_variables(var_path)
|
|
58
|
+
|
|
59
|
+
# The scope ${SCOPE} resolved to the env value before the secret was fetched.
|
|
60
|
+
mock_dbutils.secrets.get.assert_any_call("NeoSecretScope", "STORAGE-URL")
|
|
61
|
+
assert result["URL"] == "NeoSecretScope_STORAGE-URL_value"
|
|
62
|
+
assert result["SCOPE"] == "NeoSecretScope"
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def test_read_variables_skips_incomplete_secret(mock_dbutils, write_json):
|
|
66
|
+
"""A dict missing scope or key is not treated as a secret and is left out of the result."""
|
|
67
|
+
var_path = write_json(
|
|
68
|
+
"vars.json",
|
|
69
|
+
{"NO_KEY": {"scope": "s"}, "NO_SCOPE": {"key": "k"}, "GOOD": "literal"},
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
result = ConfigManager(dbutils=mock_dbutils).read_variables(var_path)
|
|
73
|
+
|
|
74
|
+
assert result == {"GOOD": "literal"}
|
|
75
|
+
mock_dbutils.secrets.get.assert_not_called()
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def test_read_variables_logs_error_for_env_entry_with_extra_key(mock_dbutils, monkeypatch, write_json, mocker):
|
|
79
|
+
"""An env entry with any key beyond 'env' logs an error but still resolves from the environment."""
|
|
80
|
+
monkeypatch.setenv("HOST", "example.com")
|
|
81
|
+
var_path = write_json("vars.json", {"HOST": {"env": "HOST", "scope": "oops"}})
|
|
82
|
+
error = mocker.patch("brickvar.config.logger.error")
|
|
83
|
+
|
|
84
|
+
result = ConfigManager(dbutils=mock_dbutils).read_variables(var_path)
|
|
85
|
+
|
|
86
|
+
assert result == {"HOST": "example.com"}
|
|
87
|
+
error.assert_called_once()
|
|
88
|
+
assert "scope" in error.call_args.args[-1]
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def test_read_variables_logs_error_for_secret_entry_with_unexpected_key(mock_dbutils, write_json, mocker):
|
|
92
|
+
"""A secret entry with keys outside scope/key/base logs an error but still resolves."""
|
|
93
|
+
var_path = write_json("vars.json", {"S": {"scope": "s", "key": "k", "bogus": 1}})
|
|
94
|
+
error = mocker.patch("brickvar.config.logger.error")
|
|
95
|
+
|
|
96
|
+
result = ConfigManager(dbutils=mock_dbutils).read_variables(var_path)
|
|
97
|
+
|
|
98
|
+
assert result["S"] == "s_k_value"
|
|
99
|
+
error.assert_called_once()
|
|
100
|
+
assert "bogus" in error.call_args.args[-1]
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def test_read_variables_logs_error_for_unpaired_scope_or_key(mock_dbutils, write_json, mocker):
|
|
104
|
+
"""A secret entry with only one of scope/key logs an error and is not fetched."""
|
|
105
|
+
var_path = write_json("vars.json", {"NO_KEY": {"scope": "s"}, "NO_SCOPE": {"key": "k"}})
|
|
106
|
+
error = mocker.patch("brickvar.config.logger.error")
|
|
107
|
+
|
|
108
|
+
result = ConfigManager(dbutils=mock_dbutils).read_variables(var_path)
|
|
109
|
+
|
|
110
|
+
assert result == {}
|
|
111
|
+
assert error.call_count == 2
|
|
112
|
+
mock_dbutils.secrets.get.assert_not_called()
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def test_read_variables_logs_no_error_for_valid_entries(mock_dbutils, write_json, mocker):
|
|
116
|
+
"""Well-formed literal, env, and secret (with optional base) entries produce no error logs."""
|
|
117
|
+
var_path = write_json(
|
|
118
|
+
"vars.json",
|
|
119
|
+
{
|
|
120
|
+
"LIT": "x",
|
|
121
|
+
"PLAIN": {"scope": "s", "key": "k"},
|
|
122
|
+
"WRAPPED": {"scope": "s", "key": "k", "base": "ci@{}"},
|
|
123
|
+
},
|
|
124
|
+
)
|
|
125
|
+
error = mocker.patch("brickvar.config.logger.error")
|
|
126
|
+
|
|
127
|
+
ConfigManager(dbutils=mock_dbutils).read_variables(var_path)
|
|
128
|
+
|
|
129
|
+
error.assert_not_called()
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def test_read_json_substitutes_variables(mock_dbutils, write_json):
|
|
133
|
+
"""read_json substitutes ${VAR} placeholders from the variables file."""
|
|
134
|
+
var_path = write_json("vars.json", {"HOST": "example.com", "DB": "grads"})
|
|
135
|
+
doc_path = write_json("doc.json", {"endpoint": "https://${HOST}", "database": "${DB}"})
|
|
136
|
+
|
|
137
|
+
result = ConfigManager(dbutils=mock_dbutils).read_json(doc_path, var_path)
|
|
138
|
+
|
|
139
|
+
assert result == {"endpoint": "https://example.com", "database": "grads"}
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def test_read_json_without_variables(mock_dbutils, write_json):
|
|
143
|
+
"""read_json with no variables file returns the JSON unchanged."""
|
|
144
|
+
doc_path = write_json("doc.json", {"a": 1, "b": "${UNTOUCHED}"})
|
|
145
|
+
|
|
146
|
+
result = ConfigManager(dbutils=mock_dbutils).read_json(doc_path)
|
|
147
|
+
|
|
148
|
+
assert result == {"a": 1, "b": "${UNTOUCHED}"}
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def test_read_json_warns_on_unresolved_variable(mock_dbutils, write_json, mocker):
|
|
152
|
+
"""A ${VAR} the variables file does not supply is left intact and logged as a warning."""
|
|
153
|
+
var_path = write_json("vars.json", {"PROVIDED": "ok"})
|
|
154
|
+
doc_path = write_json("doc.json", {"path": "${PROVIDED}", "extra": "${MISSING}"})
|
|
155
|
+
warning = mocker.patch("brickvar.config.logger.warning")
|
|
156
|
+
|
|
157
|
+
result = ConfigManager(dbutils=mock_dbutils).read_json(doc_path, var_path)
|
|
158
|
+
|
|
159
|
+
assert result == {"path": "ok", "extra": "${MISSING}"}
|
|
160
|
+
warning.assert_called_once()
|
|
161
|
+
# The warning names the unresolved variable, not the resolved one.
|
|
162
|
+
assert "MISSING" in warning.call_args.args[-1]
|
|
163
|
+
assert "PROVIDED" not in warning.call_args.args[-1]
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def test_unresolved_variables_helper():
|
|
167
|
+
"""unresolved_variables reports referenced names absent from provided, ignoring escapes."""
|
|
168
|
+
content = "${A} and $B and $$C and ${D}"
|
|
169
|
+
assert unresolved_variables(content, {"A": 1}) == ["B", "D"]
|