diff --git a/src/containerapp/HISTORY.rst b/src/containerapp/HISTORY.rst index aead66294ff..8206a881cfd 100644 --- a/src/containerapp/HISTORY.rst +++ b/src/containerapp/HISTORY.rst @@ -8,6 +8,8 @@ Release History * 'az containerapp create': allow authenticating with managed identity (MSI) instead of ACR username & password * 'az containerapp show': Add parameter --show-secrets to show secret values * 'az containerapp env create': Add better message when polling times out +* 'az containerapp env certificate upload': Fix bug where certificate uploading failed with error "Certificate must contain one private key." +* 'az containerapp env certificate upload': Fix bug where replacing invalid character in certificate name failed" 0.3.8 ++++++ diff --git a/src/containerapp/azext_containerapp/_utils.py b/src/containerapp/azext_containerapp/_utils.py index 9f7e44bae4c..63a6be7c216 100644 --- a/src/containerapp/azext_containerapp/_utils.py +++ b/src/containerapp/azext_containerapp/_utils.py @@ -1051,7 +1051,7 @@ def generate_randomized_cert_name(thumbprint, prefix, initial="rg"): cert_name = "{}-{}-{}-{:04}".format(prefix[:14], initial[:14], thumbprint[:4].lower(), randint(0, 9999)) for c in cert_name: if not (c.isalnum() or c == '-' or c == '.'): - cert_name.replace(c, '-') + cert_name = cert_name.replace(c, '-') return cert_name.lower() @@ -1312,8 +1312,7 @@ def load_cert_file(file_path, cert_password=None): x509 = p12.get_certificate() digest_algorithm = 'sha256' thumbprint = x509.digest(digest_algorithm).decode("utf-8").replace(':', '') - pem_data = crypto.dump_certificate(crypto.FILETYPE_PEM, x509) - blob = b64encode(pem_data).decode("utf-8") + blob = b64encode(cert_data).decode("utf-8") else: raise FileOperationError('Not a valid file type. Only .PFX and .PEM files are supported.') except Exception as e: diff --git a/src/containerapp/azext_containerapp/tests/latest/test_containerapp_env_commands.py b/src/containerapp/azext_containerapp/tests/latest/test_containerapp_env_commands.py index 5fafa7ebc93..e6f8914c65e 100644 --- a/src/containerapp/azext_containerapp/tests/latest/test_containerapp_env_commands.py +++ b/src/containerapp/azext_containerapp/tests/latest/test_containerapp_env_commands.py @@ -158,21 +158,8 @@ def test_containerapp_env_certificate_e2e(self, resource_group): JMESPathCheck('length(@)', 0), ]) - # test pem file without password - pem_file = os.path.join(TEST_DIR, 'cert.pem') - cert_2 = self.cmd('containerapp env certificate upload -g {} -n {} --certificate-file "{}"'.format(resource_group, env_name, pem_file), checks=[ - JMESPathCheck('type', "Microsoft.App/managedEnvironments/certificates"), - ]).get_output_in_json() - cert_name_2 = cert_2["name"] - cert_id_2 = cert_2["id"] - cert_thumbprint_2 = cert_2["properties"]["thumbprint"] - # list certs with a wrong location - self.cmd('containerapp env certificate upload -g {} -n {} --certificate-file "{}" -l "{}"'.format(resource_group, env_name, pem_file, "eastus2"), expect_failure=True) - - self.cmd('containerapp env certificate list -n {} -g {}'.format(env_name, resource_group), checks=[ - JMESPathCheck('length(@)', 2), - ]) + self.cmd('containerapp env certificate upload -g {} -n {} --certificate-file "{}" -l "{}"'.format(resource_group, env_name, pfx_file, "eastus2"), expect_failure=True) self.cmd('containerapp env certificate list -n {} -g {} --certificate {}'.format(env_name, resource_group, cert_name), checks=[ JMESPathCheck('length(@)', 1), @@ -197,15 +184,6 @@ def test_containerapp_env_certificate_e2e(self, resource_group): self.cmd('containerapp env certificate delete -n {} -g {} --thumbprint {} -l {} --yes'.format(env_name, resource_group, cert_thumbprint, cert_location)) - self.cmd('containerapp env certificate list -n {} -g {} --certificate {}'.format(env_name, resource_group, cert_id_2), checks=[ - JMESPathCheck('length(@)', 1), - JMESPathCheck('[0].name', cert_name_2), - JMESPathCheck('[0].id', cert_id_2), - JMESPathCheck('[0].properties.thumbprint', cert_thumbprint_2), - ]) - - self.cmd('containerapp env certificate delete -n {} -g {} --certificate {} --yes'.format(env_name, resource_group, cert_name_2)) - self.cmd('containerapp env certificate list -g {} -n {}'.format(resource_group, env_name), checks=[ JMESPathCheck('length(@)', 0), ])