librarian-puppet 2.1.1 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 004c9886df1b5f4d003a64f076c2e66bfa349fc4
4
- data.tar.gz: a473d2c6cf25a3eb249e24bc6615ab270598fd50
2
+ SHA256:
3
+ metadata.gz: c107d21c979b589b05492945c89c16c14c4dc2655b63e347ee8048d47e66a259
4
+ data.tar.gz: 60f587d482976725bd421e2617dad882a77e8d1d6fbb7c435be355b6e8d4a7d1
5
5
  SHA512:
6
- metadata.gz: 3103eb328eeffd401c6cfe890b44f2a59b211b67d99f01c10371460f152e8e0149f362b909d136b918c664e52be950cf3c2147729739a759d5ed660f4a223a83
7
- data.tar.gz: aa66afd24a2b72e50a8690ab20ec5828f95e3eba3b4866b6501b32eaf9c37909317482385607982bf9eb1c9f7547f82c769c67099315177c5c88034c2d08c840
6
+ metadata.gz: d1826a56a163a23e8b050662cea03f531158fdb682301017d5aef9aa9e0f89fc3f91d4d139dca74f35b959d9cb06663f1a0cc5ae7891857addc64255adf17073
7
+ data.tar.gz: b3dd541186ac0c1fa7de5cb175eaa146d1a8d391a2697bab3b0f09cbdb1cdb71157c16d13dc6052f149782ff7405877dd03f834ecffebdaebdd14dd3d70956e1
data/.gitignore CHANGED
@@ -2,3 +2,4 @@ pkg/
2
2
  Gemfile.lock
3
3
  tmp/
4
4
  coverage/
5
+ *.gem
data/README.md CHANGED
@@ -1,16 +1,16 @@
1
1
  # Librarian-puppet
2
2
 
3
- [![Build Status](https://travis-ci.org/rodjek/librarian-puppet.png?branch=master)](https://travis-ci.org/rodjek/librarian-puppet)
3
+ [![Build Status](https://travis-ci.org/voxpupuli/librarian-puppet.png?branch=master)](https://travis-ci.org/voxpupuli/librarian-puppet)
4
4
 
5
5
  ## Introduction
6
6
 
7
7
  Librarian-puppet is a bundler for your puppet infrastructure. You can use
8
8
  librarian-puppet to manage the puppet modules your infrastructure depends on,
9
- whether the modules come from the [Puppet Forge](https://forge.puppetlabs.com/),
9
+ whether the modules come from the [Puppet Forge](https://forge.puppet.com/),
10
10
  Git repositories or just a path.
11
11
 
12
12
  * Librarian-puppet can reuse the dependencies listed in your `Modulefile` or `metadata.json`
13
- * Forge modules can be installed from [Puppetlabs Forge](https://forge.puppetlabs.com/) or an internal Forge such as [Pulp](http://www.pulpproject.org/)
13
+ * Forge modules can be installed from [Puppetlabs Forge](https://forge.puppet.com/) or an internal Forge such as [Pulp](http://www.pulpproject.org/)
14
14
  * Git modules can be installed from a branch, tag or specific commit, optionally using a path inside the repository
15
15
  * Modules can be installed from GitHub using tarballs, without needing Git installed
16
16
  * Modules can be installed from a filesystem path
@@ -31,8 +31,9 @@ and isolate a project's dependencies.
31
31
 
32
32
  ## Versions
33
33
 
34
- Librarian-puppet >= 2.0 (as well as 1.1, 1.2 and 1.3) requires Ruby 1.9 and uses the Puppet Forge API v3.
35
- Versions < 2.0 work on Ruby 1.8.
34
+ Librarian-Puppet 3.0.0 and newer requires Ruby >= 2.0. Use version 2.2.4 if you need support for Puppet 3.7 or earlier, or Ruby 1.9 or earlier. Note that [Puppet 4.10 and newer require Ruby 2.1](https://puppet.com/docs/puppet/4.10/system_requirements.html#prerequisites) or newer.
35
+
36
+ Librarian-Puppet 2.0.0 and newer requires Ruby >= 1.9 and uses Puppet Forge API v3. For Ruby 1.8 use 1.5.0.
36
37
 
37
38
  See the [Changelog](Changelog.md) for more details.
38
39
 
@@ -129,6 +130,11 @@ This includes any branch name, tag name, SHA, or SHA unique prefix. If we use a
129
130
  branch, we can later ask Librarian-puppet to update the module by fetching the
130
131
  most recent version of the module from that same branch.
131
132
 
133
+ Note that Librarian-puppet recognizes the [r10k Puppetfile's](https://github.com/puppetlabs/r10k/blob/master/doc/puppetfile.mkd) additional
134
+ options, `:tag`, `:commit`, and `:branch`, but only as aliases for `:ref`.
135
+ That is, there is no implementation of r10k's optimizations around fetching
136
+ these different types of git objects.
137
+
132
138
  The Git source also supports a `:path =>` option. If we use the path option,
133
139
  Librarian-puppet will navigate down into the Git repository and only use the
134
140
  specified subdirectory. Some people have the habit of having a single repository
@@ -321,5 +327,5 @@ Please include:
321
327
 
322
328
 
323
329
  ## License
324
- Please see the [LICENSE](https://github.com/rodjek/librarian-puppet/blob/master/LICENSE)
330
+ Please see the [LICENSE](https://github.com/voxpupuli/librarian-puppet/blob/master/LICENSE)
325
331
  file.
@@ -1,4 +1,5 @@
1
1
  require 'librarian/action/resolve'
2
+ require 'librarian/puppet/resolver'
2
3
 
3
4
  module Librarian
4
5
  module Puppet
@@ -15,6 +16,10 @@ module Librarian
15
16
  end
16
17
  end
17
18
 
19
+ def resolver
20
+ Resolver.new(environment)
21
+ end
22
+
18
23
  end
19
24
  end
20
25
  end
@@ -5,13 +5,21 @@ module Librarian
5
5
 
6
6
  include Librarian::Puppet::Util
7
7
 
8
- def initialize(name, requirement, source)
8
+ attr_accessor :parent
9
+ private :parent=
10
+
11
+ def initialize(name, requirement, source, parent = nil)
9
12
  # Issue #235 fail if forge source is not defined
10
13
  raise Error, "forge entry is not defined in Puppetfile" if source.instance_of?(Array) && source.empty?
11
14
 
15
+ self.parent = parent
12
16
  super(normalize_name(name), requirement, source)
13
17
  end
14
18
 
19
+ def to_s
20
+ "#{name} (#{requirement}) <#{source}> (from #{parent.nil? ? '<nil>' : parent})"
21
+ end
22
+
15
23
  end
16
24
 
17
25
  end
@@ -37,6 +37,37 @@ module Librarian
37
37
  Receiver.new(target)
38
38
  end
39
39
 
40
+ def run(specfile = nil, sources = [])
41
+ specfile, sources = nil, specfile if specfile.kind_of?(Array) && sources.empty?
42
+
43
+ Target.new(self).tap do |target|
44
+ target.precache_sources(sources)
45
+ debug_named_source_cache("Pre-Cached Sources", target)
46
+
47
+ specfile ||= Proc.new if block_given?
48
+
49
+ if specfile.kind_of?(Pathname) and !File.exists?(specfile)
50
+ debug { "Specfile #{specfile} not found, using defaults" } unless specfile.nil?
51
+ receiver(target).run(specfile, &default_specfile)
52
+ else
53
+ receiver(target).run(specfile)
54
+ end
55
+
56
+ post_process_target(target)
57
+
58
+ debug_named_source_cache("Post-Cached Sources", target)
59
+ end.to_spec
60
+ end
61
+
62
+ class Target < Librarian::Dsl::Target
63
+ def dependency(name, *args)
64
+ options = args.last.is_a?(Hash) ? args.pop : {}
65
+ source = source_from_options(options) || @source
66
+ dep = dependency_type.new(name, args, source, 'Puppetfile')
67
+ @dependencies << dep
68
+ end
69
+ end
70
+
40
71
  class Receiver < Librarian::Dsl::Receiver
41
72
  attr_reader :specfile, :working_path
42
73
 
@@ -25,7 +25,46 @@ module Librarian
25
25
  alias_method :old_lookup, :[]
26
26
  define_method(:[]) { |k| self.old_lookup(normalize_name(k)) }
27
27
  end
28
- super(lines, manifests_index)
28
+ dependencies = []
29
+ while lines.first =~ /^ {2}([\w\-\/]+)(?: \((.*)\))?$/
30
+ lines.shift
31
+ name, requirement = $1, $2.split(/,\s*/)
32
+ dependencies << environment.dsl_class.dependency_type.new(name, requirement, manifests_index[name].source, 'lockfile')
33
+ end
34
+ dependencies
35
+ end
36
+
37
+ def compile_placeholder_manifests(sources_ast)
38
+ manifests = {}
39
+ sources_ast.each do |source_ast|
40
+ source_type = source_ast[:type]
41
+ source = source_type.from_lock_options(environment, source_ast[:options])
42
+ source_ast[:manifests].each do |manifest_name, manifest_ast|
43
+ manifests[manifest_name] = ManifestPlaceholder.new(
44
+ source,
45
+ manifest_name,
46
+ manifest_ast[:version],
47
+ manifest_ast[:dependencies].map do |k, v|
48
+ environment.dsl_class.dependency_type.new(k, v, nil, manifest_name)
49
+ end
50
+ )
51
+ end
52
+ end
53
+ manifests
54
+ end
55
+
56
+ def compile(sources_ast)
57
+ manifests = compile_placeholder_manifests(sources_ast)
58
+ manifests = manifests.map do |name, manifest|
59
+ dependencies = manifest.dependencies.map do |d|
60
+ environment.dsl_class.dependency_type.new(d.name, d.requirement, manifests[d.name].source, name)
61
+ end
62
+ real = Manifest.new(manifest.source, manifest.name)
63
+ real.version = manifest.version
64
+ real.dependencies = manifest.dependencies
65
+ real
66
+ end
67
+ ManifestSet.sort(manifests)
29
68
  end
30
69
 
31
70
  end
@@ -0,0 +1,21 @@
1
+ require 'librarian/resolver'
2
+
3
+ module Librarian
4
+ module Puppet
5
+ class Resolver < Librarian::Resolver
6
+
7
+ class Implementation < Librarian::Resolver::Implementation
8
+ def sourced_dependency_for(dependency)
9
+ return dependency if dependency.source
10
+
11
+ source = dependency_source_map[dependency.name] || default_source
12
+ dependency.class.new(dependency.name, dependency.requirement, source, dependency.parent)
13
+ end
14
+ end
15
+
16
+ def implementation(spec)
17
+ Implementation.new(self, spec, :cyclic => cyclic)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -144,7 +144,7 @@ module Librarian
144
144
  def fetch_dependencies(name, version, version_uri)
145
145
  repo(name).dependencies(version).map do |k, v|
146
146
  v = Librarian::Dependency::Requirement.new(v).to_gem_requirement
147
- Dependency.new(k, v, nil)
147
+ Dependency.new(k, v, nil, name)
148
148
  end
149
149
  end
150
150
 
@@ -158,7 +158,8 @@ module Librarian
158
158
  @repo ||= {}
159
159
 
160
160
  unless @repo[name]
161
- # if we are using the official Forge then use API v3, otherwise stick to v1 for now
161
+ # If we are using the official Forge then use API v3, otherwise use the preferred api
162
+ # as defined by the CLI option use_v1_api
162
163
  if uri.hostname =~ /\.puppetlabs\.com$/ || !environment.use_v1_api
163
164
  @repo[name] = RepoV3.new(self, name)
164
165
  else
@@ -87,7 +87,7 @@ module Librarian
87
87
  target = vendored?(name, version) ? vendored_path(name, version).to_s : name
88
88
 
89
89
  # can't pass the default v3 forge url (http://forgeapi.puppetlabs.com)
90
- # to clients that use the v1 API (https://forge.puppetlabs.com)
90
+ # to clients that use the v1 API (https://forge.puppet.com)
91
91
  # nor the other way around
92
92
  module_repository = source.to_s
93
93
 
@@ -145,7 +145,7 @@ module Librarian
145
145
  debug { "Downloading #{url} into #{path}"}
146
146
  environment.vendor!
147
147
  File.open(path, 'wb') do |f|
148
- open(url, "rb") do |input|
148
+ URI.open(url, 'rb') do |input|
149
149
  f.write(input.read)
150
150
  end
151
151
  end
@@ -11,10 +11,10 @@ module Librarian
11
11
  def initialize(source, name)
12
12
  super(source, name)
13
13
  # API returned data for this module including all versions and dependencies, indexed by module name
14
- # from http://forge.puppetlabs.com/api/v1/releases.json?module=#{name}
14
+ # from https://forge.puppetlabs.com/api/v1/releases.json?module=#{name}
15
15
  @api_data = nil
16
16
  # API returned data for this module and a specific version, indexed by version
17
- # from http://forge.puppetlabs.com/api/v1/releases.json?module=#{name}&version=#{version}
17
+ # from https://forge.puppetlabs.com/api/v1/releases.json?module=#{name}&version=#{version}
18
18
  @api_version_data = {}
19
19
  end
20
20
 
@@ -74,7 +74,7 @@ module Librarian
74
74
  debug { "Querying Forge API for module #{name}#{" and version #{version}" unless version.nil?}: #{url}" }
75
75
 
76
76
  begin
77
- data = open(url) {|f| f.read}
77
+ data = URI.open(url) {|f| f.read}
78
78
  JSON.parse(data)
79
79
  rescue OpenURI::HTTPError => e
80
80
  case e.io.status[0].to_i
@@ -16,11 +16,11 @@ module Librarian
16
16
  end
17
17
 
18
18
  def get_versions
19
- get_module.releases.map{|r| r.version}
19
+ get_module.releases.select{|r| r.deleted_at.nil?}.map{|r| r.version}
20
20
  end
21
21
 
22
22
  def dependencies(version)
23
- array = get_release(version).metadata[:dependencies].map{|d| [d['name'], d['version_requirement']]}
23
+ array = get_release(version).metadata[:dependencies].map{|d| [d[:name], d[:version_requirement]]}
24
24
  Hash[*array.flatten(1)]
25
25
  end
26
26
 
@@ -30,7 +30,7 @@ module Librarian
30
30
  else
31
31
  # should never get here as we use one repo object for each module (to be changed in the future)
32
32
  debug { "Looking up url for #{name}@#{version}" }
33
- release = PuppetForge::Release.find("#{name}-#{version}")
33
+ release = PuppetForge::V3::Release.find("#{name}-#{version}")
34
34
  end
35
35
  "#{source}#{release.file_uri}"
36
36
  end
@@ -38,8 +38,11 @@ module Librarian
38
38
  private
39
39
 
40
40
  def get_module
41
- @module ||= PuppetForge::Module.find(name)
42
- raise(Error, "Unable to find module '#{name}' on #{source}") unless @module
41
+ begin
42
+ @module ||= PuppetForge::V3::Module.find(name)
43
+ rescue Faraday::ResourceNotFound => e
44
+ raise(Error, "Unable to find module '#{name}' on #{source}")
45
+ end
43
46
  @module
44
47
  end
45
48
 
@@ -77,7 +77,7 @@ module Librarian
77
77
  File.open(vendored_path(vendored_name(name), version).to_s, 'wb') do |f|
78
78
  begin
79
79
  debug { "Downloading <#{url}> to <#{f.path}>" }
80
- open(url,
80
+ URI.open(url,
81
81
  "User-Agent" => "librarian-puppet v#{Librarian::Puppet::VERSION}") do |res|
82
82
  while buffer = res.read(8192)
83
83
  f.write(buffer)
@@ -44,7 +44,7 @@ module Librarian
44
44
 
45
45
  parsed_metadata['dependencies'].each do |d|
46
46
  gem_requirement = Librarian::Dependency::Requirement.new(d['version_requirement']).to_gem_requirement
47
- new_dependency = Dependency.new(d['name'], gem_requirement, forge_source)
47
+ new_dependency = Dependency.new(d['name'], gem_requirement, forge_source, name)
48
48
  dependencies << new_dependency
49
49
  end
50
50
 
@@ -85,6 +85,13 @@ module Librarian
85
85
  @@require_puppet ||= require_puppet
86
86
 
87
87
  metadata = ::Puppet::ModuleTool::Metadata.new
88
+
89
+ # Puppet 4 does not have the class
90
+ unless defined? ::Puppet::ModuleTool::ModulefileReader
91
+ warn { "Can't parse Modulefile in Puppet >= 4.0 and you are using #{Librarian::Puppet::puppet_version}. Ignoring dependencies in #{modulefile}" }
92
+ return metadata
93
+ end
94
+
88
95
  begin
89
96
  ::Puppet::ModuleTool::ModulefileReader.evaluate(metadata, modulefile)
90
97
  raise SyntaxError, "Missing version" unless metadata.version
@@ -26,7 +26,21 @@ module Librarian
26
26
  # If the rsync configuration parameter is set, use rsync instead of FileUtils
27
27
  def cp_r(src, dest)
28
28
  if rsync?
29
- Rsync.run(File.join(src, "/"), dest, ['-avz', '--delete'])
29
+ if Gem.win_platform?
30
+ src_clean = "#{src}".gsub(/^([a-z])\:/i,'/cygdrive/\1')
31
+ dest_clean = "#{dest}".gsub(/^([a-z])\:/i,'/cygdrive/\1')
32
+ else
33
+ src_clean = src
34
+ dest_clean = dest
35
+ end
36
+ debug { "Copying #{src_clean}/ to #{dest_clean}/ with rsync -avz --delete" }
37
+ result = Rsync.run(File.join(src_clean, "/"), File.join(dest_clean, "/"), ['-avz', '--delete'])
38
+ if result.success?
39
+ debug { "Rsync from #{src_clean}/ to #{dest_clean}/ successfull" }
40
+ else
41
+ msg = "Failed to rsync from #{src_clean}/ to #{dest_clean}/: " + result.error
42
+ raise Error, msg
43
+ end
30
44
  else
31
45
  begin
32
46
  FileUtils.cp_r(src, dest, :preserve => true)
@@ -1,5 +1,5 @@
1
1
  module Librarian
2
2
  module Puppet
3
- VERSION = "2.1.1"
3
+ VERSION = "3.0.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: librarian-puppet
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Sharpe
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-05-22 00:00:00.000000000 Z
12
+ date: 2021-04-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: librarianp
@@ -45,14 +45,14 @@ dependencies:
45
45
  requirements:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '1.0'
48
+ version: '2.1'
49
49
  type: :runtime
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: '1.0'
55
+ version: '2.1'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: rake
58
58
  requirement: !ruby/object:Gem::Requirement
@@ -85,44 +85,44 @@ dependencies:
85
85
  name: cucumber
86
86
  requirement: !ruby/object:Gem::Requirement
87
87
  requirements:
88
- - - ">="
88
+ - - "<"
89
89
  - !ruby/object:Gem::Version
90
- version: '0'
90
+ version: 3.0.0
91
91
  type: :development
92
92
  prerelease: false
93
93
  version_requirements: !ruby/object:Gem::Requirement
94
94
  requirements:
95
- - - ">="
95
+ - - "<"
96
96
  - !ruby/object:Gem::Version
97
- version: '0'
97
+ version: 3.0.0
98
98
  - !ruby/object:Gem::Dependency
99
99
  name: aruba
100
100
  requirement: !ruby/object:Gem::Requirement
101
101
  requirements:
102
- - - ">="
102
+ - - "<"
103
103
  - !ruby/object:Gem::Version
104
- version: '0'
104
+ version: 0.8.0
105
105
  type: :development
106
106
  prerelease: false
107
107
  version_requirements: !ruby/object:Gem::Requirement
108
108
  requirements:
109
- - - ">="
109
+ - - "<"
110
110
  - !ruby/object:Gem::Version
111
- version: '0'
111
+ version: 0.8.0
112
112
  - !ruby/object:Gem::Dependency
113
113
  name: puppet
114
114
  requirement: !ruby/object:Gem::Requirement
115
115
  requirements:
116
- - - ">="
116
+ - - "~>"
117
117
  - !ruby/object:Gem::Version
118
- version: '0'
118
+ version: 5.3.0
119
119
  type: :development
120
120
  prerelease: false
121
121
  version_requirements: !ruby/object:Gem::Requirement
122
122
  requirements:
123
- - - ">="
123
+ - - "~>"
124
124
  - !ruby/object:Gem::Version
125
- version: '0'
125
+ version: 5.3.0
126
126
  - !ruby/object:Gem::Dependency
127
127
  name: minitest
128
128
  requirement: !ruby/object:Gem::Requirement
@@ -191,6 +191,7 @@ files:
191
191
  - lib/librarian/puppet/environment.rb
192
192
  - lib/librarian/puppet/extension.rb
193
193
  - lib/librarian/puppet/lockfile.rb
194
+ - lib/librarian/puppet/resolver.rb
194
195
  - lib/librarian/puppet/source.rb
195
196
  - lib/librarian/puppet/source/forge.rb
196
197
  - lib/librarian/puppet/source/forge/repo.rb
@@ -205,7 +206,7 @@ files:
205
206
  - lib/librarian/puppet/templates/Puppetfile
206
207
  - lib/librarian/puppet/util.rb
207
208
  - lib/librarian/puppet/version.rb
208
- homepage: https://github.com/rodjek/librarian-puppet
209
+ homepage: https://github.com/voxpupuli/librarian-puppet
209
210
  licenses:
210
211
  - MIT
211
212
  metadata: {}
@@ -217,15 +218,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
217
218
  requirements:
218
219
  - - ">="
219
220
  - !ruby/object:Gem::Version
220
- version: 1.9.0
221
+ version: 2.0.0
221
222
  required_rubygems_version: !ruby/object:Gem::Requirement
222
223
  requirements:
223
224
  - - ">="
224
225
  - !ruby/object:Gem::Version
225
226
  version: '0'
226
227
  requirements: []
227
- rubyforge_project:
228
- rubygems_version: 2.4.6
228
+ rubygems_version: 3.0.8
229
229
  signing_key:
230
230
  specification_version: 4
231
231
  summary: Bundler for your Puppet modules