-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcertificate.py
More file actions
82 lines (71 loc) · 2.96 KB
/
certificate.py
File metadata and controls
82 lines (71 loc) · 2.96 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
76
77
78
79
80
81
82
from scheduler.resources import Resource
from scheduler.exceptions import KubeHTTPException
class Certificate(Resource):
def manifest(self, namespace, name, ingress_class, hosts, version=None):
data = {
"apiVersion": "certmanager.k8s.io/v1alpha1",
"kind": "Certificate",
"metadata": {
"name": name,
"namespace": namespace
},
"spec": {
"secretName": "%s-auto-tls" % name,
"issuerRef": {
"name": "drycc-letsencrypt",
"kind": "ClusterIssuer"
},
"dnsNames": hosts,
"acme": {
"config": [
{
"http01": {
"ingressClass": ingress_class
},
"domains": 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 = "/apis/certmanager.k8s.io/v1alpha1/namespaces/%s/certificates/%s" % (
namespace, name)
message = 'get certificate ' + name
else:
url = "/apis/certmanager.k8s.io/v1alpha1/namespaces/%s/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, ingress_class, hosts):
url = "/apis/certmanager.k8s.io/v1alpha1/namespaces/%s/certificates" % namespace
data = self.manifest(namespace, name, ingress_class, 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, ingress_class, hosts, version):
url = "/apis/certmanager.k8s.io/v1alpha1/namespaces/%s/certificates/%s" % (namespace, name)
data = self.manifest(namespace, name, ingress_class, 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 = "/apis/certmanager.k8s.io/v1alpha1/namespaces/%s/certificates/%s" % (namespace, name)
response = self.http_delete(url)
if self.unhealthy(response.status_code):
raise KubeHTTPException(response, 'delete certificate ' + name)
return response