Encapsulates ACM functions.
| 22 | |
| 23 | # snippet-start:[python.example_code.acm.AcmCertificate] |
| 24 | class AcmCertificate: |
| 25 | """ |
| 26 | Encapsulates ACM functions. |
| 27 | """ |
| 28 | |
| 29 | def __init__(self, acm_client): |
| 30 | """ |
| 31 | :param acm_client: A Boto3 ACM client. |
| 32 | """ |
| 33 | self.acm_client = acm_client |
| 34 | |
| 35 | # snippet-end:[python.example_code.acm.AcmCertificate] |
| 36 | |
| 37 | # snippet-start:[python.example_code.acm.DescribeCertificate] |
| 38 | def describe(self, certificate_arn): |
| 39 | """ |
| 40 | Gets certificate metadata. |
| 41 | |
| 42 | :param certificate_arn: The Amazon Resource Name (ARN) of the certificate. |
| 43 | :return: Metadata about the certificate. |
| 44 | """ |
| 45 | try: |
| 46 | response = self.acm_client.describe_certificate( |
| 47 | CertificateArn=certificate_arn |
| 48 | ) |
| 49 | certificate = response["Certificate"] |
| 50 | logger.info( |
| 51 | "Got metadata for certificate for domain %s.", certificate["DomainName"] |
| 52 | ) |
| 53 | except ClientError: |
| 54 | logger.exception("Couldn't get data for certificate %s.", certificate_arn) |
| 55 | raise |
| 56 | else: |
| 57 | return certificate |
| 58 | |
| 59 | # snippet-end:[python.example_code.acm.DescribeCertificate] |
| 60 | |
| 61 | # snippet-start:[python.example_code.acm.GetCertificate] |
| 62 | def get(self, certificate_arn): |
| 63 | """ |
| 64 | Gets the body and certificate chain of a certificate. |
| 65 | |
| 66 | :param certificate_arn: The ARN of the certificate. |
| 67 | :return: The body and chain of a certificate. |
| 68 | """ |
| 69 | try: |
| 70 | response = self.acm_client.get_certificate(CertificateArn=certificate_arn) |
| 71 | logger.info("Got certificate %s and its chain.", certificate_arn) |
| 72 | except ClientError: |
| 73 | logger.exception("Couldn't get certificate %s.", certificate_arn) |
| 74 | raise |
| 75 | else: |
| 76 | return response |
| 77 | |
| 78 | # snippet-end:[python.example_code.acm.GetCertificate] |
| 79 | |
| 80 | # snippet-start:[python.example_code.acm.ListCertificates] |
| 81 | def list( |
no outgoing calls