コード例 #1
0
ファイル: handlers.py プロジェクト: scottjiang1415/syndicate
    def get(self, operation, volume_id_str, file_id_str, *args):

        # valid operation?
        if operation not in MSFileHandler.get_api_calls.keys():
            response_user_error(self, 401)
            return

        # valid file ID?
        file_id = -1
        try:
            file_id = MSEntry.unserialize_id(int(file_id_str, 16))
        except:
            response_user_error(self, 400)
            return

        # valid gateway and volume?
        gateway, volume, response_timing = response_begin(
            self, volume_id_str, fail_if_no_auth_header=False)
        if volume == None:
            return

        # reader allowed?
        allowed = file_read_auth(gateway, volume)
        if not allowed:
            response_user_error(self, 403)
            return

        # parse CGI arguments
        status, kw = MSFileHandler.parse_cgi(operation, self.request,
                                             self.cgi_args)

        if status != 200:
            response_user_error(self, status)
            return

        benchmark_header = MSFileHandler.get_benchmark_headers[operation]
        api_call = MSFileHandler.get_api_calls[operation]

        timing = {}

        # run and benchmark the operation
        try:
            data = benchmark(
                benchmark_header, timing,
                lambda: api_call(gateway, volume, file_id, args, kw))

        except storagetypes.RequestDeadlineExceededError, de:
            response_user_error(self, 503)
            return
コード例 #2
0
ファイル: handlers.py プロジェクト: etherparty/syndicate
   def get( self, operation, volume_id_str, file_id_str, *args ):

      # valid operation?
      if operation not in MSFileHandler.get_api_calls.keys():
         response_user_error( self, 401 )
         return 
      
      # valid file ID?
      file_id = -1
      try:
         file_id = MSEntry.unserialize_id( int( file_id_str, 16 ) )
      except:
         response_user_error( self, 400 )
         return
      
      # valid gateway and volume?
      gateway, volume, response_timing = response_begin( self, volume_id_str, fail_if_no_auth_header=False )
      if volume == None:
         return
      
      # reader allowed?
      allowed = file_read_auth( gateway, volume )
      if not allowed:
         response_user_error( self, 403 )
         return 
      
      # parse CGI arguments 
      status, kw = MSFileHandler.parse_cgi( operation, self.request, self.cgi_args )
      
      if status != 200:
         response_user_error( self, status )
         return 
         
      benchmark_header = MSFileHandler.get_benchmark_headers[ operation ]
      api_call = MSFileHandler.get_api_calls[ operation ]
      
      timing = {}
      
      # run and benchmark the operation
      try:
         data = benchmark( benchmark_header, timing, lambda: api_call( gateway, volume, file_id, args, kw ) )
         
      except storagetypes.RequestDeadlineExceededError, de:
         response_user_error( self, 503 )
         return
コード例 #3
0
ファイル: handlers.py プロジェクト: pombredanne/syndicate
   def get( self, operation, volume_id_str, volume_version_str, cert_version_str, file_id_str, *args ):

      # valid operation?
      if operation not in MSFileHandler.get_api_calls.keys():
         logging.error("Unrecognized operation '%s'" % operation)
         response_user_error( self, 401 )
         return 
      
      # valid file ID?
      file_id = -1
      try:
         file_id = MSEntry.unserialize_id( int( file_id_str, 16 ) )
      except:
         response_user_error( self, 400 )
         return
      
      # valid volume ID?
      volume_id = -1 
      try:
         volume_id = int( volume_id_str )
      except:
         response_user_error( self, 400 )
         return 
      
      # get gateway, volume, and timing...
      volume, gateway, status, response_timing = response_begin( self, volume_id )
      
      if volume is None:
         response_user_error( self, status )
         return
      
      # reader allowed?
      allowed = file_read_auth( gateway, volume )
      if not allowed:
         response_user_error( self, 403 )
         return 
      
      # reader has fresh volume cert?
      if volume.version != int(volume_version_str):
         # stale
         log.error( "volume.version = %s, volume_version_str = %s" % (volume.version, volume_version_str) )
         response_user_error( self, 410, "Stale volume version" )
         return 
      
      # reader has fresh cert bundle?
      if volume.cert_bundle is not None and volume.cert_bundle.mtime_sec != int(cert_version_str):
         # stale 
         log.error( "volume.cert_bundle.mtime_sec = %s, cert_version_str = %s" % (volume.cert_bundle.mtime_sec, cert_version_str))
         response_user_error( self, 410, "Stale gateway version" )
         return
         
      # parse CGI arguments 
      status, kw = MSFileHandler.parse_cgi( operation, self.request, self.cgi_args )
      
      if status != 200:
         response_user_error( self, status )
         return 
         
      benchmark_header = MSFileHandler.get_benchmark_headers[ operation ]
      api_call = MSFileHandler.get_api_calls[ operation ]
      
      timing = {}
      
      # run and benchmark the operation
      try:
         data = benchmark( benchmark_header, timing, lambda: api_call( gateway, volume, file_id, args, kw ) )
         
      except storagetypes.RequestDeadlineExceededError, de:
         response_user_error( self, 503 )
         return
コード例 #4
0
ファイル: handlers.py プロジェクト: fireshock199/syndicate
   def get( self, operation, volume_id_str, file_id_str, *args ):

      # valid operation?
      if operation not in MSFileHandler.get_api_calls.keys():
         response_user_error( self, 401 )
         return 
      
      # valid file ID?
      file_id = -1
      try:
         file_id = MSEntry.unserialize_id( int( file_id_str, 16 ) )
      except:
         response_user_error( self, 400 )
         return
      
      # valid gateway and volume?
      gateway, volume, response_timing = response_begin( self, volume_id_str, fail_if_no_auth_header=False )
      if volume == None:
         return
      
      # reader allowed?
      allowed = file_read_auth( gateway, volume )
      if not allowed:
         response_user_error( self, 403 )
         return 
      
      # do we have a requested page for this request?
      page_id = self.request.get('page_id')
      file_ids_only = self.request.get('file_ids_only')
      
      if page_id is None or len(page_id) == 0:
         log.error("No page ID given")
         response_user_error( self, 400 )
         return 
      
      if file_ids_only is None or len(file_ids_only) == 0:
         file_ids_only = 0
      else:
         try:
            file_ids_only = int(file_ids_only)
         except:
            log.error("Invalid file_ids_only value '%s'" % file_ids_only)
            response_user_error( self, 400 )
            return 
            
      if file_ids_only != 0:
         file_ids_only = True 
      else:
         file_ids_only = False 
         
      # validate 
      try:
         page_id = int(page_id)
         assert page_id >= 0, "Invalid page ID value"
      except:
         # needs to be a number 
         log.error("Invalid page ID '%s'" % page_id)
         response_user_error( self, 400 )
         return 
         
      benchmark_header = MSFileHandler.get_benchmark_headers[ operation ]
      api_call = MSFileHandler.get_api_calls[ operation ]
      
      timing = {}
      
      # run and benchmark the operation
      try:
         data = benchmark( benchmark_header, timing, lambda: api_call( gateway, volume, file_id, args, page_id, file_ids_only ) )
         
      except storagetypes.RequestDeadlineExceededError, de:
         response_user_error( self, 503 )
         return
コード例 #5
0
ファイル: handlers.py プロジェクト: iychoi/syndicate-core
    def get(self, operation, volume_id_str, volume_version_str,
            cert_version_str, file_id_str, *args):

        # valid operation?
        if operation not in MSFileHandler.get_api_calls.keys():
            logging.error("Unrecognized operation '%s'" % operation)
            response_user_error(self, 401)
            return

        # valid file ID?
        file_id = -1
        try:
            file_id = MSEntry.unserialize_id(int(file_id_str, 16))
        except:
            response_user_error(self, 400)
            return

        # valid volume ID?
        volume_id = -1
        try:
            volume_id = int(volume_id_str)
        except:
            response_user_error(self, 400)
            return

        # get gateway, volume, and timing...
        volume, gateway, status, response_timing = response_begin(
            self, volume_id)

        if volume is None:
            response_user_error(self, status)
            return

        # reader allowed?
        allowed = file_read_auth(gateway, volume)
        if not allowed:
            response_user_error(self, 403)
            return

        # reader has fresh volume cert?
        if volume.version != int(volume_version_str):
            # stale
            log.error("volume.version = %s, volume_version_str = %s" %
                      (volume.version, volume_version_str))
            response_user_error(self, 410, "Stale volume version")
            return

        # reader has fresh cert bundle?
        if volume.cert_bundle is not None and volume.cert_bundle.mtime_sec != int(
                cert_version_str):
            # stale
            log.error(
                "volume.cert_bundle.mtime_sec = %s, cert_version_str = %s" %
                (volume.cert_bundle.mtime_sec, cert_version_str))
            response_user_error(self, 410, "Stale gateway version")
            return

        # parse CGI arguments
        status, kw = MSFileHandler.parse_cgi(operation, self.request,
                                             self.cgi_args)

        if status != 200:
            response_user_error(self, status)
            return

        benchmark_header = MSFileHandler.get_benchmark_headers[operation]
        api_call = MSFileHandler.get_api_calls[operation]

        timing = {}

        # run and benchmark the operation
        try:
            data = benchmark(
                benchmark_header, timing,
                lambda: api_call(gateway, volume, file_id, args, kw))

        except storagetypes.RequestDeadlineExceededError, de:
            response_user_error(self, 503)
            return