Merge "Add new certificate api find_cert_with_pem"
This commit is contained in:
commit
208bc027fb
|
@ -6086,6 +6086,22 @@ class TestPolicyCertificate(NsxPolicyLibTestCase):
|
||||||
sleep=0.1, tenant=TEST_TENANT)
|
sleep=0.1, tenant=TEST_TENANT)
|
||||||
self.assertEqual(info, actual_info)
|
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):
|
class TestPolicyExcludeList(NsxPolicyLibTestCase):
|
||||||
|
|
||||||
|
|
|
@ -2384,7 +2384,7 @@ class CertificateDef(ResourceDef):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def resource_type():
|
def resource_type():
|
||||||
return "TlsTrustData"
|
return "TlsCertificate"
|
||||||
|
|
||||||
def get_obj_dict(self):
|
def get_obj_dict(self):
|
||||||
body = super(CertificateDef, self).get_obj_dict()
|
body = super(CertificateDef, self).get_obj_dict()
|
||||||
|
|
|
@ -4493,6 +4493,14 @@ class NsxPolicyCertApi(NsxPolicyResourceBase):
|
||||||
certificate_def = self.entry_def(tenant=tenant)
|
certificate_def = self.entry_def(tenant=tenant)
|
||||||
return self._list(certificate_def)
|
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,
|
def update(self, certificate_id, name=IGNORE,
|
||||||
pem_encoded=IGNORE, private_key=IGNORE,
|
pem_encoded=IGNORE, private_key=IGNORE,
|
||||||
passphrase=IGNORE, key_algo=IGNORE, description=IGNORE,
|
passphrase=IGNORE, key_algo=IGNORE, description=IGNORE,
|
||||||
|
|
Loading…
Reference in New Issue