|
@@ -76,35 +76,50 @@ def delivery_from_grpc(delivery_entity: DeliveryEntity):
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+def check_error(res, context):
|
|
|
|
+ if not res.get('success', True):
|
|
|
|
+ match res.get('errorType'):
|
|
|
|
+ case 'validation':
|
|
|
|
+ context.abort(grpc.StatusCode.INVALID_ARGUMENT, json.dumps(res.get('errors')))
|
|
|
|
+ case _:
|
|
|
|
+ context.abort(grpc.StatusCode.UNKNOWN, json.dumps(res))
|
|
|
|
+
|
|
|
|
+
|
|
class DeliveryServiceServicer(llnw_pb2_grpc.DeliveryServiceServicer):
|
|
class DeliveryServiceServicer(llnw_pb2_grpc.DeliveryServiceServicer):
|
|
|
|
|
|
def ListDelivery(self, request, context):
|
|
def ListDelivery(self, request, context):
|
|
res = get_cl(request.base).list_delivery_service_instances(request.shortName).json()
|
|
res = get_cl(request.base).list_delivery_service_instances(request.shortName).json()
|
|
|
|
+ check_error(res, context)
|
|
return DeliveryList(deliveries=[delivery_to_grpc(results) for results in res['results']])
|
|
return DeliveryList(deliveries=[delivery_to_grpc(results) for results in res['results']])
|
|
|
|
|
|
def ValidateDelivery(self, request, context):
|
|
def ValidateDelivery(self, request, context):
|
|
delivery_config = delivery_from_grpc(request.delivery)
|
|
delivery_config = delivery_from_grpc(request.delivery)
|
|
del delivery_config['uuid']
|
|
del delivery_config['uuid']
|
|
res = get_cl(request.base).validate_delivery_service_instance(delivery_config).json()
|
|
res = get_cl(request.base).validate_delivery_service_instance(delivery_config).json()
|
|
|
|
+ check_error(res, context)
|
|
return delivery_to_grpc(res)
|
|
return delivery_to_grpc(res)
|
|
|
|
|
|
def CreateDelivery(self, request, context):
|
|
def CreateDelivery(self, request, context):
|
|
delivery_config = delivery_from_grpc(request.delivery)
|
|
delivery_config = delivery_from_grpc(request.delivery)
|
|
del delivery_config['uuid']
|
|
del delivery_config['uuid']
|
|
res = get_cl(request.base).create_delivery_service_instance(delivery_config).json()
|
|
res = get_cl(request.base).create_delivery_service_instance(delivery_config).json()
|
|
|
|
+ check_error(res, context)
|
|
return delivery_to_grpc(res)
|
|
return delivery_to_grpc(res)
|
|
|
|
|
|
def GetDelivery(self, request, context):
|
|
def GetDelivery(self, request, context):
|
|
res = get_cl(request.base).get_delivery_service_instance(request.id).json()
|
|
res = get_cl(request.base).get_delivery_service_instance(request.id).json()
|
|
|
|
+ check_error(res, context)
|
|
return delivery_to_grpc(res)
|
|
return delivery_to_grpc(res)
|
|
|
|
|
|
def UpdateDelivery(self, request, context):
|
|
def UpdateDelivery(self, request, context):
|
|
delivery_config = delivery_from_grpc(request.delivery)
|
|
delivery_config = delivery_from_grpc(request.delivery)
|
|
res = get_cl(request.base).update_delivery_service_instance(delivery_config['uuid'], delivery_config).json()
|
|
res = get_cl(request.base).update_delivery_service_instance(delivery_config['uuid'], delivery_config).json()
|
|
|
|
+ check_error(res, context)
|
|
return delivery_to_grpc(res)
|
|
return delivery_to_grpc(res)
|
|
|
|
|
|
def DeleteDelivery(self, request, context):
|
|
def DeleteDelivery(self, request, context):
|
|
res = get_cl(request.base).delete_delivery_service_instance(request.id).json()
|
|
res = get_cl(request.base).delete_delivery_service_instance(request.id).json()
|
|
|
|
+ check_error(res, context)
|
|
return delivery_to_grpc(res)
|
|
return delivery_to_grpc(res)
|
|
|
|
|
|
|
|
|