gitops-configserver 1.0.1__py3-none-any.whl
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.
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/gitops_mt/__init__.py +14 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/gitops_mt/cli.py +51 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/gitops_mt/config.py +27 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/gitops_mt/__init__.py +14 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/gitops_mt/cli.py +51 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/gitops_mt/config.py +27 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/gitops_mt/__init__.py +14 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/gitops_mt/cli.py +51 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/gitops_mt/config.py +27 -0
- build/lib/build/lib/build/lib/build/lib/gitops_mt/__init__.py +14 -0
- build/lib/build/lib/build/lib/build/lib/gitops_mt/cli.py +51 -0
- build/lib/build/lib/build/lib/build/lib/gitops_mt/config.py +27 -0
- build/lib/build/lib/build/lib/gitops_mt/__init__.py +14 -0
- build/lib/build/lib/build/lib/gitops_mt/cli.py +51 -0
- build/lib/build/lib/build/lib/gitops_mt/config.py +27 -0
- build/lib/build/lib/gitops_mt/__init__.py +14 -0
- build/lib/build/lib/gitops_mt/cli.py +51 -0
- build/lib/build/lib/gitops_mt/config.py +27 -0
- build/lib/gitops_mt/__init__.py +14 -0
- build/lib/gitops_mt/cli.py +51 -0
- build/lib/gitops_mt/config.py +27 -0
- build/lib/tests/__init__.py +0 -0
- build/lib/tests/test_rendering.py +153 -0
- build/lib/tests/test_variables_resolver.py +63 -0
- gitops_configserver/__init__.py +14 -0
- gitops_configserver/cli.py +87 -0
- gitops_configserver/config.py +45 -0
- gitops_configserver/configs/__init__.py +1 -0
- gitops_configserver/configs/views.py +22 -0
- gitops_configserver/extensions.py +8 -0
- gitops_configserver/git.py +90 -0
- gitops_configserver/server.py +15 -0
- gitops_configserver/templates_rendering.py +169 -0
- gitops_configserver/utils.py +39 -0
- gitops_configserver/workflow.py +71 -0
- gitops_configserver-1.0.1.dist-info/LICENSE +2 -0
- gitops_configserver-1.0.1.dist-info/METADATA +56 -0
- gitops_configserver-1.0.1.dist-info/RECORD +46 -0
- gitops_configserver-1.0.1.dist-info/WHEEL +5 -0
- gitops_configserver-1.0.1.dist-info/top_level.txt +8 -0
- gitops_mt/__init__.py +14 -0
- gitops_mt/cli.py +51 -0
- gitops_mt/config.py +27 -0
- tests/__init__.py +0 -0
- tests/test_rendering.py +153 -0
- tests/test_variables_resolver.py +63 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
from datetime import datetime, timezone
|
|
2
|
+
from os import makedirs, path
|
|
3
|
+
from shutil import rmtree, copyfile
|
|
4
|
+
from yaml import safe_load
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def create_dir(path):
|
|
8
|
+
makedirs(path, exist_ok=True)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def file_exists(fname):
|
|
12
|
+
return path.isfile(fname)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def read_file(filepath):
|
|
16
|
+
with open(filepath, "r") as f:
|
|
17
|
+
return f.read()
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def write_to_file(filepath, content):
|
|
21
|
+
with open(filepath, "w") as f:
|
|
22
|
+
f.write(content)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def remove_dir_with_content(dirpath):
|
|
26
|
+
rmtree(dirpath, ignore_errors=True)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def load_yaml(filepath):
|
|
30
|
+
with open(filepath, "r") as f:
|
|
31
|
+
return safe_load(f.read())
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def copy_file(src, dst):
|
|
35
|
+
copyfile(src, dst)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def timestamp():
|
|
39
|
+
return datetime.now(timezone.utc).isoformat()
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
from logging import getLogger
|
|
3
|
+
from gitops_configserver.templates_rendering import (
|
|
4
|
+
TemplatesRendering,
|
|
5
|
+
TenantsConfigLoader,
|
|
6
|
+
)
|
|
7
|
+
from gitops_configserver.git import GitProvisioner, GitWrapper
|
|
8
|
+
from gitops_configserver.utils import create_dir
|
|
9
|
+
|
|
10
|
+
logger = getLogger(__name__)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class WorkflowCommand(ABC):
|
|
14
|
+
@abstractmethod
|
|
15
|
+
def execute(self, request: dict = None) -> None:
|
|
16
|
+
pass
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class TemplatesRenderingCommand(WorkflowCommand):
|
|
20
|
+
def __init__(self, config):
|
|
21
|
+
self.config = config
|
|
22
|
+
self.tenants_config_loader = TenantsConfigLoader(config)
|
|
23
|
+
|
|
24
|
+
def execute(self, request: dict = None) -> dict:
|
|
25
|
+
create_dir(self.config.TARGET_DIR)
|
|
26
|
+
tenants_list = self.tenants_config_loader.index().get("tenants", [])
|
|
27
|
+
repo_files = {}
|
|
28
|
+
for tenant_name in tenants_list:
|
|
29
|
+
templates_rendering = TemplatesRendering(self.config)
|
|
30
|
+
repositories_files = templates_rendering.render(tenant_name)
|
|
31
|
+
repo_files[tenant_name] = repositories_files
|
|
32
|
+
logger.info(f"repo_files: {repo_files}")
|
|
33
|
+
return repo_files
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class GitRepositoriesCommitterCommand(WorkflowCommand):
|
|
37
|
+
def __init__(self, config):
|
|
38
|
+
self.config = config
|
|
39
|
+
self.tenants_config_loader = TenantsConfigLoader(config)
|
|
40
|
+
self.git_wrapper = GitWrapper(self.config)
|
|
41
|
+
|
|
42
|
+
def execute(self, request: dict = None) -> dict:
|
|
43
|
+
tenants_list = self.tenants_config_loader.index().get("tenants", [])
|
|
44
|
+
global_repositories = self.tenants_config_loader.index().get(
|
|
45
|
+
"repositories", []
|
|
46
|
+
)
|
|
47
|
+
for repository_name, repository_value in global_repositories.items():
|
|
48
|
+
global_repositories[repository_name]["files"] = []
|
|
49
|
+
for tenant_name in tenants_list:
|
|
50
|
+
# tenant_config = self.tenants_config_loader.tenant(tenant_name)
|
|
51
|
+
for file_entry in request[tenant_name]["files"]:
|
|
52
|
+
if file_entry.get("repo") in global_repositories:
|
|
53
|
+
global_repositories[repository_name]["files"] += [
|
|
54
|
+
file_entry
|
|
55
|
+
]
|
|
56
|
+
logger.info(f"global_repositories: {global_repositories}")
|
|
57
|
+
git_provisioner = GitProvisioner(self.config, self.git_wrapper)
|
|
58
|
+
result = git_provisioner.provision(global_repositories)
|
|
59
|
+
return result
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class Workflow:
|
|
63
|
+
def __init__(self, config):
|
|
64
|
+
self.config = config
|
|
65
|
+
self.request = {}
|
|
66
|
+
|
|
67
|
+
def execute(self) -> None:
|
|
68
|
+
commands = [TemplatesRenderingCommand, GitRepositoriesCommitterCommand]
|
|
69
|
+
for command in commands:
|
|
70
|
+
response = command(self.config).execute(self.request)
|
|
71
|
+
self.request = response
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: gitops-configserver
|
|
3
|
+
Version: 1.0.1
|
|
4
|
+
Author-email: Piotr Przetacznik <piotr.przetacznik+gitops@gmail.com>
|
|
5
|
+
License: All rights reserved by Piotr Przetacznik.
|
|
6
|
+
MIT License.
|
|
7
|
+
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Requires-Dist: pytest
|
|
13
|
+
Requires-Dist: Jinja2
|
|
14
|
+
Requires-Dist: pyyaml
|
|
15
|
+
Requires-Dist: Flask
|
|
16
|
+
Requires-Dist: flask-restful
|
|
17
|
+
|
|
18
|
+
# GitOps Configserver
|
|
19
|
+
|
|
20
|
+
[](https://github.com/pprzetacznik/gitops-configserver/actions/workflows/test.yml)
|
|
21
|
+
|
|
22
|
+
Inspired by puppet, kustomized and GitOps practices.
|
|
23
|
+
|
|
24
|
+
## Planned features
|
|
25
|
+
|
|
26
|
+
* multitenant templates
|
|
27
|
+
* hieradata variables
|
|
28
|
+
* flask rest service
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
$ python -m gitops_server.cli config_gen -h
|
|
34
|
+
usage: cli.py config_gen [-h] --config_dir CONFIG_DIR
|
|
35
|
+
|
|
36
|
+
options:
|
|
37
|
+
-h, --help show this help message and exit
|
|
38
|
+
--config_dir CONFIG_DIR
|
|
39
|
+
Config directory
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
$ python -m gitops_server.cli server --config_dir=config
|
|
44
|
+
...
|
|
45
|
+
$ curl http://localhost:8002/configs
|
|
46
|
+
{"tenants":["tenant1"]}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Setting up GitHub tokens
|
|
50
|
+
|
|
51
|
+
* Go to Setting -> Developer Settings -> Fine-grained personal access tokens
|
|
52
|
+
* Create a token with following settings:
|
|
53
|
+
* `Only select repositories` and select your repository
|
|
54
|
+
* `Repository permissions` and select `Content`
|
|
55
|
+
|
|
56
|
+
Set the token as `$GH_PAT` in your local environment.
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/gitops_mt/__init__.py,sha256=EJUN98M90F9whuy2_ERacVa5nlC4Ji_oCyqY_TElOMk,350
|
|
2
|
+
build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/gitops_mt/cli.py,sha256=3p5Hia5qDDWsnV4sedxmExpKSib5l1vmGwqJIRAQknU,1269
|
|
3
|
+
build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/gitops_mt/config.py,sha256=AGHoubWfoKpA8N5bDKPIJnZnI0hovbnZYoBRpGKodkI,702
|
|
4
|
+
build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/gitops_mt/__init__.py,sha256=EJUN98M90F9whuy2_ERacVa5nlC4Ji_oCyqY_TElOMk,350
|
|
5
|
+
build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/gitops_mt/cli.py,sha256=3p5Hia5qDDWsnV4sedxmExpKSib5l1vmGwqJIRAQknU,1269
|
|
6
|
+
build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/gitops_mt/config.py,sha256=AGHoubWfoKpA8N5bDKPIJnZnI0hovbnZYoBRpGKodkI,702
|
|
7
|
+
build/lib/build/lib/build/lib/build/lib/build/lib/gitops_mt/__init__.py,sha256=EJUN98M90F9whuy2_ERacVa5nlC4Ji_oCyqY_TElOMk,350
|
|
8
|
+
build/lib/build/lib/build/lib/build/lib/build/lib/gitops_mt/cli.py,sha256=3p5Hia5qDDWsnV4sedxmExpKSib5l1vmGwqJIRAQknU,1269
|
|
9
|
+
build/lib/build/lib/build/lib/build/lib/build/lib/gitops_mt/config.py,sha256=AGHoubWfoKpA8N5bDKPIJnZnI0hovbnZYoBRpGKodkI,702
|
|
10
|
+
build/lib/build/lib/build/lib/build/lib/gitops_mt/__init__.py,sha256=EJUN98M90F9whuy2_ERacVa5nlC4Ji_oCyqY_TElOMk,350
|
|
11
|
+
build/lib/build/lib/build/lib/build/lib/gitops_mt/cli.py,sha256=3p5Hia5qDDWsnV4sedxmExpKSib5l1vmGwqJIRAQknU,1269
|
|
12
|
+
build/lib/build/lib/build/lib/build/lib/gitops_mt/config.py,sha256=AGHoubWfoKpA8N5bDKPIJnZnI0hovbnZYoBRpGKodkI,702
|
|
13
|
+
build/lib/build/lib/build/lib/gitops_mt/__init__.py,sha256=EJUN98M90F9whuy2_ERacVa5nlC4Ji_oCyqY_TElOMk,350
|
|
14
|
+
build/lib/build/lib/build/lib/gitops_mt/cli.py,sha256=3p5Hia5qDDWsnV4sedxmExpKSib5l1vmGwqJIRAQknU,1269
|
|
15
|
+
build/lib/build/lib/build/lib/gitops_mt/config.py,sha256=AGHoubWfoKpA8N5bDKPIJnZnI0hovbnZYoBRpGKodkI,702
|
|
16
|
+
build/lib/build/lib/gitops_mt/__init__.py,sha256=EJUN98M90F9whuy2_ERacVa5nlC4Ji_oCyqY_TElOMk,350
|
|
17
|
+
build/lib/build/lib/gitops_mt/cli.py,sha256=3p5Hia5qDDWsnV4sedxmExpKSib5l1vmGwqJIRAQknU,1269
|
|
18
|
+
build/lib/build/lib/gitops_mt/config.py,sha256=AGHoubWfoKpA8N5bDKPIJnZnI0hovbnZYoBRpGKodkI,702
|
|
19
|
+
build/lib/gitops_mt/__init__.py,sha256=EJUN98M90F9whuy2_ERacVa5nlC4Ji_oCyqY_TElOMk,350
|
|
20
|
+
build/lib/gitops_mt/cli.py,sha256=3p5Hia5qDDWsnV4sedxmExpKSib5l1vmGwqJIRAQknU,1269
|
|
21
|
+
build/lib/gitops_mt/config.py,sha256=AGHoubWfoKpA8N5bDKPIJnZnI0hovbnZYoBRpGKodkI,702
|
|
22
|
+
build/lib/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
23
|
+
build/lib/tests/test_rendering.py,sha256=HtH5LfSwrcVIQQ9TxHksoOh8gsLYOAp-u-fkzZTxOmM,7343
|
|
24
|
+
build/lib/tests/test_variables_resolver.py,sha256=s6-Op4FEaA1y_Plis5ygmRNXlimQ7M5pzp6bQhfj7KM,1746
|
|
25
|
+
gitops_configserver/__init__.py,sha256=ZcD8Cj9x6p724j8ONaoaGPrlIjro5ilkHaRELjBKpU8,360
|
|
26
|
+
gitops_configserver/cli.py,sha256=SuGRk4-7A9UIGBTSvVqrEB9SNrL6QhJ79sToWexMKpc,2417
|
|
27
|
+
gitops_configserver/config.py,sha256=HaAXgYcyUuzUlLDx2LMkvA9JSfL9a0lIAOF8O06mBc4,1456
|
|
28
|
+
gitops_configserver/extensions.py,sha256=sYuwZONE5Z6imikrx5Zf5LxYSjXIkz5eimGlIhFk1BQ,127
|
|
29
|
+
gitops_configserver/git.py,sha256=1prW5XaSKvznWX3cRJxHv2VNzzOI77KeGif-NEbzHGA,3475
|
|
30
|
+
gitops_configserver/server.py,sha256=eOrTHWPi0fSkTk4oFl69jvR5hHGvNvkDzucVvFFRxXQ,457
|
|
31
|
+
gitops_configserver/templates_rendering.py,sha256=ppN5w8NojUTm7sanDy6_ToAcjoiXrSVXTr0WGTVVIm4,6003
|
|
32
|
+
gitops_configserver/utils.py,sha256=ShLl7az_2hMbv4KYXQp1StWBP2EBUB-wdvBwZMrUjWk,729
|
|
33
|
+
gitops_configserver/workflow.py,sha256=2zXtrfrWdh7oLTvYCredxzgVLfIy35vTwCRdKlLDHsI,2685
|
|
34
|
+
gitops_configserver/configs/__init__.py,sha256=omTfkhGvwoA7VNxY3CBRpuUV-3Z7QzMZoOcYPP5aO-A,46
|
|
35
|
+
gitops_configserver/configs/views.py,sha256=uMrGzXz3P1Qr-O--nOwbao3gIKeA4XIvKCvMUJpdw8g,599
|
|
36
|
+
gitops_mt/__init__.py,sha256=EJUN98M90F9whuy2_ERacVa5nlC4Ji_oCyqY_TElOMk,350
|
|
37
|
+
gitops_mt/cli.py,sha256=3p5Hia5qDDWsnV4sedxmExpKSib5l1vmGwqJIRAQknU,1269
|
|
38
|
+
gitops_mt/config.py,sha256=AGHoubWfoKpA8N5bDKPIJnZnI0hovbnZYoBRpGKodkI,702
|
|
39
|
+
tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
40
|
+
tests/test_rendering.py,sha256=HtH5LfSwrcVIQQ9TxHksoOh8gsLYOAp-u-fkzZTxOmM,7343
|
|
41
|
+
tests/test_variables_resolver.py,sha256=s6-Op4FEaA1y_Plis5ygmRNXlimQ7M5pzp6bQhfj7KM,1746
|
|
42
|
+
gitops_configserver-1.0.1.dist-info/LICENSE,sha256=ZaCV8VcnO8I437jBDtRwUhsGyzF4kAkRjsUJ-DG3VRo,55
|
|
43
|
+
gitops_configserver-1.0.1.dist-info/METADATA,sha256=afpj1NgY90v5XVOV5Bx0rMAYmmbheyxntMxv7NdIQQ4,1553
|
|
44
|
+
gitops_configserver-1.0.1.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
|
|
45
|
+
gitops_configserver-1.0.1.dist-info/top_level.txt,sha256=YaeQA33XakFacflzVkp4pcXsZH1Mnn3rlpW_povpFGw,66
|
|
46
|
+
gitops_configserver-1.0.1.dist-info/RECORD,,
|
gitops_mt/__init__.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from os.path import join, dirname
|
|
2
|
+
from importlib import metadata
|
|
3
|
+
from importlib.metadata import PackageNotFoundError
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def read(fname):
|
|
7
|
+
with open(join(dirname(__file__), fname)) as f:
|
|
8
|
+
return f.read()
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
try:
|
|
12
|
+
__version__ = metadata.version("gitops-mt")
|
|
13
|
+
except PackageNotFoundError:
|
|
14
|
+
__version__ = read(join("..", "VERSION")).strip()
|
gitops_mt/cli.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
from argparse import Namespace, ArgumentParser
|
|
2
|
+
from abc import ABC, abstractmethod
|
|
3
|
+
from gitops_mt.config import setup_logger, Config
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class AbstractArgumentsHandler(ABC):
|
|
7
|
+
"""Command pattern interface"""
|
|
8
|
+
|
|
9
|
+
@abstractmethod
|
|
10
|
+
def execute(self, args) -> None:
|
|
11
|
+
pass
|
|
12
|
+
|
|
13
|
+
@abstractmethod
|
|
14
|
+
def add_parser(self, subparsers):
|
|
15
|
+
pass
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class ConfigGeneratorHandler(AbstractArgumentsHandler):
|
|
19
|
+
def execute(self, args):
|
|
20
|
+
config = Config()
|
|
21
|
+
print("HELLO WORLD")
|
|
22
|
+
|
|
23
|
+
def add_parser(self, subparsers):
|
|
24
|
+
parser_config_generator = subparsers.add_parser("config_gen")
|
|
25
|
+
parser_config_generator.set_defaults(func=self.execute)
|
|
26
|
+
parser_config_generator.add_argument(
|
|
27
|
+
"--config_dir",
|
|
28
|
+
type=str,
|
|
29
|
+
help="Config directory",
|
|
30
|
+
dest="config_dir",
|
|
31
|
+
required=True,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def parse_arguments() -> Namespace:
|
|
36
|
+
parser = ArgumentParser(
|
|
37
|
+
description="GitOps multitenancy templates generator"
|
|
38
|
+
)
|
|
39
|
+
subparsers = parser.add_subparsers(required=True)
|
|
40
|
+
ConfigGeneratorHandler().add_parser(subparsers)
|
|
41
|
+
return parser.parse_args()
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def main() -> None:
|
|
45
|
+
setup_logger()
|
|
46
|
+
args = parse_arguments()
|
|
47
|
+
args.func(args)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
if __name__ == "__main__":
|
|
51
|
+
main()
|
gitops_mt/config.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from os import getenv, path
|
|
2
|
+
import logging
|
|
3
|
+
import logging.config
|
|
4
|
+
import yaml
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def file_exists(fname):
|
|
8
|
+
return path.isfile(fname)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def setup_logger():
|
|
12
|
+
if file_exists(Config.LOGGER_CONFIG_FILE):
|
|
13
|
+
with open(Config.LOGGER_CONFIG_FILE, "rt") as f:
|
|
14
|
+
config = yaml.safe_load(f.read())
|
|
15
|
+
logging.config.dictConfig(config)
|
|
16
|
+
else:
|
|
17
|
+
logging.basicConfig(filename="myapp.log", level=logging.INFO)
|
|
18
|
+
logger = logging.getLogger(__name__)
|
|
19
|
+
logger.info("Started")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class Config:
|
|
23
|
+
LOGGER_CONFIG_FILE = getenv(
|
|
24
|
+
"GITOPS_MT__LOGGER_CONFIG_FILE", path.join("resources", "logger.yaml")
|
|
25
|
+
)
|
|
26
|
+
CONFIG_DIR = getenv("GITOPS_MT__CONFIG_DIR")
|
|
27
|
+
LOGS_VERBOSE = True
|
tests/__init__.py
ADDED
|
File without changes
|
tests/test_rendering.py
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
from os.path import join
|
|
2
|
+
from pytest import fixture
|
|
3
|
+
from gitops_configserver.config import Config
|
|
4
|
+
from gitops_configserver.workflow import TemplatesRenderingCommand
|
|
5
|
+
from gitops_configserver.utils import read_file, remove_dir_with_content
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@fixture
|
|
9
|
+
def config():
|
|
10
|
+
config = Config()
|
|
11
|
+
config.CONFIG_DIR = "resources/test_config"
|
|
12
|
+
config.TARGET_DIR = "target_test_configserver"
|
|
13
|
+
return config
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@fixture
|
|
17
|
+
def templates_rendering_command(config):
|
|
18
|
+
yield TemplatesRenderingCommand(config)
|
|
19
|
+
# remove_dir_with_content(config.TARGET_DIR)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def test_rendering(templates_rendering_command, config):
|
|
23
|
+
repo_files = templates_rendering_command.execute()
|
|
24
|
+
assert repo_files == {
|
|
25
|
+
"tenant1": {
|
|
26
|
+
"repositories": {
|
|
27
|
+
"test_repo1": {"type": "local", "url": "local_path"}
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
{
|
|
31
|
+
"tmp_path": "target_test_configserver/tenant1/asdf/config1-ubuntu-22.04-10-python3.10-prod.yml",
|
|
32
|
+
"destination_filename": "asdf/config1-ubuntu-22.04-10-python3.10-prod.yml",
|
|
33
|
+
"repo": "gitops-configserver-tests",
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"tmp_path": "target_test_configserver/tenant1/asdf/config1-ubuntu-22.04-10-python3.11-prod.yml",
|
|
37
|
+
"destination_filename": "asdf/config1-ubuntu-22.04-10-python3.11-prod.yml",
|
|
38
|
+
"repo": "gitops-configserver-tests",
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"tmp_path": "target_test_configserver/tenant1/asdf/config1-ubuntu-22.04-10-python3.12-prod.yml",
|
|
42
|
+
"destination_filename": "asdf/config1-ubuntu-22.04-10-python3.12-prod.yml",
|
|
43
|
+
"repo": "gitops-configserver-tests",
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"tmp_path": "target_test_configserver/tenant1/asdf/config1-ubuntu-22.04-12-python3.10-prod.yml",
|
|
47
|
+
"destination_filename": "asdf/config1-ubuntu-22.04-12-python3.10-prod.yml",
|
|
48
|
+
"repo": "gitops-configserver-tests",
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"tmp_path": "target_test_configserver/tenant1/asdf/config1-ubuntu-22.04-12-python3.11-prod.yml",
|
|
52
|
+
"destination_filename": "asdf/config1-ubuntu-22.04-12-python3.11-prod.yml",
|
|
53
|
+
"repo": "gitops-configserver-tests",
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"tmp_path": "target_test_configserver/tenant1/asdf/config1-ubuntu-22.04-12-python3.12-prod.yml",
|
|
57
|
+
"destination_filename": "asdf/config1-ubuntu-22.04-12-python3.12-prod.yml",
|
|
58
|
+
"repo": "gitops-configserver-tests",
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"tmp_path": "target_test_configserver/tenant1/asdf/config1-ubuntu-22.04-14-python3.10-prod.yml",
|
|
62
|
+
"destination_filename": "asdf/config1-ubuntu-22.04-14-python3.10-prod.yml",
|
|
63
|
+
"repo": "gitops-configserver-tests",
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"tmp_path": "target_test_configserver/tenant1/asdf/config1-ubuntu-22.04-14-python3.11-prod.yml",
|
|
67
|
+
"destination_filename": "asdf/config1-ubuntu-22.04-14-python3.11-prod.yml",
|
|
68
|
+
"repo": "gitops-configserver-tests",
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
"tmp_path": "target_test_configserver/tenant1/asdf/config1-ubuntu-22.04-14-python3.12-prod.yml",
|
|
72
|
+
"destination_filename": "asdf/config1-ubuntu-22.04-14-python3.12-prod.yml",
|
|
73
|
+
"repo": "gitops-configserver-tests",
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"tmp_path": "target_test_configserver/tenant1/asdf/config1-ubuntu-20.04-10-python3.10-prod.yml",
|
|
77
|
+
"destination_filename": "asdf/config1-ubuntu-20.04-10-python3.10-prod.yml",
|
|
78
|
+
"repo": "gitops-configserver-tests",
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
"tmp_path": "target_test_configserver/tenant1/asdf/config1-ubuntu-20.04-10-python3.11-prod.yml",
|
|
82
|
+
"destination_filename": "asdf/config1-ubuntu-20.04-10-python3.11-prod.yml",
|
|
83
|
+
"repo": "gitops-configserver-tests",
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
"tmp_path": "target_test_configserver/tenant1/asdf/config1-ubuntu-20.04-10-python3.12-prod.yml",
|
|
87
|
+
"destination_filename": "asdf/config1-ubuntu-20.04-10-python3.12-prod.yml",
|
|
88
|
+
"repo": "gitops-configserver-tests",
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
"tmp_path": "target_test_configserver/tenant1/asdf/config1-ubuntu-20.04-12-python3.10-prod.yml",
|
|
92
|
+
"destination_filename": "asdf/config1-ubuntu-20.04-12-python3.10-prod.yml",
|
|
93
|
+
"repo": "gitops-configserver-tests",
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
"tmp_path": "target_test_configserver/tenant1/asdf/config1-ubuntu-20.04-12-python3.11-prod.yml",
|
|
97
|
+
"destination_filename": "asdf/config1-ubuntu-20.04-12-python3.11-prod.yml",
|
|
98
|
+
"repo": "gitops-configserver-tests",
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
"tmp_path": "target_test_configserver/tenant1/asdf/config1-ubuntu-20.04-12-python3.12-prod.yml",
|
|
102
|
+
"destination_filename": "asdf/config1-ubuntu-20.04-12-python3.12-prod.yml",
|
|
103
|
+
"repo": "gitops-configserver-tests",
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
"tmp_path": "target_test_configserver/tenant1/asdf/config1-ubuntu-20.04-14-python3.10-prod.yml",
|
|
107
|
+
"destination_filename": "asdf/config1-ubuntu-20.04-14-python3.10-prod.yml",
|
|
108
|
+
"repo": "gitops-configserver-tests",
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
"tmp_path": "target_test_configserver/tenant1/asdf/config1-ubuntu-20.04-14-python3.11-prod.yml",
|
|
112
|
+
"destination_filename": "asdf/config1-ubuntu-20.04-14-python3.11-prod.yml",
|
|
113
|
+
"repo": "gitops-configserver-tests",
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
"tmp_path": "target_test_configserver/tenant1/asdf/config1-ubuntu-20.04-14-python3.12-prod.yml",
|
|
117
|
+
"destination_filename": "asdf/config1-ubuntu-20.04-14-python3.12-prod.yml",
|
|
118
|
+
"repo": "gitops-configserver-tests",
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
"tmp_path": "target_test_configserver/tenant1/asdf/config1-ubuntu-22.04-10-python3.7-prod.yml",
|
|
122
|
+
"destination_filename": "asdf/config1-ubuntu-22.04-10-python3.7-prod.yml",
|
|
123
|
+
"repo": "gitops-configserver-tests",
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
"tmp_path": "target_test_configserver/tenant1/config1-prod.yml",
|
|
127
|
+
"destination_filename": "config1-prod.yml",
|
|
128
|
+
"repo": "test_repo1",
|
|
129
|
+
},
|
|
130
|
+
],
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
print(repo_files)
|
|
134
|
+
content = read_file(
|
|
135
|
+
join(
|
|
136
|
+
config.TARGET_DIR,
|
|
137
|
+
"tenant1",
|
|
138
|
+
"asdf",
|
|
139
|
+
"config1-ubuntu-22.04-10-python3.12-prod.yml",
|
|
140
|
+
)
|
|
141
|
+
)
|
|
142
|
+
assert (
|
|
143
|
+
content
|
|
144
|
+
== """- my_config:
|
|
145
|
+
- var1: aaa1.default
|
|
146
|
+
- var2: bbb1.default
|
|
147
|
+
- var3: ccc1.default
|
|
148
|
+
- lll: |
|
|
149
|
+
- abc: 1
|
|
150
|
+
def: 2
|
|
151
|
+
ghi: 3
|
|
152
|
+
- mmm: 4"""
|
|
153
|
+
)
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
from gitops_configserver.templates_rendering import (
|
|
2
|
+
VariablesResolver,
|
|
3
|
+
MatrixResolver,
|
|
4
|
+
)
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def test_variables_resolver():
|
|
8
|
+
template_variables_mapping = [
|
|
9
|
+
{"tenant_variable": "aaa", "tpl_variable": "template.var1"},
|
|
10
|
+
{"tenant_variable": "bbb", "tpl_variable": "template.var2"},
|
|
11
|
+
{"tenant_variable": "ccc", "tpl_variable": "template.var3"},
|
|
12
|
+
]
|
|
13
|
+
tenant_variables = {
|
|
14
|
+
"aaa": "aaa1.default",
|
|
15
|
+
"bbb": "bbb1.default",
|
|
16
|
+
"ccc": "ccc1.default",
|
|
17
|
+
}
|
|
18
|
+
resolved_variables = VariablesResolver.resolve_for_template(
|
|
19
|
+
template_variables_mapping,
|
|
20
|
+
tenant_variables,
|
|
21
|
+
)
|
|
22
|
+
assert resolved_variables == {
|
|
23
|
+
"template.var1": "aaa1.default",
|
|
24
|
+
"template.var2": "bbb1.default",
|
|
25
|
+
"template.var3": "ccc1.default",
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def test_matrix_resolver():
|
|
30
|
+
tenant_variables = {
|
|
31
|
+
"aaa": "aaa1.default",
|
|
32
|
+
"bbb": "bbb1.default",
|
|
33
|
+
"ccc": "ccc1.default",
|
|
34
|
+
"python_version": ["3.11", "3.12"],
|
|
35
|
+
}
|
|
36
|
+
matrix = {
|
|
37
|
+
"os": ["ubuntu-22.04", "ubuntu-20.04"],
|
|
38
|
+
"version": ["10"],
|
|
39
|
+
"python_version": "{{ python_version }}",
|
|
40
|
+
}
|
|
41
|
+
resolved_variants = MatrixResolver.resolve(matrix, tenant_variables)
|
|
42
|
+
assert resolved_variants == [
|
|
43
|
+
{
|
|
44
|
+
"os": "ubuntu-22.04",
|
|
45
|
+
"python_version": "3.11",
|
|
46
|
+
"version": "10",
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"os": "ubuntu-22.04",
|
|
50
|
+
"python_version": "3.12",
|
|
51
|
+
"version": "10",
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"os": "ubuntu-20.04",
|
|
55
|
+
"python_version": "3.11",
|
|
56
|
+
"version": "10",
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"os": "ubuntu-20.04",
|
|
60
|
+
"python_version": "3.12",
|
|
61
|
+
"version": "10",
|
|
62
|
+
},
|
|
63
|
+
]
|