librarian-puppet-maestrodev 0.9.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. data/.gitignore +3 -0
  2. data/LICENSE +20 -0
  3. data/README.md +187 -0
  4. data/bin/librarian-puppet +9 -0
  5. data/lib/librarian/puppet.rb +13 -0
  6. data/lib/librarian/puppet/cli.rb +85 -0
  7. data/lib/librarian/puppet/dsl.rb +16 -0
  8. data/lib/librarian/puppet/environment.rb +54 -0
  9. data/lib/librarian/puppet/extension.rb +41 -0
  10. data/lib/librarian/puppet/lockfile/parser.rb +53 -0
  11. data/lib/librarian/puppet/source.rb +4 -0
  12. data/lib/librarian/puppet/source/forge.rb +279 -0
  13. data/lib/librarian/puppet/source/git.rb +114 -0
  14. data/lib/librarian/puppet/source/githubtarball.rb +234 -0
  15. data/lib/librarian/puppet/source/local.rb +57 -0
  16. data/lib/librarian/puppet/source/path.rb +12 -0
  17. data/lib/librarian/puppet/templates/Puppetfile +10 -0
  18. data/lib/librarian/puppet/version.rb +5 -0
  19. data/vendor/librarian/CHANGELOG.md +185 -0
  20. data/vendor/librarian/Gemfile +6 -0
  21. data/vendor/librarian/MIT-LICENSE +20 -0
  22. data/vendor/librarian/README.md +403 -0
  23. data/vendor/librarian/Rakefile +34 -0
  24. data/vendor/librarian/bin/librarian-chef +7 -0
  25. data/vendor/librarian/bin/librarian-mock +7 -0
  26. data/vendor/librarian/config/cucumber.yaml +1 -0
  27. data/vendor/librarian/features/chef/cli/init.feature +11 -0
  28. data/vendor/librarian/features/chef/cli/install.feature +64 -0
  29. data/vendor/librarian/features/chef/cli/show.feature +77 -0
  30. data/vendor/librarian/features/chef/cli/version.feature +11 -0
  31. data/vendor/librarian/features/support/env.rb +9 -0
  32. data/vendor/librarian/lib/librarian.rb +19 -0
  33. data/vendor/librarian/lib/librarian/action.rb +5 -0
  34. data/vendor/librarian/lib/librarian/action/base.rb +24 -0
  35. data/vendor/librarian/lib/librarian/action/clean.rb +44 -0
  36. data/vendor/librarian/lib/librarian/action/ensure.rb +24 -0
  37. data/vendor/librarian/lib/librarian/action/install.rb +99 -0
  38. data/vendor/librarian/lib/librarian/action/resolve.rb +81 -0
  39. data/vendor/librarian/lib/librarian/action/update.rb +78 -0
  40. data/vendor/librarian/lib/librarian/chef.rb +1 -0
  41. data/vendor/librarian/lib/librarian/chef/cli.rb +48 -0
  42. data/vendor/librarian/lib/librarian/chef/dsl.rb +15 -0
  43. data/vendor/librarian/lib/librarian/chef/environment.rb +27 -0
  44. data/vendor/librarian/lib/librarian/chef/extension.rb +9 -0
  45. data/vendor/librarian/lib/librarian/chef/integration/knife.rb +42 -0
  46. data/vendor/librarian/lib/librarian/chef/manifest_reader.rb +59 -0
  47. data/vendor/librarian/lib/librarian/chef/source.rb +3 -0
  48. data/vendor/librarian/lib/librarian/chef/source/git.rb +25 -0
  49. data/vendor/librarian/lib/librarian/chef/source/local.rb +69 -0
  50. data/vendor/librarian/lib/librarian/chef/source/path.rb +12 -0
  51. data/vendor/librarian/lib/librarian/chef/source/site.rb +446 -0
  52. data/vendor/librarian/lib/librarian/chef/templates/Cheffile +15 -0
  53. data/vendor/librarian/lib/librarian/cli.rb +205 -0
  54. data/vendor/librarian/lib/librarian/cli/manifest_presenter.rb +79 -0
  55. data/vendor/librarian/lib/librarian/config.rb +7 -0
  56. data/vendor/librarian/lib/librarian/config/database.rb +205 -0
  57. data/vendor/librarian/lib/librarian/config/file_source.rb +47 -0
  58. data/vendor/librarian/lib/librarian/config/hash_source.rb +33 -0
  59. data/vendor/librarian/lib/librarian/config/source.rb +149 -0
  60. data/vendor/librarian/lib/librarian/dependency.rb +91 -0
  61. data/vendor/librarian/lib/librarian/dsl.rb +108 -0
  62. data/vendor/librarian/lib/librarian/dsl/receiver.rb +48 -0
  63. data/vendor/librarian/lib/librarian/dsl/target.rb +172 -0
  64. data/vendor/librarian/lib/librarian/environment.rb +134 -0
  65. data/vendor/librarian/lib/librarian/error.rb +4 -0
  66. data/vendor/librarian/lib/librarian/helpers.rb +13 -0
  67. data/vendor/librarian/lib/librarian/lockfile.rb +29 -0
  68. data/vendor/librarian/lib/librarian/lockfile/compiler.rb +66 -0
  69. data/vendor/librarian/lib/librarian/lockfile/parser.rb +100 -0
  70. data/vendor/librarian/lib/librarian/logger.rb +46 -0
  71. data/vendor/librarian/lib/librarian/manifest.rb +132 -0
  72. data/vendor/librarian/lib/librarian/manifest_set.rb +153 -0
  73. data/vendor/librarian/lib/librarian/mock.rb +1 -0
  74. data/vendor/librarian/lib/librarian/mock/cli.rb +19 -0
  75. data/vendor/librarian/lib/librarian/mock/dsl.rb +15 -0
  76. data/vendor/librarian/lib/librarian/mock/environment.rb +24 -0
  77. data/vendor/librarian/lib/librarian/mock/extension.rb +9 -0
  78. data/vendor/librarian/lib/librarian/mock/source.rb +1 -0
  79. data/vendor/librarian/lib/librarian/mock/source/mock.rb +97 -0
  80. data/vendor/librarian/lib/librarian/mock/source/mock/registry.rb +83 -0
  81. data/vendor/librarian/lib/librarian/resolution.rb +44 -0
  82. data/vendor/librarian/lib/librarian/resolver.rb +78 -0
  83. data/vendor/librarian/lib/librarian/resolver/implementation.rb +118 -0
  84. data/vendor/librarian/lib/librarian/source.rb +2 -0
  85. data/vendor/librarian/lib/librarian/source/git.rb +150 -0
  86. data/vendor/librarian/lib/librarian/source/git/repository.rb +217 -0
  87. data/vendor/librarian/lib/librarian/source/local.rb +61 -0
  88. data/vendor/librarian/lib/librarian/source/path.rb +74 -0
  89. data/vendor/librarian/lib/librarian/spec.rb +13 -0
  90. data/vendor/librarian/lib/librarian/spec_change_set.rb +173 -0
  91. data/vendor/librarian/lib/librarian/specfile.rb +18 -0
  92. data/vendor/librarian/lib/librarian/support/abstract_method.rb +21 -0
  93. data/vendor/librarian/lib/librarian/ui.rb +64 -0
  94. data/vendor/librarian/lib/librarian/version.rb +3 -0
  95. data/vendor/librarian/librarian.gemspec +34 -0
  96. data/vendor/librarian/spec/functional/chef/source/git_spec.rb +432 -0
  97. data/vendor/librarian/spec/functional/chef/source/site_spec.rb +215 -0
  98. data/vendor/librarian/spec/functional/source/git/repository_spec.rb +149 -0
  99. data/vendor/librarian/spec/unit/action/base_spec.rb +18 -0
  100. data/vendor/librarian/spec/unit/action/clean_spec.rb +102 -0
  101. data/vendor/librarian/spec/unit/action/ensure_spec.rb +37 -0
  102. data/vendor/librarian/spec/unit/action/install_spec.rb +111 -0
  103. data/vendor/librarian/spec/unit/config/database_spec.rb +319 -0
  104. data/vendor/librarian/spec/unit/dependency_spec.rb +36 -0
  105. data/vendor/librarian/spec/unit/dsl_spec.rb +194 -0
  106. data/vendor/librarian/spec/unit/environment_spec.rb +9 -0
  107. data/vendor/librarian/spec/unit/lockfile/parser_spec.rb +162 -0
  108. data/vendor/librarian/spec/unit/lockfile_spec.rb +65 -0
  109. data/vendor/librarian/spec/unit/manifest_set_spec.rb +202 -0
  110. data/vendor/librarian/spec/unit/manifest_spec.rb +36 -0
  111. data/vendor/librarian/spec/unit/mock/source/mock_spec.rb +22 -0
  112. data/vendor/librarian/spec/unit/resolver_spec.rb +192 -0
  113. data/vendor/librarian/spec/unit/source/git_spec.rb +29 -0
  114. data/vendor/librarian/spec/unit/spec_change_set_spec.rb +169 -0
  115. metadata +227 -0
@@ -0,0 +1,12 @@
1
+ require 'librarian/source/path'
2
+ require 'librarian/chef/source/local'
3
+
4
+ module Librarian
5
+ module Chef
6
+ module Source
7
+ class Path < Librarian::Source::Path
8
+ include Local
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,446 @@
1
+ require 'fileutils'
2
+ require 'pathname'
3
+ require 'uri'
4
+ require 'net/http'
5
+ require 'json'
6
+ require 'digest'
7
+ require 'zlib'
8
+ require 'securerandom'
9
+ require 'archive/tar/minitar'
10
+
11
+ require 'librarian/chef/manifest_reader'
12
+
13
+ module Librarian
14
+ module Chef
15
+ module Source
16
+ class Site
17
+
18
+ class Line
19
+
20
+ attr_accessor :source, :name
21
+ private :source=, :name=
22
+
23
+ def initialize(source, name)
24
+ self.source = source
25
+ self.name = name
26
+ end
27
+
28
+ def install_version!(version, install_path)
29
+ cache_version_unpacked! version
30
+
31
+ if install_path.exist?
32
+ debug { "Deleting #{relative_path_to(install_path)}" }
33
+ install_path.rmtree
34
+ end
35
+
36
+ unpacked_path = version_unpacked_cache_path(version)
37
+
38
+ debug { "Copying #{relative_path_to(unpacked_path)} to #{relative_path_to(install_path)}" }
39
+ FileUtils.cp_r(unpacked_path, install_path)
40
+ end
41
+
42
+ def manifests
43
+ version_uris.map do |version_uri|
44
+ Manifest.new(source, name, version_uri)
45
+ end
46
+ end
47
+
48
+ def to_version(version_uri)
49
+ version_uri_metadata(version_uri)["version"]
50
+ end
51
+
52
+ def version_dependencies(version)
53
+ version_manifest(version)["dependencies"]
54
+ end
55
+
56
+ private
57
+
58
+ attr_accessor :metadata_cached
59
+ alias metadata_cached? metadata_cached
60
+
61
+ def environment
62
+ source.environment
63
+ end
64
+
65
+ def uri
66
+ @uri ||= URI.parse("#{source.uri}/cookbooks/#{name}")
67
+ end
68
+
69
+ def version_uris
70
+ metadata["versions"]
71
+ end
72
+
73
+ def version_metadata(version)
74
+ version_uri = to_version_uri(version)
75
+ version_uri_metadata(version_uri)
76
+ end
77
+
78
+ def version_uri_metadata(version_uri)
79
+ @version_uri_metadata ||= { }
80
+ @version_uri_metadata[version_uri.to_s] ||= begin
81
+ cache_version_uri_metadata! version_uri
82
+ parse_local_json(version_uri_metadata_cache_path(version_uri))
83
+ end
84
+ end
85
+
86
+ def version_manifest(version)
87
+ version_uri = to_version_uri(version)
88
+ version_uri_manifest(version_uri)
89
+ end
90
+
91
+ def version_uri_manifest(version_uri)
92
+ @version_uri_manifest ||= { }
93
+ @version_uri_manifest[version_uri.to_s] ||= begin
94
+ cache_version_uri_unpacked! version_uri
95
+ unpacked_path = version_uri_unpacked_cache_path(version_uri)
96
+ manifest_path = ManifestReader.manifest_path(unpacked_path)
97
+ ManifestReader.read_manifest(name, manifest_path)
98
+ end
99
+ end
100
+
101
+ def metadata
102
+ @metadata ||= begin
103
+ cache_metadata!
104
+ parse_local_json(metadata_cache_path)
105
+ end
106
+ end
107
+
108
+ def to_version_uri(version)
109
+ @to_version_uri ||= { }
110
+ @to_version_uri[version.to_s] ||= begin
111
+ cache_version! version
112
+ version_cache_path(version).read
113
+ end
114
+ end
115
+
116
+ def metadata_cached!
117
+ self.metadata_cached = true
118
+ end
119
+
120
+ def cache_path
121
+ @cache_path ||= source.cache_path.join(name)
122
+ end
123
+
124
+ def metadata_cache_path
125
+ @metadata_cache_path ||= cache_path.join("metadata.json")
126
+ end
127
+
128
+ def version_cache_path(version)
129
+ @version_cache_path ||= { }
130
+ @version_cache_path[version.to_s] ||= begin
131
+ cache_path.join("version").join(version.to_s)
132
+ end
133
+ end
134
+
135
+ def version_uri_cache_path(version_uri)
136
+ @version_uri_cache_path ||= { }
137
+ @version_uri_cache_path[version_uri.to_s] ||= begin
138
+ cache_path.join("version-uri").join(hexdigest(version_uri))
139
+ end
140
+ end
141
+
142
+ def version_metadata_cache_path(version)
143
+ version_uri = to_version_uri(version)
144
+ version_uri_metadata_cache_path(version_uri)
145
+ end
146
+
147
+ def version_uri_metadata_cache_path(version_uri)
148
+ @version_uri_metadata_cache_path ||= { }
149
+ @version_uri_metadata_cache_path[version_uri.to_s] ||= begin
150
+ version_uri_cache_path(version_uri).join("metadata.json")
151
+ end
152
+ end
153
+
154
+ def version_package_cache_path(version)
155
+ version_uri = to_version_uri(version)
156
+ version_uri_package_cache_path(version_uri)
157
+ end
158
+
159
+ def version_uri_package_cache_path(version_uri)
160
+ @version_uri_package_cache_path ||= { }
161
+ @version_uri_package_cache_path[version_uri.to_s] ||= begin
162
+ version_uri_cache_path(version_uri).join("package.tar.gz")
163
+ end
164
+ end
165
+
166
+ def version_unpacked_cache_path(version)
167
+ version_uri = to_version_uri(version)
168
+ version_uri_unpacked_cache_path(version_uri)
169
+ end
170
+
171
+ def version_uri_unpacked_cache_path(version_uri)
172
+ @version_uri_unpacked_cache_path ||= { }
173
+ @version_uri_unpacked_cache_path[version_uri.to_s] ||= begin
174
+ version_uri_cache_path(version_uri).join("package")
175
+ end
176
+ end
177
+
178
+ def cache_metadata!
179
+ metadata_cached? and return or metadata_cached!
180
+ cache_remote_json! metadata_cache_path, uri
181
+ end
182
+
183
+ def cache_version_uri_metadata!(version_uri)
184
+ path = version_uri_metadata_cache_path(version_uri)
185
+ path.file? and return
186
+
187
+ cache_remote_json! path, version_uri
188
+ end
189
+
190
+ def cache_version!(version)
191
+ path = version_cache_path(version)
192
+ path.file? and return
193
+
194
+ version_uris.each do |version_uri|
195
+ m = version_uri_metadata(version_uri)
196
+ v = m["version"]
197
+ if version.to_s == v
198
+ write! path, version_uri.to_s
199
+ break
200
+ end
201
+ end
202
+ end
203
+
204
+ def cache_version_package!(version)
205
+ version_uri = to_version_uri(version)
206
+ cache_version_uri_package! version_uri
207
+ end
208
+
209
+ def cache_version_uri_package!(version_uri)
210
+ path = version_uri_package_cache_path(version_uri)
211
+ path.file? and return
212
+
213
+ file_uri = version_uri_metadata(version_uri)["file"]
214
+ cache_remote_object! path, file_uri
215
+ end
216
+
217
+ def cache_version_unpacked!(version)
218
+ version_uri = to_version_uri(version)
219
+ cache_version_uri_unpacked! version_uri
220
+ end
221
+
222
+ def cache_version_uri_unpacked!(version_uri)
223
+ cache_version_uri_package!(version_uri)
224
+
225
+ path = version_uri_unpacked_cache_path(version_uri)
226
+ path.directory? and return
227
+
228
+ package_path = version_uri_package_cache_path(version_uri)
229
+ unpacked_path = version_uri_unpacked_cache_path(version_uri)
230
+
231
+ unpack_package! unpacked_path, package_path
232
+ end
233
+
234
+ def cache_remote_json!(path, uri)
235
+ path = Pathname(path)
236
+ uri = to_uri(uri)
237
+
238
+ path.dirname.mkpath unless path.dirname.directory?
239
+
240
+ debug { "Caching #{uri} to #{path}" }
241
+
242
+ http = Net::HTTP.new(uri.host, uri.port)
243
+ request = Net::HTTP::Get.new(uri.path)
244
+ response = http.start{|http| http.request(request)}
245
+ unless Net::HTTPSuccess === response
246
+ raise Error, "Could not get #{uri} because #{response.code} #{response.message}!"
247
+ end
248
+ json = response.body
249
+ JSON.parse(json) # verify that it's really JSON.
250
+ write! path, json
251
+ end
252
+
253
+ def cache_remote_object!(path, uri)
254
+ path = Pathname(path)
255
+ uri = to_uri(uri)
256
+
257
+ path.dirname.mkpath unless path.dirname.directory?
258
+
259
+ debug { "Caching #{uri} to #{path}" }
260
+
261
+ http = Net::HTTP.new(uri.host, uri.port)
262
+ request = Net::HTTP::Get.new(uri.path)
263
+ response = http.start{|http| http.request(request)}
264
+ unless Net::HTTPSuccess === response
265
+ raise Error, "Could not get #{uri} because #{response.code} #{response.message}!"
266
+ end
267
+ write! path, response.body
268
+ end
269
+
270
+ def write!(path, bytes)
271
+ path.dirname.mkpath
272
+ path.open("wb"){|f| f.write(bytes)}
273
+ end
274
+
275
+ def unpack_package!(path, source)
276
+ path = Pathname(path)
277
+ source = Pathname(source)
278
+
279
+ temp = environment.scratch_path.join(SecureRandom.hex(16))
280
+ temp.mkpath
281
+
282
+ debug { "Unpacking #{relative_path_to(source)} to #{relative_path_to(temp)}" }
283
+ Zlib::GzipReader.open(source) do |input|
284
+ Archive::Tar::Minitar.unpack(input, temp.to_s)
285
+ end
286
+
287
+ # Cookbook files, as pulled from Opscode Community Site API, are
288
+ # embedded in a subdirectory of the tarball, and the subdirectory's
289
+ # name is equal to the name of the cookbook.
290
+ subtemp = temp.join(name)
291
+ debug { "Moving #{relative_path_to(subtemp)} to #{relative_path_to(path)}" }
292
+ FileUtils.mv(subtemp, path)
293
+ ensure
294
+ temp.rmtree if temp && temp.exist?
295
+ end
296
+
297
+ def parse_local_json(path)
298
+ JSON.parse(path.read)
299
+ end
300
+
301
+ def hexdigest(bytes)
302
+ Digest::MD5.hexdigest(bytes)
303
+ end
304
+
305
+ def to_uri(uri)
306
+ uri = URI(uri) unless URI === uri
307
+ uri
308
+ end
309
+
310
+ def debug(*args, &block)
311
+ environment.logger.debug(*args, &block)
312
+ end
313
+
314
+ def relative_path_to(path)
315
+ environment.logger.relative_path_to(path)
316
+ end
317
+
318
+ end
319
+
320
+ class << self
321
+
322
+ LOCK_NAME = 'SITE'
323
+
324
+ def lock_name
325
+ LOCK_NAME
326
+ end
327
+
328
+ def from_lock_options(environment, options)
329
+ new(environment, options[:remote], options.reject{|k, v| k == :remote})
330
+ end
331
+
332
+ def from_spec_args(environment, uri, options)
333
+ recognized_options = []
334
+ unrecognized_options = options.keys - recognized_options
335
+ unrecognized_options.empty? or raise Error, "unrecognized options: #{unrecognized_options.join(", ")}"
336
+
337
+ new(environment, uri, options)
338
+ end
339
+
340
+ end
341
+
342
+ attr_accessor :environment
343
+ private :environment=
344
+ attr_reader :uri
345
+
346
+ attr_accessor :_metadata_cache
347
+ private :_metadata_cache, :_metadata_cache=
348
+
349
+ def initialize(environment, uri, options = {})
350
+ self.environment = environment
351
+ @uri = uri
352
+ @cache_path = nil
353
+ self._metadata_cache = { }
354
+ end
355
+
356
+ def to_s
357
+ uri
358
+ end
359
+
360
+ def ==(other)
361
+ other &&
362
+ self.class == other.class &&
363
+ self.uri == other.uri
364
+ end
365
+
366
+ def to_spec_args
367
+ [uri, {}]
368
+ end
369
+
370
+ def to_lock_options
371
+ {:remote => uri}
372
+ end
373
+
374
+ def pinned?
375
+ false
376
+ end
377
+
378
+ def unpin!
379
+ end
380
+
381
+ def install!(manifest)
382
+ manifest.source == self or raise ArgumentError
383
+
384
+ name = manifest.name
385
+ version = manifest.version
386
+ install_path = install_path(name)
387
+ line = line(name)
388
+
389
+ info { "Installing #{manifest.name} (#{manifest.version})" }
390
+
391
+ debug { "Installing #{manifest}" }
392
+
393
+ line.install_version! version, install_path
394
+ end
395
+
396
+ # NOTE:
397
+ # Assumes the Opscode Site API responds with versions in reverse sorted order
398
+ def manifests(name)
399
+ line(name).manifests
400
+ end
401
+
402
+ def manifest(name, version, dependencies)
403
+ manifest = Manifest.new(self, name)
404
+ manifest.version = version
405
+ manifest.dependencies = dependencies
406
+ manifest
407
+ end
408
+
409
+ def cache_path
410
+ @cache_path ||= begin
411
+ dir = Digest::MD5.hexdigest(uri)
412
+ environment.cache_path.join("source/chef/site/#{dir}")
413
+ end
414
+ end
415
+
416
+ def install_path(name)
417
+ environment.install_path.join(name)
418
+ end
419
+
420
+ def fetch_version(name, version_uri)
421
+ line(name).to_version(version_uri)
422
+ end
423
+
424
+ def fetch_dependencies(name, version, version_uri)
425
+ line(name).version_dependencies(version).map{|k, v| Dependency.new(k, v, nil)}
426
+ end
427
+
428
+ private
429
+
430
+ def line(name)
431
+ @line ||= { }
432
+ @line[name] ||= Line.new(self, name)
433
+ end
434
+
435
+ def info(*args, &block)
436
+ environment.logger.info(*args, &block)
437
+ end
438
+
439
+ def debug(*args, &block)
440
+ environment.logger.debug(*args, &block)
441
+ end
442
+
443
+ end
444
+ end
445
+ end
446
+ end