Skip to content

Commit

Permalink
Allow the use of librarian puppet without a forge
Browse files Browse the repository at this point in the history
This update adds support for using librarian puppet without a forge.

Setting the LIBRARIAN_PUPPET_USE_FORGE binary option in one of the
configuration files will prevent the utility from reaching out to a
forge for dependency resolution.

Fixes rodjek#325
  • Loading branch information
trevor-vaughan committed Dec 16, 2015
1 parent 7705d66 commit df85a34
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
5 changes: 5 additions & 0 deletions lib/librarian/puppet/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def init
option "destructive", :type => :boolean, :default => false
option "local", :type => :boolean, :default => false
option "use-v1-api", :type => :boolean, :default => true
option "use-forge", :type => :boolean
def install

ensure!
Expand All @@ -63,6 +64,9 @@ def install
end

environment.config_db.local['use-v1-api'] = options['use-v1-api'] ? '1' : nil
unless options["use-forge"].nil?
environment.config_db.local['use-forge'] = options['use-forge'].to_s
end
environment.config_db.local['mode'] = options['local'] ? 'local' : nil

resolve!
Expand All @@ -84,6 +88,7 @@ def update(*names)
option "strip-dot-git", :type => :boolean
option "path", :type => :string
option "destructive", :type => :boolean, :default => false
option "use-forge", :type => :boolean
def package
environment.vendor!
install
Expand Down
4 changes: 4 additions & 0 deletions lib/librarian/puppet/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ def local?
def use_v1_api
config_db['use-v1-api']
end

def use_forge
config_db['use-forge'].to_s == 'false' ? false : true
end
end
end
end
28 changes: 21 additions & 7 deletions lib/librarian/puppet/source/local.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,23 @@ def install!(manifest)

name, version = manifest.name, manifest.version
found_path = found_path(name)
raise Error, "Path for #{name} doesn't contain a puppet module" if found_path.nil?

unless name.include? '/' or name.include? '-'
warn { "Invalid module name '#{name}', you should qualify it with 'ORGANIZATION-#{name}' for resolution to work correctly" }
# We only care about this if we're fetching from a Forge
if found_path || self.is_a?(Librarian::Puppet::Source::Forge)
raise Error, "Path for #{name} doesn't contain a puppet module" if found_path.nil?

unless name.include? '/' or name.include? '-'
warn { "Invalid module name '#{name}', you should qualify it with 'ORGANIZATION-#{name}' for resolution to work correctly" }
end

install_path = environment.install_path.join(module_name(name))
elsif !repository_cached
raise Error, "Could not find cached version of #{name} for installation"
else
found_path = repository_cache_path
install_path = environment.project_path + path.to_s
end

install_path = environment.install_path.join(module_name(name))
if install_path.exist? && rsync? != true
debug { "Deleting #{relative_path_to(install_path)}" }
install_path.rmtree
Expand All @@ -43,9 +53,13 @@ def fetch_dependencies(name, version, extra)
end

parsed_metadata['dependencies'].each do |d|
gem_requirement = Librarian::Dependency::Requirement.new(d['version_requirement']).to_gem_requirement
new_dependency = Dependency.new(d['name'], gem_requirement, forge_source)
dependencies << new_dependency
if environment.use_forge
gem_requirement = Librarian::Dependency::Requirement.new(d['version_requirement']).to_gem_requirement
new_dependency = Dependency.new(d['name'], gem_requirement, forge_source)
dependencies << new_dependency
end

dependencies
end

dependencies
Expand Down

0 comments on commit df85a34

Please sign in to comment.