Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix cert uploading issues #141

Merged
merged 2 commits into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/containerapp/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Release History
++++++
* '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
++++++
Expand Down
5 changes: 2 additions & 3 deletions src/containerapp/azext_containerapp/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,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()


Expand Down Expand Up @@ -1307,8 +1307,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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
])
Expand Down