-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcertificate.py
More file actions
75 lines (63 loc) · 2.54 KB
/
certificate.py
File metadata and controls
75 lines (63 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from scheduler.resources import Resource
from scheduler.exceptions import KubeHTTPException
class Certificate(Resource):
api_version = 'cert-manager.io/v1alpha2'
api_prefix = 'apis'
@staticmethod
def manifest(api_version, namespace, name, hosts, version=None):
data = {
"apiVersion": api_version,
"kind": "Certificate",
"metadata": {
"name": name,
"namespace": namespace
},
"spec": {
"secretName": "%s-auto-tls" % name,
"issuerRef": {
"name": "drycc-cluster-issuer",
"kind": "ClusterIssuer"
},
"dnsNames": hosts
}
}
if version:
data["metadata"]["resourceVersion"] = version
return data
def get(self, namespace, name=None, **kwargs):
"""
Fetch a single certificate or a list of certificates
"""
if name is not None:
url = self.api('/namespaces/{}/certificates/{}', namespace, name)
message = 'get certificate ' + name
else:
url = self.api('/namespaces/{}/certificates', namespace)
message = 'get certificates'
response = self.http_get(url)
if self.unhealthy(response.status_code):
raise KubeHTTPException(response, message)
return response
def create(self, namespace, name, hosts):
url = self.api('/namespaces/{}/certificates', namespace)
data = self.manifest(self.api_version, namespace, name, hosts)
response = self.http_post(url, json=data)
if not response.status_code == 201:
raise KubeHTTPException(response, "create certificate {}".format(namespace))
return response
def put(self, namespace, name, hosts, version):
url = self.api('/namespaces/{}/certificates/{}', namespace, name)
data = self.manifest(self.api_version, namespace, name, hosts, version)
response = self.http_put(url, json=data)
if self.unhealthy(response.status_code):
raise KubeHTTPException(response, "put certificate {}".format(namespace))
return response
def delete(self, namespace, name):
"""
Delete certificate
"""
url = self.api('/namespaces/{}/certificates/{}', namespace, name)
response = self.http_delete(url)
if self.unhealthy(response.status_code):
raise KubeHTTPException(response, 'delete certificate ' + name)
return response