class Ra10ke::Dependencies::Verification

Attributes

puppetfile[R]

Public Class Methods

new(pfile) click to toggle source
# File lib/ra10ke/dependencies.rb, line 34
def initialize(pfile)
  @puppetfile = pfile
  # semver is the default version format.

  puppetfile.load!
end
register_version_format(name, &block) click to toggle source

Registers a block that finds the latest version. The block will be called with a list of tags. If the block returns nil the next format will be tried.

# File lib/ra10ke/dependencies.rb, line 19
def self.register_version_format(name, &block)
  version_formats[name] = block
end
version_formats() click to toggle source
# File lib/ra10ke/dependencies.rb, line 12
def self.version_formats
  @version_formats ||= {}
end

Public Instance Methods

get_latest_ref(remote_refs) click to toggle source
# File lib/ra10ke/dependencies.rb, line 41
def get_latest_ref(remote_refs)
  tags = remote_refs['tags'].keys
  latest_ref = nil
  self.class.version_formats.detect { |_, block| latest_ref = block.call(tags) }
  latest_ref = 'undef (tags do not follow any known pattern)' if latest_ref.nil?
  latest_ref
end
ignored_modules() click to toggle source
# File lib/ra10ke/dependencies.rb, line 49
def ignored_modules
  # ignore file allows for "don't tell me about this"
  @ignored_modules ||= begin
    File.readlines('.r10kignore').each { |l| l.chomp! } if File.exist?('.r10kignore')
  end || []
end
outdated(_supplied_puppetfile = puppetfile) click to toggle source
# File lib/ra10ke/dependencies.rb, line 128
def outdated(_supplied_puppetfile = puppetfile)
  processed_modules.find_all do |mod|
    mod[:message] == :outdated
  end
end
print_table(mods) click to toggle source
processed_modules(supplied_puppetfile = puppetfile) click to toggle source

@summary creates an array of module hashes with version info @param {Object} supplied_puppetfile - the parsed puppetfile object @returns {Array} array of version info for each module @note does not include ignored modules or modules up2date

# File lib/ra10ke/dependencies.rb, line 60
def processed_modules(supplied_puppetfile = puppetfile)
  threads = []
  threads = supplied_puppetfile.modules.map do |puppet_module|
    Thread.new do
      next if ignored_modules.include? puppet_module.title

      if puppet_module.instance_of?(::R10K::Module::Forge)
        module_name = puppet_module.title.tr('/', '-')
        forge_version = ::PuppetForge::Module.find(module_name).current_release.version
        installed_version = puppet_module.expected_version
        {
          name: puppet_module.title,
          installed: installed_version,
          latest: forge_version,
          type: 'forge',
          message: (installed_version == forge_version) ? :current : :outdated,
        }

      elsif puppet_module.instance_of?(R10K::Module::Git)
        # use helper; avoid `desired_ref`
        # we do not want to deal with `:control_branch`
        ref = puppet_module.version
        next unless ref

        remote = puppet_module.instance_variable_get(:@remote)
        remote_refs = Git.ls_remote(remote)

        # skip if ref is a branch
        next if remote_refs['branches'].key?(ref)

        if remote_refs['tags'].key?(ref)
          # there are too many possible versioning conventions
          # we have to be be opinionated here
          # so semantic versioning (vX.Y.Z) it is for us
          # as well as support for skipping the leading v letter
          #
          # register own version formats with
          # Ra10ke::Dependencies.register_version_format(:name, &block)
          latest_ref = get_latest_ref(remote_refs)
        elsif /^[a-z0-9]{40}$/.match?(ref)
          ref = ref.slice(0, 8)
          # for sha just assume head should be tracked
          latest_ref = remote_refs['head'][:sha].slice(0, 8)
        else
          raise "Unable to determine ref type for #{puppet_module.title}"
        end
        {
          name: puppet_module.title,
          installed: ref,
          latest: latest_ref,
          type: 'git',
          message: (ref == latest_ref) ? :current : :outdated,
        }

      end
    rescue R10K::Util::Subprocess::SubprocessError => e
      {
        name: puppet_module.title,
        installed: nil,
        latest: nil,
        type: :error,
        message: e.message,
      }
    end
  end
  threads.map { |th| th.join.value }.compact
end