()
| 322 | |
| 323 | # snippet-start:[python.example_code.acm.Usage_ImportListRemove] |
| 324 | def usage_demo(): |
| 325 | print("-" * 88) |
| 326 | print("Welcome to the AWS Certificate Manager (ACM) demo!") |
| 327 | print("-" * 88) |
| 328 | |
| 329 | logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") |
| 330 | |
| 331 | acm_certificate = AcmCertificate(boto3.client("acm")) |
| 332 | domain = "example.com" |
| 333 | sub_domains = [f"{sub}.{domain}" for sub in ["test", "dev"]] |
| 334 | print(f"Request a certificate for {domain}.") |
| 335 | certificate_arn = acm_certificate.request_validation(domain, sub_domains, "DNS") |
| 336 | print(f"Started validation, got certificate ARN: {certificate_arn}.") |
| 337 | |
| 338 | import_cert_arn = None |
| 339 | cert_file_name = input( |
| 340 | "Enter the file name for a self-signed certificate in PEM format. " |
| 341 | "This certificate will be imported to ACM. Press Enter to skip: " |
| 342 | ) |
| 343 | if cert_file_name: |
| 344 | pk_file_name = input( |
| 345 | "Enter the file name for the unencrypted private key of the certificate. " |
| 346 | "This file must also be in PEM format: " |
| 347 | ) |
| 348 | if pk_file_name: |
| 349 | with open(cert_file_name, "rb") as cert_file: |
| 350 | import_cert = cert_file.read() |
| 351 | with open(pk_file_name, "rb") as pk_file: |
| 352 | import_pk = pk_file.read() |
| 353 | import_cert_arn = acm_certificate.import_certificate(import_cert, import_pk) |
| 354 | print(f"Certificate imported, got ARN: {import_cert_arn}") |
| 355 | else: |
| 356 | print("No private key file entered. Skipping certificate import.") |
| 357 | else: |
| 358 | print("Skipping self-signed certificate import.") |
| 359 | |
| 360 | print("Getting the first 10 issued certificates.") |
| 361 | certificates = acm_certificate.list(10, statuses=["ISSUED"]) |
| 362 | print(f"Found {len(certificates)} issued certificates.") |
| 363 | |
| 364 | print(f"Getting metadata for certificate {certificate_arn}") |
| 365 | cert_metadata = acm_certificate.describe(certificate_arn) |
| 366 | pprint(cert_metadata) |
| 367 | |
| 368 | if import_cert_arn is not None: |
| 369 | print(f"Getting certificate for imported certificate {import_cert_arn}") |
| 370 | import_cert_data = acm_certificate.get(import_cert_arn) |
| 371 | pprint(import_cert_data) |
| 372 | |
| 373 | print(f"Adding tags to certificate {certificate_arn}.") |
| 374 | acm_certificate.add_tags(certificate_arn, {"purpose": "acm demo", "color": "green"}) |
| 375 | tags = acm_certificate.list_tags(certificate_arn) |
| 376 | print(f"Found tags: {tags}") |
| 377 | acm_certificate.remove_tags(certificate_arn, {key: None for key in tags}) |
| 378 | print("Removed tags.") |
| 379 | |
| 380 | print("Removing certificates added during the demo.") |
| 381 | acm_certificate.remove(certificate_arn) |
no test coverage detected