Skip to content

Commit 3293001

Browse files
committed
0.8.0 beta 0
1 parent 92a09b8 commit 3293001

File tree

13 files changed

+76
-88
lines changed

13 files changed

+76
-88
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ repos:
2020
hooks:
2121
- id: pyupgrade
2222
args: [ "--py38-plus" ]
23+
exclude: ^ecs_files_composer/input.py|docs/
2324

2425
- repo: https://github.com/psf/black
2526
rev: 22.3.0

ecs_files_composer/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
# -*- coding: utf-8 -*-
21
# SPDX-License-Identifier: MPL-2.0
32
# Copyright 2020-2021 John Mille<[email protected]>
43

54
"""Top-level package for ECS Files Composer."""
65

76
__author__ = """John Preston"""
87
__email__ = "[email protected]"
9-
__version__ = "0.7.3"
8+
__version__ = "0.8.0b0"

ecs_files_composer/aws_mgmt.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
# SPDX-License-Identifier: MPL-2.0
32
# Copyright 2020-2021 John Mille<[email protected]>
43

@@ -67,7 +66,7 @@ def set_session_from_iam_object(iam_config_object, source_session=None):
6766
return client_session
6867

6968

70-
class AwsResourceHandler(object):
69+
class AwsResourceHandler:
7170
"""
7271
Class to handle all AWS related credentials init.
7372
"""

ecs_files_composer/cli.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
# SPDX-License-Identifier: MPL-2.0
32
# Copyright 2020-2021 John Mille<[email protected]>
43

ecs_files_composer/common.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
# SPDX-License-Identifier: MPL-2.0
32
# Copyright 2020-2021 John Mille<[email protected]>
43

ecs_files_composer/ecs_files_composer.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
# SPDX-License-Identifier: MPL-2.0
32
# Copyright 2020-2021 John Mille<[email protected]>
43

@@ -75,7 +74,7 @@ def init_config(
7574
elif secret_config:
7675
initial_config = {"source": {"Secret": {"SecretId": secret_config}}}
7776
elif file_path:
78-
with open(path.abspath(file_path), "r") as file_fd:
77+
with open(path.abspath(file_path)) as file_fd:
7978
config_content = file_fd.read()
8079
initial_config = {"content": config_content}
8180
elif raw:
@@ -97,7 +96,7 @@ def init_config(
9796
if context:
9897
initial_config["context"] = context
9998
start_jobs(jobs_input_def)
100-
with open(config_path, "r") as config_fd:
99+
with open(config_path) as config_fd:
101100
try:
102101
config = yaml.load(config_fd.read(), Loader=Loader)
103102
LOG.info(f"Successfully loaded YAML config {config_path}")

ecs_files_composer/envsubst.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
# SPDX-License-Identifier: MPL-2.0
32
# Copyright 2020-2021 John Mille <[email protected]>
43

@@ -14,7 +13,7 @@
1413
IF_ESCAPED = r"(?<!\\)"
1514
IF_UNDEFINED = r":-"
1615
IF_DEFINED = r":+"
17-
IF_LITTERAL = re.compile("(\$(\{\![^}]+\}))")
16+
IF_LITTERAL = re.compile(r"(\$(\{\![^}]+\}))")
1817

1918

2019
def expandvars(path, default=None, skip_escaped=True, enable_litteral=True):

ecs_files_composer/files_mgmt.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
# SPDX-License-Identifier: MPL-2.0
32
# Copyright 2020-2021 John Mille<[email protected]>
43

@@ -24,7 +23,7 @@
2423
from ecs_files_composer.jinja2_filters import JINJA_FILTERS, JINJA_FUNCTIONS
2524

2625

27-
class File(FileDef, object):
26+
class File(FileDef):
2827
"""
2928
Class to wrap common files actions around
3029
"""
@@ -197,9 +196,8 @@ def set_unix_settings(self):
197196
try:
198197
res = subprocess.run(
199198
cmd,
200-
universal_newlines=True,
201-
stdout=subprocess.PIPE,
202-
stderr=subprocess.PIPE,
199+
text=True,
200+
capture_output=True,
203201
shell=False,
204202
)
205203
except subprocess.CalledProcessError:
@@ -211,9 +209,8 @@ def set_unix_settings(self):
211209
try:
212210
res = subprocess.run(
213211
cmd,
214-
universal_newlines=True,
215-
stdout=subprocess.PIPE,
216-
stderr=subprocess.PIPE,
212+
text=True,
213+
capture_output=True,
217214
shell=False,
218215
)
219216
except subprocess.CalledProcessError:
@@ -233,9 +230,8 @@ def exec_post_commands(self):
233230
try:
234231
res = subprocess.run(
235232
cmd,
236-
universal_newlines=True,
237-
stdout=subprocess.PIPE,
238-
stderr=subprocess.PIPE,
233+
text=True,
234+
capture_output=True,
239235
shell=False,
240236
)
241237
except subprocess.CalledProcessError:

ecs_files_composer/input.py

Lines changed: 53 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# generated by datamodel-codegen:
22
# filename: ecs-files-input.json
3-
# timestamp: 2022-05-18T06:23:25+00:00
3+
# timestamp: 2022-05-18T06:49:26+00:00
44

55
from __future__ import annotations
66

@@ -21,67 +21,67 @@ class Context(Enum):
2121

2222

2323
class UrlDef(BaseModel):
24-
url: AnyUrl | None = Field(None, alias="Url")
25-
username: str | None = Field(None, alias="Username")
26-
password: str | None = Field(None, alias="Password")
24+
url: Optional[AnyUrl] = Field(None, alias="Url")
25+
username: Optional[str] = Field(None, alias="Username")
26+
password: Optional[str] = Field(None, alias="Password")
2727

2828

2929
class IamOverrideDef(BaseModel):
30-
role_arn: str | None = Field(None, alias="RoleArn")
31-
session_name: str | None = Field(
30+
role_arn: Optional[str] = Field(None, alias="RoleArn")
31+
session_name: Optional[str] = Field(
3232
"S3File@EcsConfigComposer",
3333
alias="SessionName",
3434
description="Name of the IAM session",
3535
)
36-
external_id: str | None = Field(
36+
external_id: Optional[str] = Field(
3737
None,
3838
alias="ExternalId",
3939
description="The External ID to use when using sts:AssumeRole",
4040
)
41-
region_name: str | None = Field(None, alias="RegionName")
42-
access_key_id: str | None = Field(
41+
region_name: Optional[str] = Field(None, alias="RegionName")
42+
access_key_id: Optional[str] = Field(
4343
None, alias="AccessKeyId", description="AWS Access Key Id to use for session"
4444
)
45-
secret_access_key: str | None = Field(
45+
secret_access_key: Optional[str] = Field(
4646
None, alias="SecretAccessKey", description="AWS Secret Key to use for session"
4747
)
48-
session_token: str | None = Field(None, alias="SessionToken")
48+
session_token: Optional[str] = Field(None, alias="SessionToken")
4949

5050

5151
class CommandsDef(BaseModel):
52-
__root__: list[str] = Field(..., description="List of commands to run")
52+
__root__: List[str] = Field(..., description="List of commands to run")
5353

5454

5555
class X509CertDef(BaseModel):
5656
class Config:
5757
extra = Extra.allow
5858

59-
dir_path: str | None = None
60-
email_address: EmailStr | None = Field(
59+
dir_path: Optional[str] = None
60+
email_address: Optional[EmailStr] = Field(
6161
"[email protected]", alias="emailAddress"
6262
)
63-
common_name: None | (
63+
common_name: Optional[
6464
constr(
6565
regex=r"^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]{0,61}[A-Za-z0-9])\Z"
6666
)
67-
) = Field(None, alias="commonName")
68-
country_name: str | None = Field("AW", alias="countryName", regex="^[A-Z]+$")
69-
locality_name: str | None = Field("AWS", alias="localityName")
70-
state_or_province_name: str | None = Field("AWS", alias="stateOrProvinceName")
71-
organization_name: str | None = Field("AWS", alias="organizationName")
72-
organization_unit_name: str | None = Field("AWS", alias="organizationUnitName")
73-
validity_end_in_seconds: float | None = Field(
67+
] = Field(None, alias="commonName")
68+
country_name: Optional[str] = Field("AW", alias="countryName", regex="^[A-Z]+$")
69+
locality_name: Optional[str] = Field("AWS", alias="localityName")
70+
state_or_province_name: Optional[str] = Field("AWS", alias="stateOrProvinceName")
71+
organization_name: Optional[str] = Field("AWS", alias="organizationName")
72+
organization_unit_name: Optional[str] = Field("AWS", alias="organizationUnitName")
73+
validity_end_in_seconds: Optional[float] = Field(
7474
8035200,
7575
alias="validityEndInSeconds",
7676
description="Validity before cert expires, in seconds. Default 3*31*24*60*60=3Months",
7777
)
7878
key_file_name: str = Field(..., alias="keyFileName")
7979
cert_file_name: str = Field(..., alias="certFileName")
80-
group: str | None = Field(
80+
group: Optional[str] = Field(
8181
"root",
8282
description="UNIX group name or GID owner of the file. Default to root(0)",
8383
)
84-
owner: str | None = Field(
84+
owner: Optional[str] = Field(
8585
"root", description="UNIX user or UID owner of the file. Default to root(0)"
8686
)
8787

@@ -90,76 +90,78 @@ class Certificates(BaseModel):
9090
class Config:
9191
extra = Extra.forbid
9292

93-
x509: dict[str, X509CertDef] | None = None
93+
x509: Optional[Dict[str, X509CertDef]] = None
9494

9595

9696
class Commands(BaseModel):
97-
post: CommandsDef | None = Field(
97+
post: Optional[CommandsDef] = Field(
9898
None, description="Commands to run after the file was retrieved"
9999
)
100-
pre: CommandsDef | None = Field(
100+
pre: Optional[CommandsDef] = Field(
101101
None,
102102
description="Commands executed prior to the file being fetched, after `depends_on` completed",
103103
)
104104

105105

106106
class SsmDef(BaseModel):
107-
parameter_name: str | None = Field(None, alias="ParameterName")
108-
iam_override: IamOverrideDef | None = Field(None, alias="IamOverride")
107+
parameter_name: Optional[str] = Field(None, alias="ParameterName")
108+
iam_override: Optional[IamOverrideDef] = Field(None, alias="IamOverride")
109109

110110

111111
class SecretDef(BaseModel):
112112
secret_id: str = Field(..., alias="SecretId")
113-
version_id: str | None = Field(None, alias="VersionId")
114-
version_stage: str | None = Field(None, alias="VersionStage")
115-
iam_override: IamOverrideDef | None = Field(None, alias="IamOverride")
113+
version_id: Optional[str] = Field(None, alias="VersionId")
114+
version_stage: Optional[str] = Field(None, alias="VersionStage")
115+
iam_override: Optional[IamOverrideDef] = Field(None, alias="IamOverride")
116116

117117

118118
class S3Def(BaseModel):
119119
bucket_name: str = Field(
120120
..., alias="BucketName", description="Name of the S3 Bucket"
121121
)
122-
bucket_region: str | None = Field(
122+
bucket_region: Optional[str] = Field(
123123
None,
124124
alias="BucketRegion",
125125
description="S3 Region to use. Default will ignore or retrieve via s3:GetBucketLocation",
126126
)
127127
key: str = Field(..., alias="Key", description="Full path to the file to retrieve")
128-
iam_override: IamOverrideDef | None = Field(None, alias="IamOverride")
128+
iam_override: Optional[IamOverrideDef] = Field(None, alias="IamOverride")
129129

130130

131131
class SourceDef(BaseModel):
132-
url: UrlDef | None = Field(None, alias="Url")
133-
ssm: SsmDef | None = Field(None, alias="Ssm")
134-
s3: S3Def | None = Field(None, alias="S3")
135-
secret: SecretDef | None = Field(None, alias="Secret")
132+
url: Optional[UrlDef] = Field(None, alias="Url")
133+
ssm: Optional[SsmDef] = Field(None, alias="Ssm")
134+
s3: Optional[S3Def] = Field(None, alias="S3")
135+
secret: Optional[SecretDef] = Field(None, alias="Secret")
136136

137137

138138
class FileDef(BaseModel):
139139
class Config:
140140
extra = Extra.allow
141141

142-
path: str | None = None
143-
content: str | None = Field(None, description="The raw content of the file to use")
144-
source: SourceDef | None = None
145-
encoding: Encoding | None = "plain"
146-
group: str | None = Field(
142+
path: Optional[str] = None
143+
content: Optional[str] = Field(
144+
None, description="The raw content of the file to use"
145+
)
146+
source: Optional[SourceDef] = None
147+
encoding: Optional[Encoding] = "plain"
148+
group: Optional[str] = Field(
147149
"root",
148150
description="UNIX group name or GID owner of the file. Default to root(0)",
149151
)
150-
owner: str | None = Field(
152+
owner: Optional[str] = Field(
151153
"root", description="UNIX user or UID owner of the file. Default to root(0)"
152154
)
153-
mode: str | None = Field("0644", description="UNIX file mode")
154-
context: Context | None = "plain"
155-
ignore_if_failed: bool | None = Field(
155+
mode: Optional[str] = Field("0644", description="UNIX file mode")
156+
context: Optional[Context] = "plain"
157+
ignore_if_failed: Optional[bool] = Field(
156158
False,
157159
description="Whether or not the failure to retrieve the file should stop the execution",
158160
)
159-
commands: Commands | None = None
161+
commands: Optional[Commands] = None
160162

161163

162164
class Model(BaseModel):
163-
files: dict[str, FileDef]
164-
certificates: Certificates | None = None
165-
iam_override: IamOverrideDef | None = Field(None, alias="IamOverride")
165+
files: Dict[str, FileDef]
166+
certificates: Optional[Certificates] = None
167+
iam_override: Optional[IamOverrideDef] = Field(None, alias="IamOverride")

ecs_files_composer/jinja2_filters/__init__.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
# SPDX-License-Identifier: MPL-2.0
32
# Copyright 2020-2021 John Mille<[email protected]>
43

@@ -32,9 +31,7 @@ def define_metadata(for_task=False):
3231
elif environ.get(meta_v4, None):
3332
meta_url = environ.get(meta_v4)
3433
else:
35-
raise EnvironmentError(
36-
"No ECS Metadata URL provided. This filter only works on ECS"
37-
)
34+
raise OSError("No ECS Metadata URL provided. This filter only works on ECS")
3835
if for_task:
3936
return requests.get(f"{meta_url}/task")
4037
else:

0 commit comments

Comments
 (0)