Class: Puppet::Forge::ModuleRelease

Inherits:
SemanticPuppet::Dependency::ModuleRelease
  • Object
show all
Defined in:
lib/puppet/forge.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, data) ⇒ ModuleRelease


125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/puppet/forge.rb', line 125

def initialize(source, data)
  @data = data
   = meta = data['metadata']

  name = meta['name'].tr('/', '-')
  version = SemanticPuppet::Version.parse(meta['version'])
  release = "#{name}@#{version}"

  if meta['dependencies']
    dependencies = meta['dependencies'].collect do |dep|
      begin
        Puppet::ModuleTool::.new.add_dependency(dep['name'], dep['version_requirement'], dep['repository'])
        Puppet::ModuleTool.parse_module_dependency(release, dep)[0..1]
      rescue ArgumentError => e
        raise ArgumentError, _("Malformed dependency: %{name}.") % { name: dep['name'] } +
            ' ' + _("Exception was: %{detail}") % { detail: e }
      end
    end
  else
    dependencies = []
  end

  super(source, name, version, Hash[dependencies])
end

Instance Attribute Details

#install_dirObject (readonly)

Returns the value of attribute install_dir


123
124
125
# File 'lib/puppet/forge.rb', line 123

def install_dir
  @install_dir
end

#metadataObject (readonly)

Returns the value of attribute metadata


123
124
125
# File 'lib/puppet/forge.rb', line 123

def 
  
end

Instance Method Details

#install(dir) ⇒ Object


150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/puppet/forge.rb', line 150

def install(dir)
  staging_dir = self.prepare

  module_dir = dir + name[/-(.*)/, 1]
  module_dir.rmtree if module_dir.exist?

  # Make sure unpacked module has the same ownership as the folder we are moving it into.
  Puppet::ModuleTool::Applications::Unpacker.harmonize_ownership(dir, staging_dir)

  FileUtils.mv(staging_dir, module_dir)
  @install_dir = dir

  # Return the Pathname object representing the directory where the
  # module release archive was unpacked the to.
  return module_dir
ensure
  staging_dir.rmtree if staging_dir.exist?
end

#prepareObject


169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/puppet/forge.rb', line 169

def prepare
  return @unpacked_into if @unpacked_into

  Puppet.warning "#{@metadata['name']} has been deprecated by its author! View module on Puppet Forge for more info." if deprecated?

  download(@data['file_uri'], tmpfile)
  checksum = @data['file_sha256']
  if checksum
    validate_checksum(tmpfile, checksum, Digest::SHA256)
  else
    checksum = @data['file_md5']
    if checksum
      validate_checksum(tmpfile, checksum, Digest::MD5)
    else
      raise _("Forge module is missing SHA256 and MD5 checksums")
    end
  end

  unpack(tmpfile, tmpdir)

  @unpacked_into = Pathname.new(tmpdir)
end