librarian-puppet-maestrodev 0.9.10.1 → 0.9.11.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,12 +1,11 @@
1
1
  # Librarian-puppet
2
2
 
3
- ## Note
3
+ [![Build Status](https://travis-ci.org/maestrodev/librarian-puppet.png?branch=maestrodev)](https://travis-ci.org/maestrodev/librarian-puppet)
4
4
 
5
- This is a fork of [rodjek librarian-puppet](https://github.com/rodjek/librarian-puppet) with
6
- a bunch of fixes submitted as pull requests there.
7
- It is published to rubygems as [librarian-puppet-maestrodev](https://rubygems.org/gems/librarian-puppet-maestrodev)
8
- so you can easily try it.
5
+ ## Note
9
6
 
7
+ This is a fork of [rodjek librarian-puppet](https://github.com/rodjek/librarian-puppet) to publish to rubygems
8
+ [librarian-puppet-maestrodev](https://rubygems.org/gems/librarian-puppet-maestrodev)
10
9
 
11
10
  ## Introduction
12
11
 
@@ -30,6 +29,15 @@ Every Puppet repository that uses Librarian-puppet will have a file named
30
29
  `Puppetfile` in the root directory of that repository. The full specification
31
30
  for which modules your puppet infrastructure repository depends goes in here.
32
31
 
32
+ ### Simple Puppetfile
33
+
34
+ This Puppetfile will download all the dependencies listed in your Modulefile from the Puppet Forge
35
+
36
+ forge "http://forge.puppetlabs.com"
37
+
38
+ modulefile
39
+
40
+
33
41
  ### Example Puppetfile
34
42
 
35
43
  forge "http://forge.puppetlabs.com"
@@ -45,6 +45,12 @@ module Librarian
45
45
  option "destructive", :type => :boolean, :default => false
46
46
  option "local", :type => :boolean, :default => false
47
47
  def install
48
+
49
+ unless File.exist?('Puppetfile')
50
+ say "Could not find Puppetfile in #{Dir.pwd}", :red
51
+ exit 1
52
+ end
53
+
48
54
  ensure!
49
55
  clean! if options["clean"]
50
56
  unless options["destructive"].nil?
@@ -14,3 +14,16 @@ module Librarian
14
14
  end
15
15
  end
16
16
  end
17
+
18
+ module Librarian
19
+ class Dsl
20
+ class Receiver
21
+ def modulefile
22
+ File.read('Modulefile').lines.each do |line|
23
+ regexp = /\s*dependency\s+('|")([^'"]+)\1\s*(?:,\s*('|")([^'"]+)\3)?/
24
+ regexp =~ line && mod($2, $4)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -216,4 +216,186 @@ module Librarian
216
216
  end
217
217
  end
218
218
 
219
+ # Fixes for librarian not yet released in their gem
220
+ module Mock
221
+ module Source
222
+ class Mock
223
+ alias :eql? :==
224
+
225
+ def hash
226
+ self.to_s.hash
227
+ end
228
+ end
229
+ end
230
+ end
231
+ module Source
232
+ class Git
233
+ alias :eql? :==
234
+
235
+ def hash
236
+ self.to_s.hash
237
+ end
238
+ end
239
+
240
+ class Path
241
+ alias :eql? :==
242
+
243
+ def hash
244
+ self.to_s.hash
245
+ end
246
+ end
247
+ end
248
+
249
+
250
+ module Action
251
+ class Install < Base
252
+
253
+ private
254
+
255
+ def create_install_path
256
+ install_path.rmtree if install_path.exist? && destructive?
257
+ install_path.mkpath
258
+ end
259
+
260
+ def destructive?
261
+ environment.config_db.local['destructive'] == 'true'
262
+ end
263
+ end
264
+ end
265
+
266
+ class ManifestSet
267
+ private
268
+
269
+ # Check if module doesn't exist and fail fast
270
+ def dependencies_of(names)
271
+ names = Array === names ? names.dup : names.to_a
272
+ assert_strings!(names)
273
+
274
+ deps = Set.new
275
+ until names.empty?
276
+ name = names.shift
277
+ next if deps.include?(name)
278
+
279
+ deps << name
280
+ raise(Error, "Unable to find module #{name}") if index[name].nil?
281
+ names.concat index[name].dependencies.map(&:name)
282
+ end
283
+ deps.to_a
284
+ end
285
+ end
286
+
287
+ class Manifest
288
+
289
+ class PreReleaseVersion
290
+
291
+ # Compares pre-release component ids using Semver 2.0.0 spec
292
+ def self.compare_components(this_id,other_id)
293
+ case # Strings have higher precedence than numbers
294
+ when (this_id.is_a?(Integer) and other_id.is_a?(String))
295
+ -1
296
+ when (this_id.is_a?(String) and other_id.is_a?(Integer))
297
+ 1
298
+ else
299
+ this_id <=> other_id
300
+ end
301
+ end
302
+
303
+ # Parses pre-release components `a.b.c` into an array ``[a,b,c]`
304
+ # Converts numeric components into +Integer+
305
+ def self.parse(prerelease)
306
+ if prerelease.nil?
307
+ []
308
+ else
309
+ prerelease.split('.').collect do |id|
310
+ id = Integer(id) if /^[0-9]+$/ =~ id
311
+ id
312
+ end
313
+ end
314
+ end
315
+
316
+ include Comparable
317
+
318
+ attr_reader :components
319
+
320
+ def initialize(prerelease)
321
+ @prerelease = prerelease
322
+ @components = PreReleaseVersion.parse(prerelease)
323
+ end
324
+
325
+ def to_s
326
+ @prerelease
327
+ end
328
+
329
+ def <=>(other)
330
+ # null-fill zip array to prevent loss of components
331
+ z = Array.new([components.length,other.components.length])
332
+
333
+ # Compare each component against the other
334
+ comp = z.zip(components,other.components).collect do |ids|
335
+ case # All components being equal, the version with more of them takes precedence
336
+ when ids[1].nil? # Self has less elements, other wins
337
+ -1
338
+ when ids[2].nil? # Other has less elements, self wins
339
+ 1
340
+ else
341
+ PreReleaseVersion.compare_components(ids[1],ids[2])
342
+ end
343
+ end
344
+ # Chose the first non-zero comparison or return 0
345
+ comp.delete_if {|c| c == 0}[0] || 0
346
+ end
347
+ end
348
+ class Version
349
+ @@SEMANTIC_VERSION_PATTERN = /^([0-9]+\.[0-9]+(?:\.[0-9]+)?)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$/
350
+ def self.parse_semver(version_string)
351
+ parsed = @@SEMANTIC_VERSION_PATTERN.match(version_string.strip)
352
+ if parsed
353
+ {
354
+ :full_version => parsed[0],
355
+ :version => parsed[1],
356
+ :prerelease => (PreReleaseVersion.new(parsed[2]) if parsed[2]),
357
+ :build => parsed[3]
358
+ }
359
+ end
360
+ end
361
+
362
+ attr_reader :prerelease
363
+
364
+ def initialize(*args)
365
+ args = initialize_normalize_args(args)
366
+ semver = Version.parse_semver(*args)
367
+ if semver
368
+ self.backing = Gem::Version.new(semver[:version])
369
+ @prerelease = semver[:prerelease]
370
+ @full_version = semver[:full_version]
371
+ else
372
+ self.backing = Gem::Version.new(*args)
373
+ @full_version = to_gem_version.to_s
374
+ end
375
+ end
376
+
377
+ def <=>(other)
378
+ cmp = to_gem_version <=> other.to_gem_version
379
+
380
+ # Should compare pre-release versions?
381
+ if cmp == 0 and not (prerelease.nil? and other.prerelease.nil?)
382
+ case # Versions without prerelease take precedence
383
+ when (prerelease.nil? and not other.prerelease.nil?)
384
+ 1
385
+ when (not prerelease.nil? and other.prerelease.nil?)
386
+ -1
387
+ else
388
+ prerelease <=> other.prerelease
389
+ end
390
+ else
391
+ cmp
392
+ end
393
+ end
394
+
395
+ def to_s
396
+ @full_version
397
+ end
398
+ end
399
+ end
400
+
219
401
  end
@@ -4,7 +4,7 @@ module Librarian
4
4
  attr_reader :requirement
5
5
 
6
6
  def initialize(requirement)
7
- @requirement = requirement
7
+ @requirement = requirement || ">=0"
8
8
  end
9
9
 
10
10
  # convert Puppet versions to gem supported versions
@@ -18,10 +18,8 @@ module Librarian
18
18
 
19
19
  def versions
20
20
  return @versions if @versions
21
- versions = api_data[name].map { |r| r['version'] }.reverse
22
- debug { " Module #{name} found versions: #{versions.join(", ")}" }
23
- versions.select { |v| ! Gem::Version.correct? v }.each { |v| debug { "Ignoring invalid version '#{v}' for module #{name}" } }
24
- @versions = versions.select { |v| Gem::Version.correct? v }
21
+ @versions = api_data[name].map { |r| r['version'] }.reverse
22
+ debug { " Module #{name} found versions: #{@versions.join(", ")}" }
25
23
  @versions
26
24
  end
27
25
 
@@ -104,6 +102,7 @@ module Librarian
104
102
  path.unlink
105
103
  raise Error, "Error executing puppet module install:\n#{command}\nError:\n#{output}"
106
104
  end
105
+
107
106
  end
108
107
 
109
108
  def check_puppet_module_options
@@ -209,11 +208,6 @@ module Librarian
209
208
  self.class == other.class &&
210
209
  self.uri == other.uri
211
210
  end
212
- alias eql? ==
213
-
214
- def hash
215
- self.uri.hash
216
- end
217
211
 
218
212
  alias :eql? :==
219
213
 
@@ -275,14 +269,9 @@ module Librarian
275
269
  end
276
270
 
277
271
  def fetch_dependencies(name, version, version_uri)
278
- environment.logger.debug { " Fetching dependencies for #{name} #{version}" }
279
272
  repo(name).dependencies(version).map do |k, v|
280
- begin
281
- v = Requirement.new(v).gem_requirement
282
- Dependency.new(k, v, nil)
283
- rescue ArgumentError => e
284
- raise Error, "Error fetching dependency for #{name} [#{version}]: #{k} [#{v}]: #{e}"
285
- end
273
+ v = Requirement.new(v).gem_requirement
274
+ Dependency.new(k, v, nil)
286
275
  end
287
276
  end
288
277
 
@@ -14,51 +14,6 @@ module Librarian
14
14
  command = %W(rev-parse #{reference}^{commit} --quiet)
15
15
  run!(command, :chdir => true).strip
16
16
  end
17
-
18
- # Naming this method 'version' causes an exception to be raised.
19
- def module_version
20
- return '0.0.1' unless modulefile?
21
-
22
- metadata = ::Puppet::ModuleTool::Metadata.new
23
- ::Puppet::ModuleTool::ModulefileReader.evaluate(metadata, modulefile)
24
-
25
- metadata.version
26
- end
27
-
28
- def dependencies
29
- return {} unless modulefile? or puppetfile?
30
-
31
- if modulefile?
32
- metadata = ::Puppet::ModuleTool::Metadata.new
33
-
34
- ::Puppet::ModuleTool::ModulefileReader.evaluate(metadata, modulefile)
35
-
36
- metadata.dependencies.map do |dependency|
37
- name = dependency.instance_variable_get(:@full_module_name)
38
- version = dependency.instance_variable_get(:@version_requirement) || ">=0"
39
- v = Librarian::Puppet::Requirement.new(version).gem_requirement
40
- Dependency.new(name, v, forge_source)
41
- end
42
- elsif puppetfile?
43
- Librarian::Puppet::Environment.new(:project_path => path).specfile.read.dependencies
44
- end
45
- end
46
-
47
- def modulefile
48
- File.join(path, 'Modulefile')
49
- end
50
-
51
- def modulefile?
52
- File.exists?(modulefile)
53
- end
54
-
55
- def puppetfile?
56
- File.exists?(File.join(path, 'Puppetfile'))
57
- end
58
-
59
- def forge_source
60
- Librarian::Puppet::Source::Forge.from_lock_options(environment, :remote=>"http://forge.puppetlabs.com")
61
- end
62
17
  end
63
18
  end
64
19
  end
@@ -108,19 +63,52 @@ module Librarian
108
63
  def fetch_version(name, extra)
109
64
  cache!
110
65
  found_path = found_path(name)
111
- v = repository.module_version
112
- v = v.gsub("-",".") # fix for some invalid versions like 1.0.0-rc1
66
+ module_version
67
+ end
113
68
 
114
- # if still not valid, use some default version
115
- unless Gem::Version.correct? v
116
- debug { "Ignoring invalid version '#{v}' for module #{name}, using 0.0.1" }
117
- v = '0.0.1'
69
+ def fetch_dependencies(name, version, extra)
70
+ dependencies.map do |k, v|
71
+ v = Requirement.new(v).gem_requirement
72
+ Dependency.new(k, v, forge_source)
118
73
  end
119
- v
120
74
  end
121
75
 
122
- def fetch_dependencies(name, version, extra)
123
- repository.dependencies
76
+ def forge_source
77
+ Forge.from_lock_options(environment, :remote=>"http://forge.puppetlabs.com")
78
+ end
79
+
80
+ private
81
+
82
+ # Naming this method 'version' causes an exception to be raised.
83
+ def module_version
84
+ return '0.0.1' unless modulefile?
85
+
86
+ metadata = ::Puppet::ModuleTool::Metadata.new
87
+ ::Puppet::ModuleTool::ModulefileReader.evaluate(metadata, modulefile)
88
+
89
+ metadata.version
90
+ end
91
+
92
+ def dependencies
93
+ return {} unless modulefile?
94
+
95
+ metadata = ::Puppet::ModuleTool::Metadata.new
96
+
97
+ ::Puppet::ModuleTool::ModulefileReader.evaluate(metadata, modulefile)
98
+
99
+ metadata.dependencies.inject({}) do |h, dependency|
100
+ name = dependency.instance_variable_get(:@full_module_name)
101
+ version = dependency.instance_variable_get(:@version_requirement)
102
+ h.update(name => version)
103
+ end
104
+ end
105
+
106
+ def modulefile
107
+ File.join(filesystem_path, 'Modulefile')
108
+ end
109
+
110
+ def modulefile?
111
+ File.exists?(modulefile)
124
112
  end
125
113
 
126
114
  end
@@ -9,6 +9,7 @@ module Librarian
9
9
  module Source
10
10
  class GitHubTarball
11
11
  class Repo
12
+ TOKEN_KEY = 'GITHUB_API_TOKEN'
12
13
 
13
14
  attr_accessor :source, :name
14
15
  private :source=, :name=
@@ -24,11 +25,7 @@ module Librarian
24
25
  raise Error, "Unable to find module '#{source.uri}' on https://github.com"
25
26
  end
26
27
 
27
- all_versions = data.map { |r| r['name'] }.sort.reverse
28
-
29
- all_versions = all_versions.map do |version|
30
- version.gsub(/^v/, '')
31
- end
28
+ all_versions = data.map { |r| r['name'].gsub(/^v/, '') }.sort.reverse
32
29
 
33
30
  all_versions.delete_if do |version|
34
31
  version !~ /\A\d\.\d(\.\d.*)?\z/
@@ -114,34 +111,35 @@ module Librarian
114
111
 
115
112
  def api_call(path)
116
113
  url = "https://api.github.com#{path}"
117
- url << "?access_token=#{ENV['GITHUB_API_TOKEN']}" if ENV['GITHUB_API_TOKEN']
118
- uri = URI.parse(url)
119
- http = Net::HTTP.new(uri.host, uri.port)
120
- http.use_ssl = true
121
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
122
- request = Net::HTTP::Get.new(uri.request_uri)
123
-
124
- request.add_field "User-Agent",
125
- "librarian-puppet v#{Librarian::Puppet::VERSION}"
126
-
127
- resp = http.request(request)
128
- data = resp.body
114
+ url << "?access_token=#{ENV[TOKEN_KEY]}" if ENV[TOKEN_KEY]
115
+ code, data = http_get(url, :headers => {
116
+ "User-Agent" => "librarian-puppet v#{Librarian::Puppet::VERSION}"
117
+ })
129
118
 
130
- if resp.code.to_i == 403
119
+ if code == 200
120
+ JSON.parse(data)
121
+ elsif code == 403
131
122
  begin
132
123
  message = JSON.parse(data)['message']
133
- if message.include? 'API rate limit exceeded'
134
- raise Error, message
124
+ if message && message.include?('API rate limit exceeded')
125
+ raise Error, message + " -- increase limit by authenticating via #{TOKEN_KEY}=your-token"
135
126
  end
136
- rescue JSON::ParserError
137
- # 403 response does not return json, skip.
127
+ rescue JSON::ParserError
128
+ # 403 response does not return json, skip.
138
129
  end
139
- elsif resp.code.to_i != 200
140
- nil
141
- else
142
- JSON.parse(data)
143
130
  end
144
131
  end
132
+
133
+ def http_get(url, options)
134
+ uri = URI.parse(url)
135
+ http = Net::HTTP.new(uri.host, uri.port)
136
+ http.use_ssl = true
137
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
138
+ request = Net::HTTP::Get.new(uri.request_uri)
139
+ options[:headers].each { |k, v| request.add_field k, v }
140
+ resp = http.request(request)
141
+ [resp.code.to_i, resp.body]
142
+ end
145
143
  end
146
144
 
147
145
  class << self
@@ -41,7 +41,7 @@ module Librarian
41
41
 
42
42
  def install_perform_step_copy!(found_path, install_path)
43
43
  debug { "Copying #{relative_path_to(found_path)} to #{relative_path_to(install_path)}" }
44
- FileUtils.cp_r(found_path, install_path)
44
+ FileUtils.cp_r(found_path, install_path, :preserve => true)
45
45
  end
46
46
 
47
47
  def manifest?(name, path)
@@ -1,3 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ #^syntax detection
3
+
1
4
  forge "http://forge.puppetlabs.com"
2
5
 
3
6
  # mod 'puppetlabs/stdlib'
@@ -1,5 +1,5 @@
1
1
  module Librarian
2
2
  module Puppet
3
- VERSION = "0.9.10.1"
3
+ VERSION = "0.9.11.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: librarian-puppet-maestrodev
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.10.1
4
+ version: 0.9.11.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-10 00:00:00.000000000 Z
12
+ date: 2013-12-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: librarian
@@ -123,6 +123,38 @@ dependencies:
123
123
  - - ! '>='
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: minitest
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ~>
132
+ - !ruby/object:Gem::Version
133
+ version: '5'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ~>
140
+ - !ruby/object:Gem::Version
141
+ version: '5'
142
+ - !ruby/object:Gem::Dependency
143
+ name: mocha
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
126
158
  description: ! "Simplify deployment of your Puppet infrastructure by\n automatically
127
159
  pulling in modules from the forge and git repositories with\n a single command."
128
160
  email:
@@ -152,7 +184,8 @@ files:
152
184
  - lib/librarian/puppet/source/path.rb
153
185
  - lib/librarian/puppet/source/local.rb
154
186
  homepage: https://github.com/rodjek/librarian-puppet
155
- licenses: []
187
+ licenses:
188
+ - MIT
156
189
  post_install_message:
157
190
  rdoc_options: []
158
191
  require_paths:
@@ -165,7 +198,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
165
198
  version: '0'
166
199
  segments:
167
200
  - 0
168
- hash: -2861496222512018377
201
+ hash: -3890518888719605347
169
202
  required_rubygems_version: !ruby/object:Gem::Requirement
170
203
  none: false
171
204
  requirements:
@@ -174,7 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
174
207
  version: '0'
175
208
  segments:
176
209
  - 0
177
- hash: -2861496222512018377
210
+ hash: -3890518888719605347
178
211
  requirements: []
179
212
  rubyforge_project:
180
213
  rubygems_version: 1.8.25