class ChefCLI::Policyfile::ArtifactoryCookbookSource
Attributes
chef_config[R]
preferred_cookbooks[R]
uri[R]
Public Class Methods
new(uri, chef_config: nil) { |self| ... }
click to toggle source
# File lib/chef-cli/policyfile/artifactory_cookbook_source.rb, line 32 def initialize(uri, chef_config: nil) @uri = uri @http_connections = {} @chef_config = chef_config @preferred_cookbooks = [] yield self if block_given? end
Public Instance Methods
==(other)
click to toggle source
# File lib/chef-cli/policyfile/artifactory_cookbook_source.rb, line 44 def ==(other) other.is_a?(self.class) && other.uri == uri && other.preferred_cookbooks == preferred_cookbooks end
artifactory_api_key()
click to toggle source
# File lib/chef-cli/policyfile/artifactory_cookbook_source.rb, line 85 def artifactory_api_key chef_config&.artifactory_api_key || ENV["ARTIFACTORY_API_KEY"] end
default_source_args()
click to toggle source
# File lib/chef-cli/policyfile/artifactory_cookbook_source.rb, line 40 def default_source_args [:artifactory, uri] end
desc()
click to toggle source
# File lib/chef-cli/policyfile/artifactory_cookbook_source.rb, line 81 def desc "artifactory(#{uri})" end
null?()
click to toggle source
# File lib/chef-cli/policyfile/artifactory_cookbook_source.rb, line 77 def null? false end
preferred_for(*cookbook_names)
click to toggle source
# File lib/chef-cli/policyfile/artifactory_cookbook_source.rb, line 48 def preferred_for(*cookbook_names) preferred_cookbooks.concat(cookbook_names) end
preferred_source_for?(cookbook_name)
click to toggle source
# File lib/chef-cli/policyfile/artifactory_cookbook_source.rb, line 52 def preferred_source_for?(cookbook_name) preferred_cookbooks.include?(cookbook_name) end
source_options_for(cookbook_name, cookbook_version)
click to toggle source
# File lib/chef-cli/policyfile/artifactory_cookbook_source.rb, line 68 def source_options_for(cookbook_name, cookbook_version) base_uri = full_community_graph[cookbook_name][cookbook_version]["download_url"] { artifactory: base_uri, version: cookbook_version, http_client: http_connection_for(base_uri.to_s), } end
universe_graph()
click to toggle source
# File lib/chef-cli/policyfile/artifactory_cookbook_source.rb, line 56 def universe_graph @universe_graph ||= begin full_community_graph.inject({}) do |normalized_graph, (cookbook_name, metadata_by_version)| normalized_graph[cookbook_name] = metadata_by_version.inject({}) do |deps_by_version, (version, metadata)| deps_by_version[version] = metadata["dependencies"] deps_by_version end normalized_graph end end end
Private Instance Methods
full_community_graph()
click to toggle source
# File lib/chef-cli/policyfile/artifactory_cookbook_source.rb, line 96 def full_community_graph @full_community_graph ||= begin graph_json = http_connection_for(uri).get("/universe") JSON.parse(graph_json) end end
http_connection_for(base_url)
click to toggle source
# File lib/chef-cli/policyfile/artifactory_cookbook_source.rb, line 91 def http_connection_for(base_url) headers = { "X-Jfrog-Art-API" => artifactory_api_key } @http_connections[base_url] ||= Chef::HTTP::Simple.new(base_url, headers: headers) end