blob: 4abf3dcbb93649c964197192e7a4de4d053a5921 [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 *
9from apihelper import XOSAPIHelperMixin, translate_exceptions
Matteo Scandolo1d01b692018-10-03 15:53:36 -070010import grpc
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020011
Scott Bakerb96ba432018-02-26 09:53:48 -080012class XosService(xos_pb2_grpc.xosServicer, XOSAPIHelperMixin):
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020013 def __init__(self, thread_pool):
14 self.thread_pool = thread_pool
15 XOSAPIHelperMixin.__init__(self)
16
17 def stop(self):
18 pass
19
20{% for object in proto.messages | sort(attribute='name') %}
21{%- if object.name!='XOSBase' %}
Matteo Scandolo1d01b692018-10-03 15:53:36 -070022 @translate_exceptions("{{ object.name }}", "List{{ object.name }}")
23 @track_request_time("{{ object.name }}", "List{{ object.name }}")
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020024 def List{{ object.name }}(self, request, context):
25 user=self.authenticate(context)
26 model=self.get_model("{{ object.name }}")
Matteo Scandolo1d01b692018-10-03 15:53:36 -070027 res = self.list(model, user)
28 REQUEST_COUNT.labels('xos-core', "{{ object.name }}", "List{{ object.name }}", grpc.StatusCode.OK).inc()
29 return res
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020030
Matteo Scandolo1d01b692018-10-03 15:53:36 -070031 @translate_exceptions("{{ object.name }}", "Filter{{ object.name }}")
32 @track_request_time("{{ object.name }}", "Filter{{ object.name }}")
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020033 def Filter{{ object.name }}(self, request, context):
34 user=self.authenticate(context)
35 model=self.get_model("{{ object.name }}")
Matteo Scandolo1d01b692018-10-03 15:53:36 -070036 res = self.filter(model, user, request)
37 REQUEST_COUNT.labels('xos-core', "{{ object.name }}", "List{{ object.name }}", grpc.StatusCode.OK).inc()
38 return res
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020039
Matteo Scandolo1d01b692018-10-03 15:53:36 -070040 @translate_exceptions("{{ object.name }}", "Get{{ object.name }}")
41 @track_request_time("{{ object.name }}", "Get{{ object.name }}")
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020042 def Get{{ object.name }}(self, request, context):
43 user=self.authenticate(context)
44 model=self.get_model("{{ object.name }}")
Matteo Scandolo1d01b692018-10-03 15:53:36 -070045 res = self.get(model, user, request.id)
46 REQUEST_COUNT.labels('xos-core', "{{ object.name }}", "List{{ object.name }}", grpc.StatusCode.OK).inc()
47 return res
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020048
Matteo Scandolo1d01b692018-10-03 15:53:36 -070049 @translate_exceptions("{{ object.name }}", "Create{{ object.name }}")
50 @track_request_time("{{ object.name }}", "Create{{ object.name }}")
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020051 def Create{{ object.name }}(self, request, context):
52 user=self.authenticate(context)
53 model=self.get_model("{{ object.name }}")
Matteo Scandolo1d01b692018-10-03 15:53:36 -070054 res = self.create(model, user, request)
55 REQUEST_COUNT.labels('xos-core', "{{ object.name }}", "List{{ object.name }}", grpc.StatusCode.OK).inc()
56 return res
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020057
Matteo Scandolo1d01b692018-10-03 15:53:36 -070058 @translate_exceptions("{{ object.name }}", "Delete{{ object.name }}")
59 @track_request_time("{{ object.name }}", "Delete{{ object.name }}")
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020060 def Delete{{ object.name }}(self, request, context):
61 user=self.authenticate(context)
62 model=self.get_model("{{ object.name }}")
Matteo Scandolo1d01b692018-10-03 15:53:36 -070063 res = self.delete(model, user, request.id)
64 REQUEST_COUNT.labels('xos-core', "{{ object.name }}", "List{{ object.name }}", grpc.StatusCode.OK).inc()
65 return res
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020066
Matteo Scandolo1d01b692018-10-03 15:53:36 -070067 @translate_exceptions("{{ object.name }}", "Update{{ object.name }}")
68 @track_request_time("{{ object.name }}", "Update{{ object.name }}")
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020069 def Update{{ object.name }}(self, request, context):
70 user=self.authenticate(context)
71 model=self.get_model("{{ object.name }}")
Matteo Scandolo1d01b692018-10-03 15:53:36 -070072 res = self.update(model, user, request.id, request, context)
73 REQUEST_COUNT.labels('xos-core', "{{ object.name }}", "List{{ object.name }}", grpc.StatusCode.OK).inc()
74 return res
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020075{%- endif %}
76{% endfor %}
77
78