Debian Codegraph @

magnum_tempest_plugin/tests/api/v1/clients/cert_client.py

raw
1 # Licensed under the Apache License, Version 2.0 (the "License"); you may
2 # not use this file except in compliance with the License. You may obtain
3 # a copy of the License at
4 #
5 # http://www.apache.org/licenses/LICENSE-2.0
6 #
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 # License for the specific language governing permissions and limitations
11 # under the License.
12
13 from magnum_tempest_plugin.common import client
14 from magnum_tempest_plugin.tests.api.v1.models import cert_model
15
16
17 class CertClient(client.MagnumClient):
18 """Encapsulates REST calls and maps JSON to/from models"""
19
20 url = "/certificates"
21
22 @classmethod
23 def cert_uri(cls, cluster_id):
24 """Construct cluster uri
25
26 :param cluster_id: cluster uuid or name
27 :returns: url string
28 """
29
30 return "{0}/{1}".format(cls.url, cluster_id)
31
32 def get_cert(self, cluster_id, **kwargs):
33 """Makes GET /certificates/cluster_id request and returns CertEntity
34
35 Abstracts REST call to return a single cert based on uuid or name
36
37 :param cluster_id: cluster uuid or name
38 :returns: response object and ClusterCollection object
39 """
40
41 resp, body = self.get(self.cert_uri(cluster_id), **kwargs)
42 return self.deserialize(resp, body, cert_model.CertEntity)
43
44 def post_cert(self, model, **kwargs):
45 """Makes POST /certificates request and returns CertEntity
46
47 Abstracts REST call to sign new certificate
48
49 :param model: CertEntity
50 :returns: response object and CertEntity object
51 """
52
53 resp, body = self.post(
54 CertClient.url,
55 body=model.to_json(), **kwargs)
56 return self.deserialize(resp, body, cert_model.CertEntity)