Skip to content

Commit 936b3c5

Browse files
committed
Upgrading dependencies and code changes to adapt to updates
1 parent 1a005de commit 936b3c5

File tree

7 files changed

+613
-606
lines changed

7 files changed

+613
-606
lines changed

.pre-commit-config.yaml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.0.1
3+
rev: v4.2.0
44
hooks:
55
- id: end-of-file-fixer
66
- id: trailing-whitespace
7+
- id: check-case-conflict
8+
- id: check-json
9+
- id: check-yaml
10+
- id: check-toml
11+
- id: end-of-file-fixer
12+
- id: trailing-whitespace
13+
- id: mixed-line-ending
14+
- id: detect-aws-credentials
15+
- id: detect-private-key
16+
- id: fix-byte-order-marker
17+
18+
- repo: https://github.com/asottile/pyupgrade
19+
rev: v2.32.1
20+
hooks:
21+
- id: pyupgrade
22+
args: [ "--py38-plus" ]
23+
724
- repo: https://github.com/psf/black
8-
rev: 21.12b0
25+
rev: 22.3.0
926
hooks:
1027
- id: black
1128
- repo: https://github.com/pycqa/isort

Makefile

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: clean clean-test clean-pyc clean-build docs help
1+
.PHONY: clean clean-test clean-pyc clean-build docs help data-model
22
.DEFAULT_GOAL := help
33

44
define BROWSER_PYSCRIPT
@@ -94,15 +94,12 @@ dist: clean ## builds source and wheel package
9494
ls -l dist
9595

9696
install: clean ## install the package to the active Python's site-packages
97-
pip install . --use-pep517 --use-feature=in-tree-build
97+
pip install . --use-pep517
9898

9999
conform : ## Conform to a standard of coding syntax
100100
isort --profile black ecs_files_composer
101101
black ecs_files_composer tests
102102
find ecs_files_composer -name "*.json" -type f -exec sed -i '1s/^\xEF\xBB\xBF//' {} +
103103

104104
data-model:
105-
datamodel-codegen --input ecs-files-input.json \
106-
--input-file-type jsonschema \
107-
--output ecs_files_composer/input.py
108-
# --enum-field-as-literal all
105+
datamodel-codegen

ecs-files-input.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
"additionalProperties": false,
2222
"properties": {
2323
"x509": {
24-
"uniqueItems": true,
2524
"patternProperties": {
2625
"^/[\\x00-\\x7F]+$": {
2726
"$ref": "#/definitions/X509CertDef"

ecs_files_composer/certificates_mgmt.py

Lines changed: 3 additions & 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

@@ -13,7 +12,7 @@
1312
from ecs_files_composer.input import X509CertDef
1413

1514

16-
class X509Certificate(X509CertDef, object):
15+
class X509Certificate(X509CertDef):
1716
"""
1817
Class to wrap actions around a new X509 certificate
1918
"""
@@ -107,8 +106,8 @@ def process_x509_certs(job):
107106
return
108107
for cert_path, cert_def in job.certificates.x509.items():
109108
cert_obj = X509Certificate(
110-
keyFileName=cert_def["keyFileName"], certFileName=cert_def["certFileName"]
111-
).parse_obj(cert_def)
109+
**(cert_def.dict(by_alias=True)),
110+
)
112111
cert_obj.dir_path = cert_path
113112
cert_obj.init_cert_paths()
114113
cert_obj.set_cert_files()

ecs_files_composer/input.py

Lines changed: 59 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
11
# generated by datamodel-codegen:
22
# filename: ecs-files-input.json
3-
# timestamp: 2021-08-16T12:01:22+00:00
3+
# timestamp: 2022-05-18T06:23:25+00:00
44

55
from __future__ import annotations
66

77
from enum import Enum
8-
from typing import Any, Dict, List, Optional
8+
from typing import Dict, List, Optional
99

1010
from pydantic import AnyUrl, BaseModel, EmailStr, Extra, Field, constr
1111

1212

13-
class Certificates(BaseModel):
14-
class Config:
15-
extra = Extra.forbid
16-
17-
x509: Optional[Any] = None
18-
19-
2013
class Encoding(Enum):
2114
base64 = "base64"
2215
plain = "plain"
@@ -28,140 +21,145 @@ class Context(Enum):
2821

2922

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

3528

3629
class IamOverrideDef(BaseModel):
37-
role_arn: Optional[str] = Field(None, alias="RoleArn")
38-
session_name: Optional[str] = Field(
30+
role_arn: str | None = Field(None, alias="RoleArn")
31+
session_name: str | None = Field(
3932
"S3File@EcsConfigComposer",
4033
alias="SessionName",
4134
description="Name of the IAM session",
4235
)
43-
external_id: Optional[str] = Field(
36+
external_id: str | None = Field(
4437
None,
4538
alias="ExternalId",
4639
description="The External ID to use when using sts:AssumeRole",
4740
)
48-
region_name: Optional[str] = Field(None, alias="RegionName")
49-
access_key_id: Optional[str] = Field(
41+
region_name: str | None = Field(None, alias="RegionName")
42+
access_key_id: str | None = Field(
5043
None, alias="AccessKeyId", description="AWS Access Key Id to use for session"
5144
)
52-
secret_access_key: Optional[str] = Field(
45+
secret_access_key: str | None = Field(
5346
None, alias="SecretAccessKey", description="AWS Secret Key to use for session"
5447
)
55-
session_token: Optional[str] = Field(None, alias="SessionToken")
48+
session_token: str | None = Field(None, alias="SessionToken")
5649

5750

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

6154

6255
class X509CertDef(BaseModel):
6356
class Config:
6457
extra = Extra.allow
6558

66-
dir_path: Optional[str] = None
67-
email_address: Optional[EmailStr] = Field(
59+
dir_path: str | None = None
60+
email_address: EmailStr | None = Field(
6861
"[email protected]", alias="emailAddress"
6962
)
70-
common_name: Optional[
63+
common_name: None | (
7164
constr(
7265
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"
7366
)
74-
] = Field(None, alias="commonName")
75-
country_name: Optional[str] = Field("AW", alias="countryName", regex="^[A-Z]+$")
76-
locality_name: Optional[str] = Field("AWS", alias="localityName")
77-
state_or_province_name: Optional[str] = Field("AWS", alias="stateOrProvinceName")
78-
organization_name: Optional[str] = Field("AWS", alias="organizationName")
79-
organization_unit_name: Optional[str] = Field("AWS", alias="organizationUnitName")
80-
validity_end_in_seconds: Optional[float] = Field(
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(
8174
8035200,
8275
alias="validityEndInSeconds",
8376
description="Validity before cert expires, in seconds. Default 3*31*24*60*60=3Months",
8477
)
8578
key_file_name: str = Field(..., alias="keyFileName")
8679
cert_file_name: str = Field(..., alias="certFileName")
87-
group: Optional[str] = Field(
80+
group: str | None = Field(
8881
"root",
8982
description="UNIX group name or GID owner of the file. Default to root(0)",
9083
)
91-
owner: Optional[str] = Field(
84+
owner: str | None = Field(
9285
"root", description="UNIX user or UID owner of the file. Default to root(0)"
9386
)
9487

9588

96-
class Model(BaseModel):
97-
files: Dict[str, Any]
98-
certificates: Optional[Certificates] = None
99-
iam_override: Optional[IamOverrideDef] = Field(None, alias="IamOverride")
89+
class Certificates(BaseModel):
90+
class Config:
91+
extra = Extra.forbid
92+
93+
x509: dict[str, X509CertDef] | None = None
10094

10195

10296
class Commands(BaseModel):
103-
post: Optional[CommandsDef] = Field(
97+
post: CommandsDef | None = Field(
10498
None, description="Commands to run after the file was retrieved"
10599
)
106-
pre: Optional[CommandsDef] = Field(
100+
pre: CommandsDef | None = Field(
107101
None,
108102
description="Commands executed prior to the file being fetched, after `depends_on` completed",
109103
)
110104

111105

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

116110

117111
class SecretDef(BaseModel):
118112
secret_id: str = Field(..., alias="SecretId")
119-
version_id: Optional[str] = Field(None, alias="VersionId")
120-
version_stage: Optional[str] = Field(None, alias="VersionStage")
121-
iam_override: Optional[IamOverrideDef] = Field(None, alias="IamOverride")
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")
122116

123117

124118
class S3Def(BaseModel):
125119
bucket_name: str = Field(
126120
..., alias="BucketName", description="Name of the S3 Bucket"
127121
)
128-
bucket_region: Optional[str] = Field(
122+
bucket_region: str | None = Field(
129123
None,
130124
alias="BucketRegion",
131125
description="S3 Region to use. Default will ignore or retrieve via s3:GetBucketLocation",
132126
)
133127
key: str = Field(..., alias="Key", description="Full path to the file to retrieve")
134-
iam_override: Optional[IamOverrideDef] = Field(None, alias="IamOverride")
128+
iam_override: IamOverrideDef | None = Field(None, alias="IamOverride")
135129

136130

137131
class SourceDef(BaseModel):
138-
url: Optional[UrlDef] = Field(None, alias="Url")
139-
ssm: Optional[SsmDef] = Field(None, alias="Ssm")
140-
s3: Optional[S3Def] = Field(None, alias="S3")
141-
secret: Optional[SecretDef] = Field(None, alias="Secret")
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")
142136

143137

144138
class FileDef(BaseModel):
145139
class Config:
146140
extra = Extra.allow
147141

148-
path: Optional[str] = None
149-
content: Optional[str] = Field(
150-
None, description="The raw content of the file to use"
151-
)
152-
source: Optional[SourceDef] = None
153-
encoding: Optional[Encoding] = "plain"
154-
group: Optional[str] = Field(
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(
155147
"root",
156148
description="UNIX group name or GID owner of the file. Default to root(0)",
157149
)
158-
owner: Optional[str] = Field(
150+
owner: str | None = Field(
159151
"root", description="UNIX user or UID owner of the file. Default to root(0)"
160152
)
161-
mode: Optional[str] = Field("0644", description="UNIX file mode")
162-
context: Optional[Context] = "plain"
163-
ignore_if_failed: Optional[bool] = Field(
153+
mode: str | None = Field("0644", description="UNIX file mode")
154+
context: Context | None = "plain"
155+
ignore_if_failed: bool | None = Field(
164156
False,
165157
description="Whether or not the failure to retrieve the file should stop the execution",
166158
)
167-
commands: Optional[Commands] = None
159+
commands: Commands | None = None
160+
161+
162+
class Model(BaseModel):
163+
files: dict[str, FileDef]
164+
certificates: Certificates | None = None
165+
iam_override: IamOverrideDef | None = Field(None, alias="IamOverride")

0 commit comments

Comments
 (0)