Class: CookbookOmnifetch::ChefServerArtifactLocation

Inherits:
BaseLocation
  • Object
show all
Defined in:
lib/cookbook-omnifetch/chef_server_artifact.rb

Overview

This location allows fetching from the ‘cookbook_artifacts/` API where Chef Server stores cookbooks for policyfile use when they’re uploaded via ‘chef push`.

End users likely won’t have much use for this; it’s intended to facilitate included policies when including a policy stored on a chef server and cookbooks cannot be installed from the original source based on the information in the included policy.

Instance Attribute Summary collapse

Attributes inherited from BaseLocation

#dependency, #options

Instance Method Summary collapse

Methods inherited from BaseLocation

#to_lock, #validate_cached!

Constructor Details

#initialize(dependency, options = {}) ⇒ ChefServerArtifactLocation

Returns a new instance of ChefServerArtifactLocation.



17
18
19
20
21
22
# File 'lib/cookbook-omnifetch/chef_server_artifact.rb', line 17

def initialize(dependency, options = {})
  super
  @cookbook_identifier = options[:identifier]
  @http_client = options[:http_client] || default_chef_server_http_client
  @uri ||= options[:chef_server_artifact]
end

Instance Attribute Details

#cookbook_identifierObject (readonly)

Returns the value of attribute cookbook_identifier.



14
15
16
# File 'lib/cookbook-omnifetch/chef_server_artifact.rb', line 14

def cookbook_identifier
  @cookbook_identifier
end

#uriObject (readonly)

Returns the value of attribute uri.



15
16
17
# File 'lib/cookbook-omnifetch/chef_server_artifact.rb', line 15

def uri
  @uri
end

Instance Method Details

#cache_keyObject



67
68
69
# File 'lib/cookbook-omnifetch/chef_server_artifact.rb', line 67

def cache_key
  "#{dependency.name}-#{cookbook_identifier}"
end

#cached_cookbookObject



72
73
74
# File 'lib/cookbook-omnifetch/chef_server_artifact.rb', line 72

def cached_cookbook
  @cached_cookbook ||= CookbookOmnifetch.cached_cookbook_class.from_path(install_path)
end

#cookbook_nameObject



28
29
30
# File 'lib/cookbook-omnifetch/chef_server_artifact.rb', line 28

def cookbook_name
  dependency.name
end

#http_clientObject



51
52
53
# File 'lib/cookbook-omnifetch/chef_server_artifact.rb', line 51

def http_client
  @http_client
end

#installObject



40
41
42
# File 'lib/cookbook-omnifetch/chef_server_artifact.rb', line 40

def install
  installer.install
end

#install_pathPathname?

The path where this cookbook would live in the store, if it were installed.

Returns:

  • (Pathname, nil)


59
60
61
# File 'lib/cookbook-omnifetch/chef_server_artifact.rb', line 59

def install_path
  @install_path ||= CookbookOmnifetch.storage_path.join(cache_key)
end

#installed?Boolean

Determine if this revision is installed.

Returns:

  • (Boolean)


47
48
49
# File 'lib/cookbook-omnifetch/chef_server_artifact.rb', line 47

def installed?
  install_path.exist?
end

#installerObject



36
37
38
# File 'lib/cookbook-omnifetch/chef_server_artifact.rb', line 36

def installer
  MetadataBasedInstaller.new(http_client: http_client, url_path: url_path, install_path: install_path)
end

#lock_dataObject



63
64
65
# File 'lib/cookbook-omnifetch/chef_server_artifact.rb', line 63

def lock_data
  { "chef_server_artifact" => uri, "identifier" => cookbook_identifier }
end

#repo_hostObject



24
25
26
# File 'lib/cookbook-omnifetch/chef_server_artifact.rb', line 24

def repo_host
  @host ||= URI.parse(uri).host
end

#url_pathObject



32
33
34
# File 'lib/cookbook-omnifetch/chef_server_artifact.rb', line 32

def url_path
  "/cookbook_artifacts/#{cookbook_name}/#{cookbook_identifier}"
end