Sha256: 9f3780f66fe27d5d5e787a56921037359ea17dc97d0c393235d9d39484b3b5f5
Contents?: true
Size: 1.49 KB
Versions: 4
Compression:
Stored size: 1.49 KB
Contents
require 'singleton' require 'open-uri' require 'cocoapods-whitelist/model/allowed_dependency' class WhitelistResolver include Singleton attr_accessor :whitelist attr_accessor :whitelist_loaded attr_accessor :whitelist_url def config @whitelist ||= [] end def initialize() @whitelist_url = DEFAULT_WHITELIST_URL load_whitelist() end def get_whitelist(whitelist_url = DEFAULT_WHITELIST_URL) @whitelist_loaded = @whitelist_url == whitelist_url @whitelist_url = whitelist_url load_whitelist() unless @whitelist_loaded return @whitelist end def load_whitelist begin URI.open(@whitelist_url) { |io| buffer = io.read @whitelist = parse_whitelist(buffer) @whitelist_loaded = true } rescue OpenURI::HTTPError => e status = e.io.status.join(' ') raise "Failed to fetch whitelist from '#{@whitelist_url}'.\n Error: #{status}" end end def parse_whitelist(raw_whitelist) json = JSON.parse(raw_whitelist) return json["whitelist"].map { |dependencyJson| AllowedDependency.new( dependencyJson["name"], dependencyJson["version"], dependencyJson["expire"], dependencyJson["source"], dependencyJson["target"], dependencyJson["allows_granular_projects"] ) } end end
Version data entries
4 entries across 4 versions & 1 rubygems