Beispiel #1
0
 def get(self, request, *args, **kwargs):
     """ Provides the CA certificate """
     verify_secure(request)
     form = kwargs.get('form', 'pem').lower()
     # Get MD5 value from request if available
     req_md5 = None
     if 'HTTP_X_MD5' in request.META:
         req_md5 = request.META['HTTP_X_MD5']
     # Calculate MD5 value
     file_md5 = None
     try:
         file_md5 = openssl.get_ca_crt_md5(settings.APP_DATA_CERT_DIR, form)
     except Exception as e:
         raise exceptions.NotFound(e)
     # If MD5 value is provided in request => Verify that update is required
     if req_md5 and req_md5 == file_md5:
         return Response(status=rest_status.HTTP_304_NOT_MODIFIED)
     # Deliver update
     stream = None
     try:
         stream = openssl.get_ca_crt_stream(settings.APP_DATA_CERT_DIR,
                                            form)
     except Exception as e:
         raise exceptions.NotFound(e)
     if (not stream) or (not file_md5):
         raise exceptions.NotFound()
     response = http.FileResponse(stream)
     response['Content-Type'] = 'application/octet-stream'
     response['Content-Length'] = os.fstat(stream.fileno()).st_size
     response['Content-Disposition'] = "attachment; filename={}.{}".format(
         'ca.crt', form)
     response['x-MD5'] = file_md5
     return response
Beispiel #2
0
 def get(self, request):
     """ Provides the firmware if the update is required """
     verify_secure(request)
     if not request.user.profile.is_device:
         raise rest_exceptions.NotAcceptable('Only for devices')
     assignment = None
     try:
         assignment = request.user.firmware
     except local_models.FirmwareAssignmentModel.DoesNotExist:
         raise rest_exceptions.NotFound({'firmware': 'Not available'})
     if assignment.value.hardware == local_models.FirmwareModel.HW_ESP8266_4MB:
         return esp8266.update(request, assignment)
     else:
         raise rest_exceptions.NotAcceptable(
             'The [{:s}] is not supported'.format(
                 assignment.value.hardware))
Beispiel #3
0
 def patch(self, request, *args, **kwargs):
     """ Partially updating the specific firmware """
     verify_secure(request)
     return super().patch(request, args, kwargs)
Beispiel #4
0
 def put(self, request, *args, **kwargs):
     """ Updating the specific firmware """
     verify_secure(request)
     return super().put(request, args, kwargs)
Beispiel #5
0
 def get(self, request, *args, **kwargs):
     """ Retrieves details about the specific firmware """
     verify_secure(request)
     return super().get(request, args, kwargs)
Beispiel #6
0
 def post(self, request, *args, **kwargs):
     """ Creates the new firmware """
     verify_secure(request)
     return super().post(request, args, kwargs)
Beispiel #7
0
 def get(self, request, *args, **kwargs):
     """ Retrieves the list of firmwares """
     verify_secure(request)
     return super().get(request, args, kwargs)
Beispiel #8
0
 def delete(self, request, *args, **kwargs):
     """ Deletes the specific firmware assignment """
     verify_secure(request)
     return super().delete(request, args, kwargs)