Class: AllowlistResolver

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/cocoapods-allowlist/client/allowlist_resolver.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAllowlistResolver

Returns a new instance of AllowlistResolver.



22
23
24
25
26
27
# File 'lib/cocoapods-allowlist/client/allowlist_resolver.rb', line 22

def initialize()
    @allowlist_url = ConfigURL::ALLOWLIST_SSH
    @allowlist_directory = nil
    @allowlist_branch = "master"
    load_allowlist()
end

Instance Attribute Details

#allowlistObject

Returns the value of attribute allowlist.



12
13
14
# File 'lib/cocoapods-allowlist/client/allowlist_resolver.rb', line 12

def allowlist
  @allowlist
end

#allowlist_branchObject

Returns the value of attribute allowlist_branch.



16
17
18
# File 'lib/cocoapods-allowlist/client/allowlist_resolver.rb', line 16

def allowlist_branch
  @allowlist_branch
end

#allowlist_directoryObject

Returns the value of attribute allowlist_directory.



15
16
17
# File 'lib/cocoapods-allowlist/client/allowlist_resolver.rb', line 15

def allowlist_directory
  @allowlist_directory
end

#allowlist_loadedObject

Returns the value of attribute allowlist_loaded.



13
14
15
# File 'lib/cocoapods-allowlist/client/allowlist_resolver.rb', line 13

def allowlist_loaded
  @allowlist_loaded
end

#allowlist_urlObject

Returns the value of attribute allowlist_url.



14
15
16
# File 'lib/cocoapods-allowlist/client/allowlist_resolver.rb', line 14

def allowlist_url
  @allowlist_url
end

Instance Method Details

#configObject



18
19
20
# File 'lib/cocoapods-allowlist/client/allowlist_resolver.rb', line 18

def config 
    @allowlist ||= []
end

#get_allowlist(allowlist_url = ConfigURL::ALLOWLIST_SSH) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/cocoapods-allowlist/client/allowlist_resolver.rb', line 29

def get_allowlist(allowlist_url = ConfigURL::ALLOWLIST_SSH)
    @allowlist_loaded = @allowlist_url == allowlist_url
    @allowlist_url = allowlist_url

    load_allowlist() unless @allowlist_loaded
    return @allowlist
end

#load_allowlistObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/cocoapods-allowlist/client/allowlist_resolver.rb', line 37

def load_allowlist
    begin
        create_temp_directory
        GitHelper.clone_from_branch(@allowlist_url, @allowlist_directory, @allowlist_branch)
        file_path = File.join(@allowlist_directory, "ios-allowlist.json")

        if File.exist?(file_path)
            file = File.read(file_path)
            @allowlist = parse_allowlist(file)
            @allowlist_loaded = true
        else
            raise "File not found: #{file_path}"
        end
    rescue OpenURI::HTTPError => e
        status = e.io.status.join(' ')
        raise "Failed to fetch allowlist from '#{@allowlist_url}'.\n Error: #{status}"
    rescue => e
        raise "Failed to load allowlist: #{e.message}"
    ensure
        cleanup
    end
end

#parse_allowlist(raw_allowlist) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/cocoapods-allowlist/client/allowlist_resolver.rb', line 60

def parse_allowlist(raw_allowlist)
    json = JSON.parse(raw_allowlist)
    return json["allowlist"].map { |dependencyJson|
        AllowedDependency.new(
            dependencyJson["name"],
            dependencyJson["version"],
            dependencyJson["expires"],
            dependencyJson["source"],
            dependencyJson["target"],
            dependencyJson["allows_granular_projects"]
        )
    }
end