|
1 | 1 | # SPDX-License-Identifier: MPL-2.0 |
2 | | -# Copyright 2020-2021 John Mille<[email protected]> |
| 2 | +# Copyright 2020-2022 John Mille<[email protected]> |
3 | 3 |
|
4 | 4 | """Main module.""" |
5 | 5 |
|
| 6 | +from __future__ import annotations |
| 7 | + |
| 8 | +from typing import TYPE_CHECKING |
| 9 | + |
| 10 | +if TYPE_CHECKING: |
| 11 | + from .input import Model |
| 12 | + |
6 | 13 | import json |
7 | 14 | import uuid |
8 | 15 | from os import environ, path |
|
13 | 20 |
|
14 | 21 | from ecs_files_composer import input |
15 | 22 | from ecs_files_composer.aws_mgmt import S3Fetcher, SecretFetcher, SsmFetcher |
| 23 | +from ecs_files_composer.certbot_aws_store import handle_certbot_store_certificates |
16 | 24 | from ecs_files_composer.certificates_mgmt import process_x509_certs |
17 | 25 | from ecs_files_composer.common import LOG |
18 | 26 | from ecs_files_composer.files_mgmt import File |
@@ -110,23 +118,29 @@ def init_config( |
110 | 118 | raise |
111 | 119 |
|
112 | 120 |
|
113 | | -def start_jobs(config, override_session=None): |
| 121 | +def process_files(job: Model, override_session=None) -> None: |
| 122 | + files: list = [] |
| 123 | + for file_path, file in job.files.items(): |
| 124 | + file_redef = File(**file.dict()) |
| 125 | + file_redef.path = file_path |
| 126 | + files.append(file_redef) |
| 127 | + for file in files: |
| 128 | + file.handler(job.iam_override, override_session) |
| 129 | + LOG.info(f"Tasks for {file.path} completed.") |
| 130 | + |
| 131 | + |
| 132 | +def start_jobs(config: dict, override_session=None): |
114 | 133 | """ |
115 | 134 | Starting point to run the files job |
116 | 135 |
|
117 | 136 | :param config: |
118 | 137 | :param override_session: |
119 | 138 | :return: |
120 | 139 | """ |
121 | | - if not keyisset("files", config): |
122 | | - raise KeyError("Missing required files from configuration input") |
123 | | - job = input.Model(files=config["files"]).parse_obj(config) |
124 | | - process_x509_certs(job) |
125 | | - for file_path, file in job.files.items(): |
126 | | - if not isinstance(file, File): |
127 | | - file_def = File().parse_obj(file) |
128 | | - job.files[file_path] = file_def |
129 | | - file_def.path = file_path |
130 | | - for file in job.files.values(): |
131 | | - file.handler(job.iam_override, override_session) |
132 | | - LOG.info(f"Tasks for {file.path} completed.") |
| 140 | + job = input.Model(**config) |
| 141 | + if job.certificates: |
| 142 | + process_x509_certs(job) |
| 143 | + if job.certbot_store: |
| 144 | + handle_certbot_store_certificates(job) |
| 145 | + if job.files: |
| 146 | + process_files(job, override_session) |
0 commit comments