Browse Source

Merge "Add new certificate api find_cert_with_pem"

changes/80/738980/1
Zuul 1 week ago
committed by Gerrit Code Review
parent
commit
208bc027fb
3 changed files with 25 additions and 1 deletions
  1. +16
    -0
      vmware_nsxlib/tests/unit/v3/policy/test_resources.py
  2. +1
    -1
      vmware_nsxlib/v3/policy/core_defs.py
  3. +8
    -0
      vmware_nsxlib/v3/policy/core_resources.py

+ 16
- 0
vmware_nsxlib/tests/unit/v3/policy/test_resources.py View File

@@ -6086,6 +6086,22 @@ class TestPolicyCertificate(NsxPolicyLibTestCase):
sleep=0.1, tenant=TEST_TENANT)
self.assertEqual(info, actual_info)

def test_find_cert_with_pem(self):
id1 = '1'
id2 = '2'
pem1 = '111'
pem2 = '222'
with mock.patch.object(self.policy_api, "list",
return_value={'results': [
{'id': id1, 'pem_encoded': pem1},
{'id': id2, 'pem_encoded': pem2}]}) as api:
cert_ids = self.resourceApi.find_cert_with_pem(
pem1, tenant=TEST_TENANT)
self.assertEqual(1, len(cert_ids))
self.assertEqual(id1, cert_ids[0])
expected_def = core_defs.CertificateDef(tenant=TEST_TENANT)
self.assert_called_with_def(api, expected_def)


class TestPolicyExcludeList(NsxPolicyLibTestCase):



+ 1
- 1
vmware_nsxlib/v3/policy/core_defs.py View File

@@ -2384,7 +2384,7 @@ class CertificateDef(ResourceDef):

@staticmethod
def resource_type():
return "TlsTrustData"
return "TlsCertificate"

def get_obj_dict(self):
body = super(CertificateDef, self).get_obj_dict()


+ 8
- 0
vmware_nsxlib/v3/policy/core_resources.py View File

@@ -4493,6 +4493,14 @@ class NsxPolicyCertApi(NsxPolicyResourceBase):
certificate_def = self.entry_def(tenant=tenant)
return self._list(certificate_def)

def find_cert_with_pem(self, cert_pem,
tenant=constants.POLICY_INFRA_TENANT):
# Find certificate with cert_pem
certs = self.list(tenant=tenant)
cert_ids = [cert['id'] for cert in certs
if cert['pem_encoded'] == cert_pem]
return cert_ids

def update(self, certificate_id, name=IGNORE,
pem_encoded=IGNORE, private_key=IGNORE,
passphrase=IGNORE, key_algo=IGNORE, description=IGNORE,


Loading…
Cancel
Save