Skip to content

Commit

Permalink
Techdebt: Remove warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
bblommers committed Feb 16, 2024
1 parent 4b89874 commit d88001c
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 26 deletions.
7 changes: 0 additions & 7 deletions .github/workflows/dockertests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ jobs:
if: always()
run: |
mkdir serverlogs1
pwd
ls -la
cp server_output.log serverlogs1/server_output.log
docker stop motoserver
- name: Archive Logs
Expand Down Expand Up @@ -141,8 +139,6 @@ jobs:
if: always()
run: |
mkdir serverlogs2
pwd
ls -la
cp server_output.log serverlogs2/server_output.log
- name: Archive logs
if: always()
Expand Down Expand Up @@ -200,10 +196,7 @@ jobs:
if: always()
run: |
mkdir serverlogs3
pwd
ls -la
cp server_output.log serverlogs3/server_output.log
ls -la serverlogs3
- name: Archive Logs
if: always()
uses: actions/upload-artifact@v4
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test_outdated_versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
responses-version: ["0.15.0", "0.17.0", "0.19.0", "0.20.0" ]
werkzeug-version: ["2.0.1", "2.1.1", "2.2.2"]
openapi-spec-validator-version: ["0.5.0"]
cryptography-version: ["39.0.0"]

steps:
- name: Checkout repository
Expand All @@ -40,6 +41,7 @@ jobs:
pip install werkzeug==${{ matrix.werkzeug-version }}
pip install openapi-spec-validator==${{ matrix.openapi-spec-validator-version }}
pip install ${{ matrix.botocore }}
pip install cryptography==${{ matrix.cryptography-version }}
- name: Run tests
run: |
Expand All @@ -59,8 +61,6 @@ jobs:
if: always()
run: |
mkdir serverlogs
pwd
ls -la
cp server_output.log serverlogs/server_output.log
docker stop motoserver
- name: Archive TF logs
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/tests_proxymode.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ jobs:
- name: "Stop MotoProxy"
if: always()
run: |
pwd
ls -la
kill $(lsof -t -i:5005)
- name: Archive Proxy logs
if: always()
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/tests_servermode.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ jobs:
if: always()
run: |
mkdir serverlogs
pwd
ls -la
cp server_output.log serverlogs/server_output.log
docker stop motoserver
- name: Archive TF logs
Expand Down
28 changes: 22 additions & 6 deletions moto/acm/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,12 @@ def validate_certificate(self) -> cryptography.x509.base.Certificate:
)

now = utcnow()
if _cert.not_valid_after < now:
if self._not_valid_after(_cert) < now:
raise AWSValidationException(
"The certificate has expired, is not valid."
)

if _cert.not_valid_before > now:
if self._not_valid_before(_cert) > now:
raise AWSValidationException(
"The certificate is not in effect yet, is not valid."
)
Expand All @@ -256,6 +256,22 @@ def validate_certificate(self) -> cryptography.x509.base.Certificate:
)
return _cert

def _not_valid_after(
self, _cert: cryptography.x509.base.Certificate
) -> datetime.datetime:
try:
return _cert.not_valid_after_utc.replace(tzinfo=None)
except AttributeError:
return _cert.not_valid_after

def _not_valid_before(
self, _cert: cryptography.x509.base.Certificate
) -> datetime.datetime:
try:
return _cert.not_valid_before_utc.replace(tzinfo=None)
except AttributeError:
return _cert.not_valid_before

def validate_chain(self) -> None:
try:
for cert_armored in self.chain.split(b"-\n-"):
Expand All @@ -267,12 +283,12 @@ def validate_chain(self) -> None:
)

now = utcnow()
if self._cert.not_valid_after < now:
if self._not_valid_after(self._cert) < now:
raise AWSValidationException(
"The certificate chain has expired, is not valid."
)

if self._cert.not_valid_before > now:
if self._not_valid_before(self._cert) > now:
raise AWSValidationException(
"The certificate chain is not in effect yet, is not valid."
)
Expand Down Expand Up @@ -325,8 +341,8 @@ def describe(self) -> Dict[str, Any]:
0
].value,
"KeyAlgorithm": key_algo,
"NotAfter": datetime_to_epoch(self._cert.not_valid_after),
"NotBefore": datetime_to_epoch(self._cert.not_valid_before),
"NotAfter": datetime_to_epoch(self._not_valid_after(self._cert)),
"NotBefore": datetime_to_epoch(self._not_valid_before(self._cert)),
"Serial": str(self._cert.serial_number),
"SignatureAlgorithm": self._cert.signature_algorithm_oid._name.upper().replace(
"ENCRYPTION", ""
Expand Down
10 changes: 8 additions & 2 deletions moto/acmpca/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,19 @@ def certificate_bytes(self) -> bytes:
def not_valid_after(self) -> Optional[float]:
if self.certificate is None:
return None
return unix_time(self.certificate.not_valid_after)
try:
return unix_time(self.certificate.not_valid_after_utc.replace(tzinfo=None))
except AttributeError:
return unix_time(self.certificate.not_valid_after)

@property
def not_valid_before(self) -> Optional[float]:
if self.certificate is None:
return None
return unix_time(self.certificate.not_valid_before)
try:
return unix_time(self.certificate.not_valid_before_utc.replace(tzinfo=None))
except AttributeError:
return unix_time(self.certificate.not_valid_before)

def import_certificate_authority_certificate(
self, certificate: bytes, certificate_chain: Optional[bytes]
Expand Down
8 changes: 4 additions & 4 deletions tests/test_core/test_mypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@


@mock_aws
def test_without_parentheses() -> int:
def method_without_parentheses() -> int:
assert boto3.client("s3").list_buckets()["Buckets"] == []
return 123


@mock_aws()
def test_with_parentheses() -> int:
def method_with_parentheses() -> int:
assert boto3.client("s3").list_buckets()["Buckets"] == []
return 456

Expand All @@ -35,8 +35,8 @@ def test_manual() -> None:
m.stop()


x: int = test_with_parentheses()
x: int = method_with_parentheses()
assert x == 456

y: int = test_without_parentheses()
y: int = method_without_parentheses()
assert y == 123
2 changes: 1 addition & 1 deletion tests/test_ec2/test_route_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@ def test_create_route_with_vpc_endpoint():
VpcEndpointId=vpce_id,
RouteTableId=route_table.id,
)
rt = ec2_client.describe_route_tables()
rt = ec2_client.describe_route_tables(RouteTableIds=[route_table.id])
new_route = rt["RouteTables"][-1]["Routes"][1]

# Verify
Expand Down

0 comments on commit d88001c

Please sign in to comment.