|
5 | 5 |
|
6 | 6 | from __future__ import annotations |
7 | 7 |
|
| 8 | +import os |
8 | 9 | from typing import TYPE_CHECKING |
9 | 10 |
|
10 | 11 | if TYPE_CHECKING: |
11 | 12 | from .input import Model |
12 | 13 |
|
13 | 14 | import json |
14 | | -import uuid |
15 | 15 | from os import environ, path |
16 | 16 | from tempfile import TemporaryDirectory |
17 | 17 |
|
18 | 18 | import yaml |
19 | | -from compose_x_common.compose_x_common import keyisset |
20 | 19 | from yaml import Loader |
21 | 20 |
|
22 | 21 | from ecs_files_composer import input |
23 | | -from ecs_files_composer.aws_mgmt import S3Fetcher, SecretFetcher, SsmFetcher |
| 22 | +from ecs_files_composer.aws_mgmt import S3Fetcher |
24 | 23 | from ecs_files_composer.certbot_aws_store import handle_certbot_store_certificates |
25 | 24 | from ecs_files_composer.certificates_mgmt import process_x509_certs |
26 | 25 | from ecs_files_composer.common import LOG |
@@ -110,18 +109,22 @@ def init_config( |
110 | 109 | if context: |
111 | 110 | initial_config["context"] = context |
112 | 111 | start_jobs(jobs_input_def) |
113 | | - with open(config_path) as config_fd: |
114 | | - try: |
115 | | - config = yaml.load(config_fd.read(), Loader=Loader) |
116 | | - LOG.info(f"Successfully loaded YAML config {config_path}") |
117 | | - return config |
118 | | - except yaml.YAMLError: |
119 | | - config = json.loads(config_fd.read()) |
120 | | - LOG.info(f"Successfully loaded JSON config {config_path}") |
121 | | - return config |
122 | | - except Exception: |
123 | | - LOG.error("Input content is neither JSON nor YAML formatted") |
124 | | - raise |
| 112 | + try: |
| 113 | + with open(config_path) as config_fd: |
| 114 | + try: |
| 115 | + config = yaml.load(config_fd.read(), Loader=Loader) |
| 116 | + LOG.info(f"Successfully loaded YAML config {config_path}") |
| 117 | + return config |
| 118 | + except yaml.YAMLError: |
| 119 | + config = json.loads(config_fd.read()) |
| 120 | + LOG.info(f"Successfully loaded JSON config {config_path}") |
| 121 | + return config |
| 122 | + except Exception: |
| 123 | + LOG.error("Input content is neither JSON nor YAML formatted") |
| 124 | + raise |
| 125 | + except OSError as error: |
| 126 | + LOG.exception(error) |
| 127 | + LOG.error(f"Failed to read input file from {config_path}") |
125 | 128 |
|
126 | 129 |
|
127 | 130 | def process_files(job: Model, override_session=None) -> None: |
|
0 commit comments