Skip to content

Commit c28ab0b

Browse files
committed
Using proper temp dir and external_id variable
1 parent 36bad7f commit c28ab0b

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

ecs_files_composer/certbot_aws_store.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,18 @@
1212
if TYPE_CHECKING:
1313
from .input import Model
1414

15+
from os import makedirs, path
16+
1517
from certbot_aws_store.certificate import AcmeCertificate
1618

1719
from ecs_files_composer.common import LOG
1820

1921

2022
def handle_certbot_store_certificates(job: Model) -> None:
23+
"""
24+
Pulls certificates from certbot-aws-store to local filesystem
25+
If the path does not exist, creates a new directory for download.
26+
"""
2127
if not job.certbot_store:
2228
return
2329
for _hostname, _definition in job.certbot_store.items():
@@ -29,9 +35,13 @@ def handle_certbot_store_certificates(job: Model) -> None:
2935
if _definition.table_region_name
3036
else None,
3137
)
38+
if not path.exists(_definition.storage_path):
39+
makedirs(_definition.storage_path, exist_ok=True)
3240
try:
3341
certificate.pull(_definition.storage_path)
3442
LOG.info("Successfully pulled certificates for %s", _hostname)
3543
except Exception as error:
36-
print(error)
37-
print("Failed to download certificate from certbot-aws-store", _hostname)
44+
LOG.exceptions(error)
45+
LOG.error(
46+
"Failed to download certificate from certbot-aws-store", _hostname
47+
)

ecs_files_composer/ecs_files_composer.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import json
1414
import uuid
1515
from os import environ, path
16+
from tempfile import TemporaryDirectory
1617

1718
import yaml
1819
from compose_x_common.compose_x_common import keyisset
@@ -56,7 +57,7 @@ def init_config(
5657
iam_override = {"SessionName": "FilesComposerInit"}
5758
if ssm_parameter or s3_config or secret_config:
5859
role_arn = environ.get("CONFIG_IAM_ROLE_ARN", role_arn)
59-
external_id = environ.get("CONFIG_IAM_EXTERNAL_ID", None)
60+
external_id = environ.get("CONFIG_IAM_EXTERNAL_ID", external_id)
6061
if role_arn:
6162
iam_override.update({"RoleArn": role_arn})
6263
if external_id:
@@ -90,11 +91,12 @@ def init_config(
9091
elif env_var:
9192
initial_config = {"content": environ.get(env_var, None)}
9293
else:
93-
raise Exception("No input source was provided")
94+
raise ValueError("No input source was provided")
9495
if not initial_config:
9596
raise ImportError("Failed to import a configuration content")
9697
LOG.debug(initial_config)
97-
config_path = f"/tmp/{str(uuid.uuid1())}/init_config.conf"
98+
temp_dir = TemporaryDirectory()
99+
config_path = f"{temp_dir.name}/init_config.conf"
98100
jobs_input_def = {
99101
"files": {config_path: initial_config},
100102
"IamOverride": iam_override,

0 commit comments

Comments
 (0)