Class: ChefCLI::Policyfile::CookbookLock

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

Overview

Base class for CookbookLock implementations

Direct Known Subclasses

ArchivedCookbook, CachedCookbook, LocalCookbook

Constant Summary collapse

REQUIRED_LOCK_DATA_KEYS =
%w{version identifier dotted_decimal_identifier cache_key source_options}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from StorageConfigDelegation

#cache_path, #policyfile_expanded_path, #policyfile_filename, #policyfile_lock_expanded_path, #relative_paths_root

Constructor Details

#initialize(name, storage_config) ⇒ CookbookLock

Returns a new instance of CookbookLock.



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

def initialize(name, storage_config)
  @name = name
  @version = nil
  @source_options = nil
  @identifier = nil
  @dotted_decimal_identifier = nil
  @storage_config = storage_config
end

Instance Attribute Details

#dotted_decimal_identifierObject

A string in “X.Y.Z” version number format that uniquely identifies the cookbook version. This is for compatibility with Chef Infra Server 11.x, where cookbooks are stored by x.y.z version numbers.



59
60
61
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 59

def dotted_decimal_identifier
  @dotted_decimal_identifier
end

#identifierObject

A string that uniquely identifies the cookbook version. If not explicitly set, an identifier is generated based on the cookbook’s content.



54
55
56
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 54

def identifier
  @identifier
end

#nameObject (readonly)

The cookbook name (without any version or other info suffixed)



44
45
46
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 44

def name
  @name
end

#source_optionsObject

Options specifying the source and revision of this cookbook. These can be passed to a CookbookLocationSpecification to create an object that can install the same revision of the cookbook on another machine.



49
50
51
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 49

def source_options
  @source_options
end

#storage_configObject (readonly)

Returns the value of attribute storage_config.



61
62
63
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 61

def storage_config
  @storage_config
end

#versionObject

Returns the value of attribute version.



63
64
65
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 63

def version
  @version
end

Instance Method Details

#build_from_lock_data(lock_data) ⇒ Object

Raises:

  • (NotImplementedError)


116
117
118
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 116

def build_from_lock_data(lock_data)
  raise NotImplementedError, "#{self.class} must override #build_from_lock_data with a specific implementation"
end

#chefignoreObject



161
162
163
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 161

def chefignore
  @chefignore ||= Chef::Cookbook::Chefignore.new(File.join(cookbook_path, "chefignore"))
end

#cookbook_loaderObject



152
153
154
155
156
157
158
159
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 152

def cookbook_loader
  @cookbook_loader ||=
    begin
      loader = Chef::Cookbook::CookbookVersionLoader.new(cookbook_path, chefignore)
      loader.load!
      loader
    end
end

#cookbook_location_specObject



82
83
84
85
86
87
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 82

def cookbook_location_spec
  raise InvalidCookbookLockData, "Cannot create CookbookLocationSpecification for #{name} without version" if version.nil?
  raise InvalidCookbookLockData, "Cannot create CookbookLocationSpecification for #{name} without source options" if source_options.nil?

  @location_spec ||= CookbookLocationSpecification.new(name, "= #{version}", source_options, storage_config)
end

#cookbook_pathObject

Raises:

  • (NotImplementedError)


103
104
105
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 103

def cookbook_path
  raise NotImplementedError, "#{self.class} must override #cookbook_path with a specific implementation"
end

#cookbook_versionObject



148
149
150
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 148

def cookbook_version
  @cookbook_version ||= cookbook_loader.cookbook_version
end

#dependenciesObject



89
90
91
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 89

def dependencies
  cookbook_location_spec.dependencies
end

#gather_profile_dataObject



93
94
95
96
97
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 93

def gather_profile_data
  @identifier ||= identifiers.content_identifier
  @dotted_decimal_identifier ||= identifiers.dotted_decimal_identifier
  @version ||= identifiers.semver_version
end

#identifier_updated?Boolean

Returns:

  • (Boolean)


132
133
134
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 132

def identifier_updated?
  false
end

#identifiersObject



99
100
101
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 99

def identifiers
  @identifiers ||= CookbookProfiler::Identifiers.new(cookbook_version)
end

#install_lockedObject



78
79
80
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 78

def install_locked
  cookbook_location_spec.ensure_cached
end

#installed?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 74

def installed?
  cookbook_location_spec.installed?
end

#lock_dataObject

Raises:

  • (NotImplementedError)


112
113
114
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 112

def lock_data
  raise NotImplementedError, "#{self.class} must override #lock_data a specific implementation"
end

#refresh!Object

Raises:

  • (NotImplementedError)


124
125
126
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 124

def refresh!
  raise NotImplementedError, "#{self.class} must override #refresh! with a specific implementation"
end

#symbolize_source_options_keys(source_options_from_json) ⇒ Object



140
141
142
143
144
145
146
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 140

def symbolize_source_options_keys(source_options_from_json)
  source_options_from_json ||= {}
  source_options_from_json.inject({}) do |normalized_source_opts, (key, value)|
    normalized_source_opts[key.to_sym] = value
    normalized_source_opts
  end
end

#to_lockObject



107
108
109
110
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 107

def to_lock
  validate!
  lock_data
end

#updated?Boolean

Returns:

  • (Boolean)


128
129
130
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 128

def updated?
  false
end

#validate!Object

Raises:

  • (NotImplementedError)


120
121
122
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 120

def validate!
  raise NotImplementedError, "#{self.class} must override #validate! with a specific implementation"
end

#version_updated?Boolean

Returns:

  • (Boolean)


136
137
138
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 136

def version_updated?
  false
end