Class: ChefCLI::Policyfile::ArtifactoryCookbookSource

Inherits:
Object
  • Object
show all
Defined in:
lib/chef-cli/policyfile/artifactory_cookbook_source.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, chef_config: nil) {|_self| ... } ⇒ ArtifactoryCookbookSource

Returns a new instance of ArtifactoryCookbookSource.

Yields:

  • (_self)

Yield Parameters:



32
33
34
35
36
37
38
# 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

Instance Attribute Details

#chef_configObject (readonly)

Returns the value of attribute chef_config.



30
31
32
# File 'lib/chef-cli/policyfile/artifactory_cookbook_source.rb', line 30

def chef_config
  @chef_config
end

#preferred_cookbooksObject (readonly)

Returns the value of attribute preferred_cookbooks.



29
30
31
# File 'lib/chef-cli/policyfile/artifactory_cookbook_source.rb', line 29

def preferred_cookbooks
  @preferred_cookbooks
end

#uriObject (readonly)

Returns the value of attribute uri.



28
29
30
# File 'lib/chef-cli/policyfile/artifactory_cookbook_source.rb', line 28

def uri
  @uri
end

Instance Method Details

#==(other) ⇒ Object



44
45
46
# 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_keyObject



83
84
85
# File 'lib/chef-cli/policyfile/artifactory_cookbook_source.rb', line 83

def artifactory_api_key
  chef_config&.artifactory_api_key || (ENV["ARTIFACTORY_API_KEY"] unless ENV["ARTIFACTORY_API_KEY"].to_s.strip.empty?)
end

#artifactory_identity_tokenObject



87
88
89
# File 'lib/chef-cli/policyfile/artifactory_cookbook_source.rb', line 87

def artifactory_identity_token
  chef_config&.artifactory_identity_token || (ENV["ARTIFACTORY_IDENTITY_TOKEN"] unless ENV["ARTIFACTORY_IDENTITY_TOKEN"].to_s.strip.empty?)
end

#default_source_argsObject



40
41
42
# File 'lib/chef-cli/policyfile/artifactory_cookbook_source.rb', line 40

def default_source_args
  [:artifactory, uri]
end

#descObject



79
80
81
# File 'lib/chef-cli/policyfile/artifactory_cookbook_source.rb', line 79

def desc
  "artifactory(#{uri})"
end

#null?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/chef-cli/policyfile/artifactory_cookbook_source.rb', line 75

def null?
  false
end

#preferred_for(*cookbook_names) ⇒ Object



48
49
50
# 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) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
# 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) ⇒ Object



66
67
68
69
70
71
72
73
# File 'lib/chef-cli/policyfile/artifactory_cookbook_source.rb', line 66

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_graphObject



56
57
58
59
60
61
62
63
64
# File 'lib/chef-cli/policyfile/artifactory_cookbook_source.rb', line 56

def universe_graph
  @universe_graph ||= full_community_graph.inject({}) do |normalized_graph, (cookbook_name, )|
    normalized_graph[cookbook_name] = .inject({}) do |deps_by_version, (version, )|
      deps_by_version[version] = ["dependencies"]
      deps_by_version
    end
    normalized_graph
  end
end