Add validity dates to IoT fakecert (#4093)

This commit is contained in:
cătălin 2021-07-27 09:59:01 +02:00 committed by GitHub
parent f9f93531e8
commit 9d7746b9e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 14 deletions

View File

@ -12,6 +12,7 @@ from datetime import datetime
from boto3 import Session from boto3 import Session
from moto.core import BaseBackend, BaseModel from moto.core import BaseBackend, BaseModel
from moto.utilities.utils import random_string
from .exceptions import ( from .exceptions import (
CertificateStateException, CertificateStateException,
DeleteConflictException, DeleteConflictException,
@ -21,7 +22,6 @@ from .exceptions import (
VersionConflictException, VersionConflictException,
ResourceAlreadyExistsException, ResourceAlreadyExistsException,
) )
from moto.utilities.utils import random_string
class FakeThing(BaseModel): class FakeThing(BaseModel):
@ -144,7 +144,8 @@ class FakeCertificate(BaseModel):
self.transfer_data = {} self.transfer_data = {}
self.creation_date = time.time() self.creation_date = time.time()
self.last_modified_date = self.creation_date self.last_modified_date = self.creation_date
self.validity_not_before = time.time() - 86400
self.validity_not_after = time.time() + 86400
self.ca_certificate_id = None self.ca_certificate_id = None
self.ca_certificate_pem = ca_certificate_pem self.ca_certificate_pem = ca_certificate_pem
if ca_certificate_pem: if ca_certificate_pem:
@ -174,6 +175,10 @@ class FakeCertificate(BaseModel):
"ownedBy": self.owner, "ownedBy": self.owner,
"creationDate": self.creation_date, "creationDate": self.creation_date,
"lastModifiedDate": self.last_modified_date, "lastModifiedDate": self.last_modified_date,
"validity": {
"notBefore": self.validity_not_before,
"notAfter": self.validity_not_after,
},
"transferData": self.transfer_data, "transferData": self.transfer_data,
} }

View File

@ -37,7 +37,9 @@ def main():
for region in regions: for region in regions:
for location_type in TYPES: for location_type in TYPES:
ec2 = boto3.client("ec2", region_name=region) ec2 = boto3.client("ec2", region_name=region)
dest = os.path.join(root_dir, "{0}/{1}/{2}.json".format(PATH, location_type, region)) dest = os.path.join(
root_dir, "{0}/{1}/{2}.json".format(PATH, location_type, region)
)
try: try:
instances = [] instances = []
offerings = ec2.describe_instance_type_offerings( offerings = ec2.describe_instance_type_offerings(
@ -47,8 +49,7 @@ def main():
next_token = offerings.get("NextToken", "") next_token = offerings.get("NextToken", "")
while next_token: while next_token:
offerings = ec2.describe_instance_type_offerings( offerings = ec2.describe_instance_type_offerings(
LocationType=location_type, LocationType=location_type, NextToken=next_token
NextToken=next_token
) )
instances.extend(offerings["InstanceTypeOfferings"]) instances.extend(offerings["InstanceTypeOfferings"])
next_token = offerings.get("NextToken", None) next_token = offerings.get("NextToken", None)

View File

@ -26,9 +26,7 @@ def main():
instances.extend(offerings["InstanceTypes"]) instances.extend(offerings["InstanceTypes"])
next_token = offerings.get("NextToken", "") next_token = offerings.get("NextToken", "")
while next_token: while next_token:
offerings = ec2.describe_instance_types( offerings = ec2.describe_instance_types(NextToken=next_token)
NextToken=next_token
)
instances.extend(offerings["InstanceTypes"]) instances.extend(offerings["InstanceTypes"])
next_token = offerings.get("NextToken", None) next_token = offerings.get("NextToken", None)
except Exception: except Exception:
@ -39,7 +37,7 @@ def main():
print("Parsing data") print("Parsing data")
result = {} result = {}
for instance in instances: for instance in instances:
result[instance.get('InstanceType')] = instance result[instance.get("InstanceType")] = instance
root_dir = ( root_dir = (
subprocess.check_output(["git", "rev-parse", "--show-toplevel"]) subprocess.check_output(["git", "rev-parse", "--show-toplevel"])

View File

@ -538,6 +538,10 @@ def test_certs():
cert_desc.should.have.key("certificateArn").which.should_not.be.none cert_desc.should.have.key("certificateArn").which.should_not.be.none
cert_desc.should.have.key("certificateId").which.should_not.be.none cert_desc.should.have.key("certificateId").which.should_not.be.none
cert_desc.should.have.key("certificatePem").which.should_not.be.none cert_desc.should.have.key("certificatePem").which.should_not.be.none
cert_desc.should.have.key("validity").which.should_not.be.none
validity = cert_desc["validity"]
validity.should.have.key("notBefore").which.should_not.be.none
validity.should.have.key("notAfter").which.should_not.be.none
cert_desc.should.have.key("status").which.should.equal("ACTIVE") cert_desc.should.have.key("status").which.should.equal("ACTIVE")
cert_pem = cert_desc["certificatePem"] cert_pem = cert_desc["certificatePem"]

View File

@ -54,7 +54,7 @@ def migrate_version(target_file, new_version):
regex = r"['\"](.*)['\"]" regex = r"['\"](.*)['\"]"
migrate_source_attribute( migrate_source_attribute(
"__version__", "__version__",
"\"{new_version}\"".format(new_version=new_version), '"{new_version}"'.format(new_version=new_version),
target_file, target_file,
regex, regex,
) )
@ -84,7 +84,9 @@ def prerelease_version():
assert ( assert (
initpy_ver > ver initpy_ver > ver
), "the moto/__init__.py version should be newer than the last tagged release." ), "the moto/__init__.py version should be newer than the last tagged release."
return "{}.{}.{}.dev{}".format(initpy_ver.major, initpy_ver.minor, initpy_ver.micro, commits_since) return "{}.{}.{}.dev{}".format(
initpy_ver.major, initpy_ver.minor, initpy_ver.micro, commits_since
)
def read(*parts): def read(*parts):
@ -116,7 +118,9 @@ def increase_patch_version(old_version):
:param old_version: 2.0.1 :param old_version: 2.0.1
:return: 2.0.2.dev :return: 2.0.2.dev
""" """
return "{}.{}.{}.dev".format(old_version.major, old_version.minor, old_version.micro + 1) return "{}.{}.{}.dev".format(
old_version.major, old_version.minor, old_version.micro + 1
)
def release_version_correct(): def release_version_correct():
@ -154,5 +158,7 @@ if __name__ == "__main__":
initpy = os.path.abspath("moto/__init__.py") initpy = os.path.abspath("moto/__init__.py")
migrate_version(initpy, new_version) migrate_version(initpy, new_version)
else: else:
print("Invalid usage. Supply 0 or 1 arguments. " print(
"Argument can be either a version '1.2.3' or 'patch' if you want to increase the patch-version (1.2.3 -> 1.2.4.dev)") "Invalid usage. Supply 0 or 1 arguments. "
"Argument can be either a version '1.2.3' or 'patch' if you want to increase the patch-version (1.2.3 -> 1.2.4.dev)"
)