Parent

Included Modules

Librarian::Puppet::Source::GitHubTarball::Repo

Constants

TOKEN_KEY

Attributes

name[RW]
source[RW]

Public Class Methods

new(source, name) click to toggle source
# File lib/librarian/puppet/source/githubtarball.rb, line 22
def initialize(source, name)
  self.source = source
  self.name = name
  warn { "githubtarball sources are deprecated: #{name} [#{source}]" }
end

Public Instance Methods

cache_path() click to toggle source
# File lib/librarian/puppet/source/githubtarball.rb, line 73
def cache_path
  @cache_path ||= source.cache_path.join(name)
end
cache_version_unpacked!(version) click to toggle source
# File lib/librarian/puppet/source/githubtarball.rb, line 85
def cache_version_unpacked!(version)
  path = version_unpacked_cache_path(version)
  return if path.directory?

  path.mkpath

  target = vendored?(source.uri, version) ? vendored_path(source.uri, version) : name

  Librarian::Posix.run!(%{tar xzf #{target} -C #{path}})
end
clean_up_old_cached_versions(name) click to toggle source
# File lib/librarian/puppet/source/githubtarball.rb, line 126
def clean_up_old_cached_versions(name)
  Dir["#{environment.vendor_cache}/#{name.sub('/', '-')}*.tar.gz"].each do |old_version|
    FileUtils.rm old_version
  end
end
environment() click to toggle source
# File lib/librarian/puppet/source/githubtarball.rb, line 69
def environment
  source.environment
end
hexdigest(value) click to toggle source
# File lib/librarian/puppet/source/githubtarball.rb, line 81
def hexdigest(value)
  Digest::MD5.hexdigest(value)
end
install_version!(version, install_path) click to toggle source
# File lib/librarian/puppet/source/githubtarball.rb, line 52
def install_version!(version, install_path)
  if environment.local? && !vendored?(source.uri, version)
    raise Error, "Could not find a local copy of #{source.uri} at #{version}."
  end

  vendor_cache(source.uri, version) unless vendored?(source.uri, version)

  cache_version_unpacked! version

  if install_path.exist?
    install_path.rmtree
  end

  unpacked_path = version_unpacked_cache_path(version).children.first
  cp_r(unpacked_path, install_path)
end
manifests() click to toggle source
# File lib/librarian/puppet/source/githubtarball.rb, line 46
def manifests
  versions.map do |version|
    Manifest.new(source, name, version)
  end
end
vendor_cache(name, version) click to toggle source
# File lib/librarian/puppet/source/githubtarball.rb, line 105
def vendor_cache(name, version)
  clean_up_old_cached_versions(name)

  url = "https://api.github.com/repos/#{name}/tarball/#{version}"
  url << "?access_token=#{ENV['GITHUB_API_TOKEN']}" if ENV['GITHUB_API_TOKEN']

  File.open(vendored_path(name, version).to_s, 'wb') do |f|
    begin
      debug { "Downloading <#{url}> to <#{f.path}>" }
      open(url,
        "User-Agent" => "librarian-puppet v#{Librarian::Puppet::VERSION}") do |res|
        while buffer = res.read(8192)
          f.write(buffer)
        end
      end
    rescue OpenURI::HTTPError => e
      raise e, "Error requesting <#{url}>: #{e.to_s}"
    end
  end
end
vendored?(name, version) click to toggle source
# File lib/librarian/puppet/source/githubtarball.rb, line 96
def vendored?(name, version)
  vendored_path(name, version).exist?
end
vendored_path(name, version) click to toggle source
# File lib/librarian/puppet/source/githubtarball.rb, line 100
def vendored_path(name, version)
  environment.vendor_cache.mkpath
  environment.vendor_cache.join("#{name.sub("/", "-")}-#{version}.tar.gz")
end
version_unpacked_cache_path(version) click to toggle source
# File lib/librarian/puppet/source/githubtarball.rb, line 77
def version_unpacked_cache_path(version)
  cache_path.join('version').join(hexdigest(version.to_s))
end
versions() click to toggle source
# File lib/librarian/puppet/source/githubtarball.rb, line 28
def versions
  return @versions if @versions
  data = api_call("/repos/#{source.uri}/tags")
  if data.nil?
    raise Error, "Unable to find module '#{source.uri}' on https://github.com"
  end

  all_versions = data.map { |r| r['name'].gsub(/^v/, '') }.sort.reverse

  all_versions.delete_if do |version|
    version !~ /\A\d\.\d(\.\d.*)?\z/
  end

  @versions = all_versions.compact
  debug { "  Module #{name} found versions: #{@versions.join(", ")}" }
  @versions
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.