Class: ChefDK::Policyfile::CookbookLock

Inherits:
Object
  • Object
show all
Includes:
StorageConfigDelegation
Defined in:
lib/chef-dk/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}

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-dk/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 Server 11.x, where cookbooks are stored by x.y.z version numbers.



59
60
61
# File 'lib/chef-dk/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-dk/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-dk/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-dk/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-dk/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-dk/policyfile/cookbook_locks.rb', line 63

def version
  @version
end

Instance Method Details

#build_from_lock_data(lock_data) ⇒ Object

Raises:

  • (NotImplementedError)


115
116
117
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 115

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

#chefignoreObject



160
161
162
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 160

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

#cookbook_loaderObject



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

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
# File 'lib/chef-dk/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)


102
103
104
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 102

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

#cookbook_versionObject



147
148
149
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 147

def cookbook_version
  @cookbook_version ||= cookbook_loader.cookbook_version
end

#dependenciesObject



88
89
90
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 88

def dependencies
  cookbook_location_spec.dependencies
end

#gather_profile_dataObject



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

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)


131
132
133
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 131

def identifier_updated?
  false
end

#identifiersObject



98
99
100
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 98

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

#install_lockedObject



78
79
80
# File 'lib/chef-dk/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-dk/policyfile/cookbook_locks.rb', line 74

def installed?
  cookbook_location_spec.installed?
end

#lock_dataObject

Raises:

  • (NotImplementedError)


111
112
113
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 111

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

#refresh!Object

Raises:

  • (NotImplementedError)


123
124
125
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 123

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

#symbolize_source_options_keys(source_options_from_json) ⇒ Object



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

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



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

def to_lock
  validate!
  lock_data
end

#updated?Boolean

Returns:

  • (Boolean)


127
128
129
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 127

def updated?
  false
end

#validate!Object

Raises:

  • (NotImplementedError)


119
120
121
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 119

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

#version_updated?Boolean

Returns:

  • (Boolean)


135
136
137
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 135

def version_updated?
  false
end