app/models/quota.rb
# Get quota objects only for requested user in JSON file(s)
#
# KeyError and JSON::ParserErrors shall be non-fatal errors
Get quota objects only for requested user in JSON file(s)
KeyError and JSON::ParserErrors shall be non-fatal errors
Get quota objects only for requested user in JSON file ( s ) KeyError and JSON :: ParserErrors shall be non - fatal errors
def find(quota_path, user)
      user  = user && user.to_s
      quotas = []
      if quota_path.instance_of?(String) and quota_path.match(/^https?:/)
        uri = URI.parse(quota_path)
        begin
          raw = Net::HTTP.get(uri)
        rescue StandardError => e
            Rails.logger.error("Quota URI failed to return data: #{e.message}")
            return []
        end
      else
        if quota_path.instance_of?(String)
          quota_path = Pathname.new(quota_path)
        end
        raw = quota_path.read
      end
      begin
        json = JSON.parse(raw)
      rescue JSON::ParserError => e
        Rails.logger.error("Quota file is not limited JSON: #{e.message}")
	return []
      end
      Rails.logger.error("#{json}")
      begin
        case json["version"].to_i
        when 1
          quotas += find_v1(user, json)
        else
          raise InvalidQuotaFile.new("JSON version found was: #{json["version"].to_i}")
        end
      rescue KeyError => e
        Rails.logger.error("Quota entry for user #{user} is missing expected parameter #{e.message}")
      end
      quotas
    end
def find ( quota_path , user ) user = user && user . to_s quotas = [ ] if quota_path . instance_of? ( String ) and quota_path . match ( / ^https?: / ) uri = URI . parse ( quota_path ) begin raw = Net :: HTTP . get ( uri ) rescue StandardError => e Rails . logger . error ( "Quota URI failed to return data: #{e.message}" ) return [ ] end else if quota_path . instance_of? ( String ) quota_path = Pathname . new ( quota_path ) end raw = quota_path . read end begin json = JSON . parse ( raw ) rescue JSON :: ParserError => e Rails . logger . error ( "Quota file is not limited JSON: #{e.message}" ) return [ ] end Rails . logger . error ( "#{json}" ) begin case json [ "version" ] . to_i when 1 quotas += find_v1 ( user , json ) else raise InvalidQuotaFile . new ( "JSON version found was: #{json["version"].to_i}" ) end rescue KeyError => e Rails . logger . error ( "Quota entry for user #{user} is missing expected parameter #{e.message}" ) end quotas end
Get quota objects only for requested user in JSON file(s)
KeyError and JSON::ParserErrors shall be non-fatal errors
Get quota objects only for requested user in JSON file ( s ) KeyError and JSON :: ParserErrors shall be non - fatal errors
# Attempt to convert path into a URI # If it is a URI, and it is http:// or https:// # There are a million ways this could go wrong, assume configured correctly and is temporary issue (e.g., not a URL typo). # Bail with empty results. Don't break portal because web service is down. # If not a URL, assume it is a local file and attempt to read. # If we're fed a string, convert to Pathname. Otherwise, use as is. # Assume this always works, unless configured wrong, in which case don't attempt to catch. # Attempt to parse raw JSON into an object # Parse JSON object into quota data
quota_path
user