librarian-puppet 0.9.10 → 0.9.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +82 -19
  3. data/bin/librarian-puppet +0 -2
  4. data/lib/librarian/puppet.rb +32 -4
  5. data/lib/librarian/puppet/cli.rb +7 -0
  6. data/lib/librarian/puppet/dsl.rb +13 -0
  7. data/lib/librarian/puppet/environment.rb +5 -8
  8. data/lib/librarian/puppet/extension.rb +212 -0
  9. data/lib/librarian/puppet/requirement.rb +6 -2
  10. data/lib/librarian/puppet/source.rb +1 -0
  11. data/lib/librarian/puppet/source/forge.rb +62 -35
  12. data/lib/librarian/puppet/source/git.rb +51 -36
  13. data/lib/librarian/puppet/source/githubtarball.rb +44 -28
  14. data/lib/librarian/puppet/source/local.rb +4 -1
  15. data/lib/librarian/puppet/templates/Puppetfile +3 -0
  16. data/lib/librarian/puppet/util.rb +27 -0
  17. data/lib/librarian/puppet/version.rb +1 -1
  18. metadata +106 -207
  19. data/vendor/librarian/CHANGELOG.md +0 -185
  20. data/vendor/librarian/Gemfile +0 -6
  21. data/vendor/librarian/MIT-LICENSE +0 -20
  22. data/vendor/librarian/README.md +0 -403
  23. data/vendor/librarian/Rakefile +0 -34
  24. data/vendor/librarian/bin/librarian-chef +0 -7
  25. data/vendor/librarian/bin/librarian-mock +0 -7
  26. data/vendor/librarian/config/cucumber.yaml +0 -1
  27. data/vendor/librarian/features/chef/cli/init.feature +0 -11
  28. data/vendor/librarian/features/chef/cli/install.feature +0 -64
  29. data/vendor/librarian/features/chef/cli/show.feature +0 -77
  30. data/vendor/librarian/features/chef/cli/version.feature +0 -11
  31. data/vendor/librarian/features/support/env.rb +0 -9
  32. data/vendor/librarian/lib/librarian.rb +0 -19
  33. data/vendor/librarian/lib/librarian/action.rb +0 -5
  34. data/vendor/librarian/lib/librarian/action/base.rb +0 -24
  35. data/vendor/librarian/lib/librarian/action/clean.rb +0 -44
  36. data/vendor/librarian/lib/librarian/action/ensure.rb +0 -24
  37. data/vendor/librarian/lib/librarian/action/install.rb +0 -99
  38. data/vendor/librarian/lib/librarian/action/resolve.rb +0 -81
  39. data/vendor/librarian/lib/librarian/action/update.rb +0 -78
  40. data/vendor/librarian/lib/librarian/chef.rb +0 -1
  41. data/vendor/librarian/lib/librarian/chef/cli.rb +0 -48
  42. data/vendor/librarian/lib/librarian/chef/dsl.rb +0 -15
  43. data/vendor/librarian/lib/librarian/chef/environment.rb +0 -27
  44. data/vendor/librarian/lib/librarian/chef/extension.rb +0 -9
  45. data/vendor/librarian/lib/librarian/chef/integration/knife.rb +0 -42
  46. data/vendor/librarian/lib/librarian/chef/manifest_reader.rb +0 -59
  47. data/vendor/librarian/lib/librarian/chef/source.rb +0 -3
  48. data/vendor/librarian/lib/librarian/chef/source/git.rb +0 -25
  49. data/vendor/librarian/lib/librarian/chef/source/local.rb +0 -69
  50. data/vendor/librarian/lib/librarian/chef/source/path.rb +0 -12
  51. data/vendor/librarian/lib/librarian/chef/source/site.rb +0 -452
  52. data/vendor/librarian/lib/librarian/chef/templates/Cheffile +0 -15
  53. data/vendor/librarian/lib/librarian/cli.rb +0 -205
  54. data/vendor/librarian/lib/librarian/cli/manifest_presenter.rb +0 -79
  55. data/vendor/librarian/lib/librarian/config.rb +0 -7
  56. data/vendor/librarian/lib/librarian/config/database.rb +0 -205
  57. data/vendor/librarian/lib/librarian/config/file_source.rb +0 -47
  58. data/vendor/librarian/lib/librarian/config/hash_source.rb +0 -33
  59. data/vendor/librarian/lib/librarian/config/source.rb +0 -149
  60. data/vendor/librarian/lib/librarian/dependency.rb +0 -91
  61. data/vendor/librarian/lib/librarian/dsl.rb +0 -108
  62. data/vendor/librarian/lib/librarian/dsl/receiver.rb +0 -48
  63. data/vendor/librarian/lib/librarian/dsl/target.rb +0 -172
  64. data/vendor/librarian/lib/librarian/environment.rb +0 -134
  65. data/vendor/librarian/lib/librarian/error.rb +0 -4
  66. data/vendor/librarian/lib/librarian/helpers.rb +0 -13
  67. data/vendor/librarian/lib/librarian/lockfile.rb +0 -29
  68. data/vendor/librarian/lib/librarian/lockfile/compiler.rb +0 -66
  69. data/vendor/librarian/lib/librarian/lockfile/parser.rb +0 -100
  70. data/vendor/librarian/lib/librarian/logger.rb +0 -46
  71. data/vendor/librarian/lib/librarian/manifest.rb +0 -234
  72. data/vendor/librarian/lib/librarian/manifest_set.rb +0 -153
  73. data/vendor/librarian/lib/librarian/mock.rb +0 -1
  74. data/vendor/librarian/lib/librarian/mock/cli.rb +0 -19
  75. data/vendor/librarian/lib/librarian/mock/dsl.rb +0 -15
  76. data/vendor/librarian/lib/librarian/mock/environment.rb +0 -24
  77. data/vendor/librarian/lib/librarian/mock/extension.rb +0 -9
  78. data/vendor/librarian/lib/librarian/mock/source.rb +0 -1
  79. data/vendor/librarian/lib/librarian/mock/source/mock.rb +0 -103
  80. data/vendor/librarian/lib/librarian/mock/source/mock/registry.rb +0 -83
  81. data/vendor/librarian/lib/librarian/resolution.rb +0 -44
  82. data/vendor/librarian/lib/librarian/resolver.rb +0 -78
  83. data/vendor/librarian/lib/librarian/resolver/implementation.rb +0 -118
  84. data/vendor/librarian/lib/librarian/source.rb +0 -2
  85. data/vendor/librarian/lib/librarian/source/git.rb +0 -156
  86. data/vendor/librarian/lib/librarian/source/git/repository.rb +0 -217
  87. data/vendor/librarian/lib/librarian/source/local.rb +0 -61
  88. data/vendor/librarian/lib/librarian/source/path.rb +0 -80
  89. data/vendor/librarian/lib/librarian/spec.rb +0 -13
  90. data/vendor/librarian/lib/librarian/spec_change_set.rb +0 -173
  91. data/vendor/librarian/lib/librarian/specfile.rb +0 -18
  92. data/vendor/librarian/lib/librarian/support/abstract_method.rb +0 -21
  93. data/vendor/librarian/lib/librarian/ui.rb +0 -64
  94. data/vendor/librarian/lib/librarian/version.rb +0 -3
  95. data/vendor/librarian/librarian.gemspec +0 -34
  96. data/vendor/librarian/spec/functional/chef/source/git_spec.rb +0 -432
  97. data/vendor/librarian/spec/functional/chef/source/site_spec.rb +0 -215
  98. data/vendor/librarian/spec/functional/source/git/repository_spec.rb +0 -149
  99. data/vendor/librarian/spec/unit/action/base_spec.rb +0 -18
  100. data/vendor/librarian/spec/unit/action/clean_spec.rb +0 -102
  101. data/vendor/librarian/spec/unit/action/ensure_spec.rb +0 -37
  102. data/vendor/librarian/spec/unit/action/install_spec.rb +0 -111
  103. data/vendor/librarian/spec/unit/config/database_spec.rb +0 -319
  104. data/vendor/librarian/spec/unit/dependency_spec.rb +0 -36
  105. data/vendor/librarian/spec/unit/dsl_spec.rb +0 -194
  106. data/vendor/librarian/spec/unit/environment_spec.rb +0 -9
  107. data/vendor/librarian/spec/unit/lockfile/parser_spec.rb +0 -162
  108. data/vendor/librarian/spec/unit/lockfile_spec.rb +0 -65
  109. data/vendor/librarian/spec/unit/manifest_set_spec.rb +0 -202
  110. data/vendor/librarian/spec/unit/manifest_spec.rb +0 -36
  111. data/vendor/librarian/spec/unit/manifest_version_spec.rb +0 -94
  112. data/vendor/librarian/spec/unit/mock/source/mock_spec.rb +0 -22
  113. data/vendor/librarian/spec/unit/resolver_spec.rb +0 -192
  114. data/vendor/librarian/spec/unit/source/git_spec.rb +0 -29
  115. data/vendor/librarian/spec/unit/spec_change_set_spec.rb +0 -169
@@ -1,78 +0,0 @@
1
- require "librarian/error"
2
- require "librarian/manifest_set"
3
- require "librarian/resolver"
4
- require "librarian/spec_change_set"
5
- require "librarian/action/base"
6
-
7
- module Librarian
8
- module Action
9
- class Update < Base
10
-
11
- def run
12
- unless lockfile_path.exist?
13
- raise Error, "Lockfile missing!"
14
- end
15
- previous_resolution = lockfile.load(lockfile_path.read)
16
- spec = specfile.read(previous_resolution.sources)
17
- changes = spec_change_set(spec, previous_resolution)
18
- manifests = changes.same? ? previous_resolution.manifests : changes.analyze
19
- partial_manifests = ManifestSet.deep_strip(manifests, dependency_names)
20
- unpinnable_sources = previous_resolution.sources - partial_manifests.map(&:source)
21
- unpinnable_sources.each(&:unpin!)
22
- resolution = resolver.resolve(spec, partial_manifests)
23
- unless resolution.correct?
24
- raise Error, "Could not resolve the dependencies."
25
- else
26
- lockfile_text = lockfile.save(resolution)
27
- debug { "Bouncing #{lockfile_name}" }
28
- bounced_lockfile_text = lockfile.save(lockfile.load(lockfile_text))
29
- unless bounced_lockfile_text == lockfile_text
30
- debug { "lockfile_text: \n#{lockfile_text}"}
31
- debug { "bounced_lockfile_text: \n#{bounced_lockfile_text}"}
32
- raise Error, "Cannot bounce #{lockfile_name}!"
33
- end
34
- lockfile_path.open('wb') { |f| f.write(lockfile_text) }
35
- end
36
- end
37
-
38
- private
39
-
40
- def dependency_names
41
- options[:names]
42
- end
43
-
44
- def specfile_name
45
- environment.specfile_name
46
- end
47
-
48
- def lockfile_name
49
- environment.lockfile_name
50
- end
51
-
52
- def specfile_path
53
- environment.specfile_path
54
- end
55
-
56
- def lockfile_path
57
- environment.lockfile_path
58
- end
59
-
60
- def specfile
61
- environment.specfile
62
- end
63
-
64
- def lockfile
65
- environment.lockfile
66
- end
67
-
68
- def resolver
69
- Resolver.new(environment)
70
- end
71
-
72
- def spec_change_set(spec, lock)
73
- SpecChangeSet.new(environment, spec, lock)
74
- end
75
-
76
- end
77
- end
78
- end
@@ -1 +0,0 @@
1
- require 'librarian/chef/extension'
@@ -1,48 +0,0 @@
1
- require 'librarian/helpers'
2
-
3
- require 'librarian/cli'
4
- require 'librarian/chef'
5
-
6
- module Librarian
7
- module Chef
8
- class Cli < Librarian::Cli
9
-
10
- module Particularity
11
- def root_module
12
- Chef
13
- end
14
- end
15
-
16
- include Particularity
17
- extend Particularity
18
-
19
- source_root Pathname.new(__FILE__).dirname.join("templates")
20
-
21
- def init
22
- copy_file environment.specfile_name
23
- end
24
-
25
- desc "install", "Resolves and installs all of the dependencies you specify."
26
- option "quiet", :type => :boolean, :default => false
27
- option "verbose", :type => :boolean, :default => false
28
- option "line-numbers", :type => :boolean, :default => false
29
- option "clean", :type => :boolean, :default => false
30
- option "strip-dot-git", :type => :boolean
31
- option "path", :type => :string
32
- def install
33
- ensure!
34
- clean! if options["clean"]
35
- if options.include?("strip-dot-git")
36
- strip_dot_git_val = options["strip-dot-git"] ? "1" : nil
37
- environment.config_db.local["install.strip-dot-git"] = strip_dot_git_val
38
- end
39
- if options.include?("path")
40
- environment.config_db.local["path"] = options["path"]
41
- end
42
- resolve!
43
- install!
44
- end
45
-
46
- end
47
- end
48
- end
@@ -1,15 +0,0 @@
1
- require 'librarian/dsl'
2
- require 'librarian/chef/source'
3
-
4
- module Librarian
5
- module Chef
6
- class Dsl < Librarian::Dsl
7
-
8
- dependency :cookbook
9
-
10
- source :site => Source::Site
11
- source :git => Source::Git
12
- source :path => Source::Path
13
- end
14
- end
15
- end
@@ -1,27 +0,0 @@
1
- require "librarian/environment"
2
- require "librarian/chef/dsl"
3
- require "librarian/chef/source"
4
-
5
- module Librarian
6
- module Chef
7
- class Environment < Environment
8
-
9
- def adapter_name
10
- "chef"
11
- end
12
-
13
- def install_path
14
- part = config_db["path"] || "cookbooks"
15
- project_path.join(part)
16
- end
17
-
18
- def config_keys
19
- super + %w[
20
- install.strip-dot-git
21
- path
22
- ]
23
- end
24
-
25
- end
26
- end
27
- end
@@ -1,9 +0,0 @@
1
- require 'librarian/chef/environment'
2
-
3
- module Librarian
4
- module Chef
5
- extend self
6
- extend Librarian
7
-
8
- end
9
- end
@@ -1,42 +0,0 @@
1
- require 'pathname'
2
- require 'securerandom'
3
- require 'highline'
4
-
5
- require 'librarian'
6
- require 'librarian/action/install'
7
- require 'librarian/chef'
8
-
9
- module Librarian
10
- module Chef
11
-
12
- class Environment
13
- def install_path
14
- @install_path ||= begin
15
- has_home = ENV["HOME"] && File.directory?(ENV["HOME"])
16
- tmp_dir = Pathname.new(has_home ? "~/.librarian/tmp" : "/tmp/librarian").expand_path
17
- enclosing = tmp_dir.join("chef/integration/knife/install")
18
- enclosing.mkpath unless enclosing.exist?
19
- dir = enclosing.join(SecureRandom.hex(16))
20
- dir.mkpath
21
- at_exit { dir.rmtree }
22
- dir
23
- end
24
- end
25
- end
26
-
27
- def install_path
28
- environment.install_path
29
- end
30
-
31
- hl = HighLine.new
32
-
33
- begin
34
- Action::Install.new(environment).run
35
- rescue Error => e
36
- message = hl.color(e.message, HighLine::RED)
37
- hl.say(message)
38
- Process.exit!(1)
39
- end
40
-
41
- end
42
- end
@@ -1,59 +0,0 @@
1
- require 'json'
2
- require 'yaml'
3
-
4
- require 'librarian/manifest'
5
-
6
- module Librarian
7
- module Chef
8
- module ManifestReader
9
- extend self
10
-
11
- MANIFESTS = %w(metadata.json metadata.yml metadata.yaml metadata.rb)
12
-
13
- def manifest_path(path)
14
- MANIFESTS.map{|s| path.join(s)}.find{|s| s.exist?}
15
- end
16
-
17
- def read_manifest(name, manifest_path)
18
- case manifest_path.extname
19
- when ".json" then JSON.parse(binread(manifest_path))
20
- when ".yml", ".yaml" then YAML.load(binread(manifest_path))
21
- when ".rb" then compile_manifest(name, manifest_path.dirname)
22
- end
23
- end
24
-
25
- def compile_manifest(name, path)
26
- # Inefficient, if there are many cookbooks with uncompiled metadata.
27
- require 'chef/json_compat'
28
- require 'chef/cookbook/metadata'
29
- md = ::Chef::Cookbook::Metadata.new
30
- md.name(name)
31
- md.from_file(path.join('metadata.rb').to_s)
32
- {"name" => md.name, "version" => md.version, "dependencies" => md.dependencies}
33
- end
34
-
35
- def manifest?(name, path)
36
- path = Pathname.new(path)
37
- !!manifest_path(path)
38
- end
39
-
40
- def check_manifest(name, manifest_path)
41
- manifest = read_manifest(name, manifest_path)
42
- manifest["name"] == name
43
- end
44
-
45
- private
46
-
47
- if IO.respond_to?(:binread)
48
- def binread(path)
49
- path.binread
50
- end
51
- else
52
- def binread(path)
53
- path.read
54
- end
55
- end
56
-
57
- end
58
- end
59
- end
@@ -1,3 +0,0 @@
1
- require 'librarian/chef/source/path'
2
- require 'librarian/chef/source/git'
3
- require 'librarian/chef/source/site'
@@ -1,25 +0,0 @@
1
- require 'librarian/source/git'
2
- require 'librarian/chef/source/local'
3
-
4
- module Librarian
5
- module Chef
6
- module Source
7
- class Git < Librarian::Source::Git
8
- include Local
9
-
10
- private
11
-
12
- def install_perform_step_copy!(found_path, install_path)
13
- debug { "Copying #{relative_path_to(found_path)} to #{relative_path_to(install_path)}" }
14
- FileUtils.cp_r(found_path, install_path)
15
-
16
- if environment.config_db["install.strip-dot-git"] == "1"
17
- dot_git = install_path.join(".git")
18
- dot_git.rmtree if dot_git.directory?
19
- end
20
- end
21
-
22
- end
23
- end
24
- end
25
- end
@@ -1,69 +0,0 @@
1
- require 'librarian/chef/manifest_reader'
2
-
3
- module Librarian
4
- module Chef
5
- module Source
6
- module Local
7
-
8
- def install!(manifest)
9
- manifest.source == self or raise ArgumentError
10
-
11
- info { "Installing #{manifest.name} (#{manifest.version})" }
12
-
13
- debug { "Installing #{manifest}" }
14
-
15
- name, version = manifest.name, manifest.version
16
- found_path = found_path(name)
17
-
18
- install_path = environment.install_path.join(name)
19
- if install_path.exist?
20
- debug { "Deleting #{relative_path_to(install_path)}" }
21
- install_path.rmtree
22
- end
23
-
24
- install_perform_step_copy!(found_path, install_path)
25
- end
26
-
27
- def fetch_version(name, extra)
28
- manifest_data(name)["version"]
29
- end
30
-
31
- def fetch_dependencies(name, version, extra)
32
- manifest_data(name)["dependencies"]
33
- end
34
-
35
- private
36
-
37
- def install_perform_step_copy!(found_path, install_path)
38
- debug { "Copying #{relative_path_to(found_path)} to #{relative_path_to(install_path)}" }
39
- FileUtils.cp_r(found_path, install_path)
40
- end
41
-
42
- def manifest_data(name)
43
- @manifest_data ||= { }
44
- @manifest_data[name] ||= fetch_manifest_data(name)
45
- end
46
-
47
- def fetch_manifest_data(name)
48
- expect_manifest!(name)
49
-
50
- found_path = found_path(name)
51
- manifest_path = ManifestReader.manifest_path(found_path)
52
- ManifestReader.read_manifest(name, manifest_path)
53
- end
54
-
55
- def manifest?(name, path)
56
- ManifestReader.manifest?(name, path)
57
- end
58
-
59
- def expect_manifest!(name)
60
- found_path = found_path(name)
61
- return if found_path && ManifestReader.manifest_path(found_path)
62
-
63
- raise Error, "No metadata file found for #{name} from #{self}! If this should be a cookbook, you might consider contributing a metadata file upstream or forking the cookbook to add your own metadata file."
64
- end
65
-
66
- end
67
- end
68
- end
69
- end
@@ -1,12 +0,0 @@
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
@@ -1,452 +0,0 @@
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
- alias :eql? :==
367
-
368
- def hash
369
- self.to_s.hash
370
- end
371
-
372
- def to_spec_args
373
- [uri, {}]
374
- end
375
-
376
- def to_lock_options
377
- {:remote => uri}
378
- end
379
-
380
- def pinned?
381
- false
382
- end
383
-
384
- def unpin!
385
- end
386
-
387
- def install!(manifest)
388
- manifest.source == self or raise ArgumentError
389
-
390
- name = manifest.name
391
- version = manifest.version
392
- install_path = install_path(name)
393
- line = line(name)
394
-
395
- info { "Installing #{manifest.name} (#{manifest.version})" }
396
-
397
- debug { "Installing #{manifest}" }
398
-
399
- line.install_version! version, install_path
400
- end
401
-
402
- # NOTE:
403
- # Assumes the Opscode Site API responds with versions in reverse sorted order
404
- def manifests(name)
405
- line(name).manifests
406
- end
407
-
408
- def manifest(name, version, dependencies)
409
- manifest = Manifest.new(self, name)
410
- manifest.version = version
411
- manifest.dependencies = dependencies
412
- manifest
413
- end
414
-
415
- def cache_path
416
- @cache_path ||= begin
417
- dir = Digest::MD5.hexdigest(uri)
418
- environment.cache_path.join("source/chef/site/#{dir}")
419
- end
420
- end
421
-
422
- def install_path(name)
423
- environment.install_path.join(name)
424
- end
425
-
426
- def fetch_version(name, version_uri)
427
- line(name).to_version(version_uri)
428
- end
429
-
430
- def fetch_dependencies(name, version, version_uri)
431
- line(name).version_dependencies(version).map{|k, v| Dependency.new(k, v, nil)}
432
- end
433
-
434
- private
435
-
436
- def line(name)
437
- @line ||= { }
438
- @line[name] ||= Line.new(self, name)
439
- end
440
-
441
- def info(*args, &block)
442
- environment.logger.info(*args, &block)
443
- end
444
-
445
- def debug(*args, &block)
446
- environment.logger.debug(*args, &block)
447
- end
448
-
449
- end
450
- end
451
- end
452
- end