-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathadmission.py
More file actions
40 lines (35 loc) · 1.13 KB
/
Copy pathadmission.py
File metadata and controls
40 lines (35 loc) · 1.13 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
"""
Admission webhook views.
"""
import json
from django.conf import settings
from rest_framework.permissions import AllowAny
from rest_framework.response import Response
from rest_framework.viewsets import GenericViewSet
from api import admissions
class AdmissionWebhookViewSet(GenericViewSet):
admission_classes = (
admissions.JobsStatusHandler,
admissions.DeploymentsScaleHandler,
)
permission_classes = (AllowAny, )
def handle(self, request, **kwargs):
key = kwargs['key']
data = json.loads(request.body.decode("utf8"))["request"]
if settings.CERT_KEY == key:
allowed = True
for admission_class in self.admission_classes:
admission = admission_class()
if admission.detect(data):
allowed = admission.handle(data)
break
else:
allowed = False
return Response({
"apiVersion": "admission.k8s.io/v1",
"kind": "AdmissionReview",
"response": {
"uid": data["uid"],
"allowed": allowed,
}
})