blob: 387a2fe40eaf9949aa02cf8bc4162a6ca62e579f [file] [log] [blame]
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +02001import base64
2import time
Scott Bakerb96ba432018-02-26 09:53:48 -08003from protos import xos_pb2, xos_pb2_grpc
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +02004from google.protobuf.empty_pb2 import Empty
Matteo Scandolo1d01b692018-10-03 15:53:36 -07005from apistats import track_request_time, REQUEST_COUNT
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +02006
7from django.contrib.auth import authenticate as django_authenticate
8from xos.exceptions import *
Scott Baker75e9d562019-02-22 09:34:00 -08009from apihelper import XOSAPIHelperMixin
10from decorators import translate_exceptions
Matteo Scandolo1d01b692018-10-03 15:53:36 -070011import grpc
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020012
Scott Bakerb96ba432018-02-26 09:53:48 -080013class XosService(xos_pb2_grpc.xosServicer, XOSAPIHelperMixin):
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020014 def __init__(self, thread_pool):
15 self.thread_pool = thread_pool
16 XOSAPIHelperMixin.__init__(self)
17
18 def stop(self):
19 pass
20
21{% for object in proto.messages | sort(attribute='name') %}
22{%- if object.name!='XOSBase' %}
Matteo Scandolo1d01b692018-10-03 15:53:36 -070023 @translate_exceptions("{{ object.name }}", "List{{ object.name }}")
24 @track_request_time("{{ object.name }}", "List{{ object.name }}")
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020025 def List{{ object.name }}(self, request, context):
26 user=self.authenticate(context)
27 model=self.get_model("{{ object.name }}")
Matteo Scandolo1d01b692018-10-03 15:53:36 -070028 res = self.list(model, user)
29 REQUEST_COUNT.labels('xos-core', "{{ object.name }}", "List{{ object.name }}", grpc.StatusCode.OK).inc()
30 return res
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020031
Matteo Scandolo1d01b692018-10-03 15:53:36 -070032 @translate_exceptions("{{ object.name }}", "Filter{{ object.name }}")
33 @track_request_time("{{ object.name }}", "Filter{{ object.name }}")
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020034 def Filter{{ object.name }}(self, request, context):
35 user=self.authenticate(context)
36 model=self.get_model("{{ object.name }}")
Matteo Scandolo1d01b692018-10-03 15:53:36 -070037 res = self.filter(model, user, request)
38 REQUEST_COUNT.labels('xos-core', "{{ object.name }}", "List{{ object.name }}", grpc.StatusCode.OK).inc()
39 return res
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020040
Matteo Scandolo1d01b692018-10-03 15:53:36 -070041 @translate_exceptions("{{ object.name }}", "Get{{ object.name }}")
42 @track_request_time("{{ object.name }}", "Get{{ object.name }}")
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020043 def Get{{ object.name }}(self, request, context):
44 user=self.authenticate(context)
45 model=self.get_model("{{ object.name }}")
Matteo Scandolo1d01b692018-10-03 15:53:36 -070046 res = self.get(model, user, request.id)
47 REQUEST_COUNT.labels('xos-core', "{{ object.name }}", "List{{ object.name }}", grpc.StatusCode.OK).inc()
48 return res
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020049
Matteo Scandolo1d01b692018-10-03 15:53:36 -070050 @translate_exceptions("{{ object.name }}", "Create{{ object.name }}")
51 @track_request_time("{{ object.name }}", "Create{{ object.name }}")
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020052 def Create{{ object.name }}(self, request, context):
53 user=self.authenticate(context)
54 model=self.get_model("{{ object.name }}")
Matteo Scandolo1d01b692018-10-03 15:53:36 -070055 res = self.create(model, user, request)
56 REQUEST_COUNT.labels('xos-core', "{{ object.name }}", "List{{ object.name }}", grpc.StatusCode.OK).inc()
57 return res
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020058
Matteo Scandolo1d01b692018-10-03 15:53:36 -070059 @translate_exceptions("{{ object.name }}", "Delete{{ object.name }}")
60 @track_request_time("{{ object.name }}", "Delete{{ object.name }}")
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020061 def Delete{{ object.name }}(self, request, context):
62 user=self.authenticate(context)
63 model=self.get_model("{{ object.name }}")
Matteo Scandolo1d01b692018-10-03 15:53:36 -070064 res = self.delete(model, user, request.id)
65 REQUEST_COUNT.labels('xos-core', "{{ object.name }}", "List{{ object.name }}", grpc.StatusCode.OK).inc()
66 return res
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020067
Matteo Scandolo1d01b692018-10-03 15:53:36 -070068 @translate_exceptions("{{ object.name }}", "Update{{ object.name }}")
69 @track_request_time("{{ object.name }}", "Update{{ object.name }}")
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020070 def Update{{ object.name }}(self, request, context):
71 user=self.authenticate(context)
72 model=self.get_model("{{ object.name }}")
Matteo Scandolo1d01b692018-10-03 15:53:36 -070073 res = self.update(model, user, request.id, request, context)
74 REQUEST_COUNT.labels('xos-core', "{{ object.name }}", "List{{ object.name }}", grpc.StatusCode.OK).inc()
75 return res
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020076{%- endif %}
77{% endfor %}
78
79