puppet-library 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,50 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # Puppet Library
3
+ # Copyright (C) 2013 drrb
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ lib = File.expand_path('../lib', __FILE__)
19
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
20
+ require 'puppet_library/version'
21
+
22
+ Gem::Specification.new do |spec|
23
+ spec.name = "puppet-library"
24
+ spec.version = PuppetLibrary::VERSION
25
+ spec.authors = ["drrb"]
26
+ spec.email = ["drrrrrrrrrrrb@gmail.com"]
27
+ spec.description = "A Puppet module server"
28
+ spec.summary = <<-EOF
29
+ Puppet Library is a private Puppet module server that's compatible with librarian-puppet.
30
+ EOF
31
+ spec.homepage = "https://github.com/drrb/puppet-library"
32
+ spec.license = "GPL-3"
33
+
34
+ spec.files = `git ls-files`.split($/)
35
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
36
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
37
+ spec.require_paths = ["lib"]
38
+
39
+ spec.add_dependency "sinatra"
40
+ spec.add_dependency "json"
41
+
42
+ spec.add_development_dependency "bundler", "~> 1.3"
43
+ spec.add_development_dependency "coveralls"
44
+ spec.add_development_dependency "mime-types", "< 2"
45
+ spec.add_development_dependency "pry"
46
+ spec.add_development_dependency "rack-test"
47
+ spec.add_development_dependency "rake"
48
+ spec.add_development_dependency "rspec"
49
+ spec.add_development_dependency "simplecov"
50
+ end
@@ -0,0 +1,80 @@
1
+ # Puppet Library
2
+ # Copyright (C) 2013 drrb
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ require 'spec_helper'
18
+
19
+ module PuppetLibrary
20
+ describe ModuleRepo do
21
+ include ModuleSpecHelper
22
+
23
+ let(:module_dir) { "/tmp/#{$$}" }
24
+ let(:module_repo) { ModuleRepo.new(module_dir) }
25
+
26
+ before do
27
+ FileUtils.mkdir_p module_dir
28
+ end
29
+
30
+ after do
31
+ FileUtils.rm_rf module_dir
32
+ end
33
+
34
+ describe "#get_module" do
35
+ context "when the module archive exists" do
36
+ before do
37
+ add_module("puppetlabs", "apache", "1.0.0")
38
+ end
39
+
40
+ it "returns a the module archive as a file buffer" do
41
+ buffer = module_repo.get_module("puppetlabs", "apache", "1.0.0")
42
+
43
+ expect(buffer.path).to end_with("puppetlabs-apache-1.0.0.tar.gz")
44
+ end
45
+ end
46
+
47
+ context "when the module file doesn't exist" do
48
+ it "returns nil" do
49
+ buffer = module_repo.get_module("puppetlabs", "noneixstant", "1.0.0")
50
+
51
+ expect(buffer).to be_nil
52
+ end
53
+ end
54
+ end
55
+
56
+ describe "#get_metadata" do
57
+ context "when the module directory is empty" do
58
+ it "returns an empty array" do
59
+ metadata_list = module_repo.get_metadata("puppetlabs", "apache")
60
+ expect(metadata_list).to be_empty
61
+ end
62
+ end
63
+
64
+ context "when the module directory contains the requested module" do
65
+ before do
66
+ add_module("puppetlabs", "apache", "1.0.0")
67
+ add_module("puppetlabs", "apache", "1.1.0")
68
+ end
69
+
70
+ it "returns an array containing the module's versions' metadata" do
71
+ metadata_list = module_repo.get_metadata("puppetlabs", "apache")
72
+ expect(metadata_list.size).to eq 2
73
+ metadata_list = metadata_list.sort_by {|m| m["version"] }
74
+ expect(metadata_list[0]).to eq({ "name" => "puppetlabs-apache", "version" => "1.0.0" })
75
+ expect(metadata_list[1]).to eq({ "name" => "puppetlabs-apache", "version" => "1.1.0" })
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,51 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # Puppet Library
3
+ # Copyright (C) 2013 drrb
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ require 'zlib'
19
+ require 'rubygems/package'
20
+
21
+ module ModuleSpecHelper
22
+ def write_tar_gzip(file_name)
23
+ tar = StringIO.new
24
+
25
+ Gem::Package::TarWriter.new(tar) do |writer|
26
+ yield(writer)
27
+ end
28
+ tar.seek(0)
29
+
30
+ gz = Zlib::GzipWriter.new(File.new(file_name, 'wb'))
31
+ gz.write(tar.read)
32
+ tar.close
33
+ gz.close
34
+ end
35
+
36
+ def add_module(author, name, version)
37
+ full_name = "#{author}-#{name}"
38
+ fqn = "#{full_name}-#{version}"
39
+ module_file = File.join(module_dir, "#{fqn}.tar.gz")
40
+
41
+ write_tar_gzip(module_file) do |archive|
42
+ archive.add_file("#{fqn}/metadata.json", 0644) do |file|
43
+ content = {
44
+ "name" => full_name,
45
+ "version" => version
46
+ }
47
+ file.write content.to_json
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,170 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # Puppet Library
3
+ # Copyright (C) 2013 drrb
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ require "spec_helper"
19
+ require 'sinatra'
20
+ require 'rack/test'
21
+
22
+ module PuppetLibrary
23
+ describe Server do
24
+ include Rack::Test::Methods
25
+ include ModuleSpecHelper
26
+
27
+ let(:module_dir) { "/tmp/#{$$}" }
28
+ let(:module_repo) { double(ModuleRepo) }
29
+ let(:app) do
30
+ Server.new(module_repo)
31
+ end
32
+
33
+ before do
34
+ FileUtils.mkdir_p module_dir
35
+ end
36
+
37
+ after do
38
+ FileUtils.rm_rf module_dir
39
+ end
40
+
41
+ describe "GET /modules/<author>-<module>-<version>.tar.gz" do
42
+ context "when the module is on the server" do
43
+ before do
44
+ add_module("puppetlabs", "apache", "1.0.0")
45
+ end
46
+ it "serves the module" do
47
+ file_buffer = StringIO.new("module content")
48
+ expect(module_repo).to receive(:get_module).with("puppetlabs", "apache", "1.0.0").and_return(file_buffer)
49
+
50
+ get "/modules/puppetlabs-apache-1.0.0.tar.gz"
51
+
52
+ expect(last_response.body).to eq "module content"
53
+ expect(last_response.content_type).to eq "application/octet-stream"
54
+ expect(last_response.headers["Content-Disposition"]).to eq 'attachment; filename="puppetlabs-apache-1.0.0.tar.gz"'
55
+ expect(last_response).to be_ok
56
+ end
57
+ end
58
+
59
+ context "when the module is not on the server" do
60
+ it "returns an error" do
61
+ expect(module_repo).to receive(:get_module).with("puppetlabs", "apache", "1.0.0").and_return(nil)
62
+
63
+ get "/modules/puppetlabs-apache-1.0.0.tar.gz"
64
+
65
+ expect(last_response.content_type).to eq "application/octet-stream"
66
+ expect(last_response.status).to eq 404
67
+ end
68
+ end
69
+ end
70
+
71
+ describe "GET /<author>/<module>.json" do
72
+ it "gets module metadata for all versions" do
73
+ metadata = [ {
74
+ "author" => "puppetlabs",
75
+ "name" => "puppetlabs-apache",
76
+ "description" => "Apache module",
77
+ "version" => "1.0.0"
78
+ }, {
79
+ "author" => "puppetlabs",
80
+ "name" => "puppetlabs-apache",
81
+ "description" => "Apache module",
82
+ "version" => "1.1.0"
83
+ } ]
84
+ expect(module_repo).to receive(:get_metadata).with("puppetlabs", "apache").and_return(metadata)
85
+
86
+ get "/puppetlabs/apache.json"
87
+
88
+ expect(last_response.body).to include('"author":"puppetlabs"')
89
+ expect(last_response.body).to include('"full_name":"puppetlabs/apache"')
90
+ expect(last_response.body).to include('"name":"apache"')
91
+ expect(last_response.body).to include('"desc":"Apache module"')
92
+ expect(last_response.body).to include('"releases":[{"version":"1.0.0"},{"version":"1.1.0"}]')
93
+ expect(last_response).to be_ok
94
+ end
95
+
96
+ context "when no modules found" do
97
+ it "returns an error" do
98
+ expect(module_repo).to receive(:get_metadata).with("nonexistant", "nonexistant").and_return([])
99
+
100
+ get "/nonexistant/nonexistant.json"
101
+
102
+ expect(last_response.body).to eq('{"error":"Could not find module \"nonexistant\""}')
103
+ expect(last_response.status).to eq(410)
104
+ end
105
+ end
106
+ end
107
+
108
+ describe "GET /api/v1/releases.json" do
109
+ it "gets metadata for module and dependencies" do
110
+ apache_metadata = [ {
111
+ "author" => "puppetlabs",
112
+ "name" => "puppetlabs-apache",
113
+ "description" => "Apache module",
114
+ "version" => "1.0.0",
115
+ "dependencies" => [
116
+ { "name" => "puppetlabs/stdlib", "version_requirement" => ">= 2.4.0" },
117
+ { "name" => "puppetlabs/concat", "version_requirement" => ">= 1.0.0" }
118
+ ]
119
+ }, {
120
+ "author" => "puppetlabs",
121
+ "name" => "puppetlabs-apache",
122
+ "description" => "Apache module",
123
+ "version" => "1.1.0",
124
+ "dependencies" => [
125
+ { "name" => "puppetlabs/stdlib", "version_requirement" => ">= 2.4.0" },
126
+ { "name" => "puppetlabs/concat", "version_requirement" => ">= 1.0.0" }
127
+ ]
128
+ } ]
129
+ stdlib_metadata = [ {
130
+ "author" => "puppetlabs",
131
+ "name" => "puppetlabs-stdlib",
132
+ "description" => "Stdlib module",
133
+ "version" => "2.0.0",
134
+ "dependencies" => [ ]
135
+ } ]
136
+ concat_metadata = [ {
137
+ "author" => "puppetlabs",
138
+ "name" => "puppetlabs-concat",
139
+ "description" => "Concat module",
140
+ "version" => "1.0.0",
141
+ "dependencies" => [ ]
142
+ } ]
143
+ expect(module_repo).to receive(:get_metadata).with("puppetlabs", "apache").and_return(apache_metadata)
144
+ expect(module_repo).to receive(:get_metadata).with("puppetlabs", "stdlib").and_return(stdlib_metadata)
145
+ expect(module_repo).to receive(:get_metadata).with("puppetlabs", "concat").and_return(concat_metadata)
146
+
147
+ get "/api/v1/releases.json?module=puppetlabs/apache"
148
+
149
+ response = JSON.parse(last_response.body)
150
+ expect(response.keys.sort).to eq(["puppetlabs/apache", "puppetlabs/concat", "puppetlabs/stdlib"])
151
+ expect(response["puppetlabs/apache"].size).to eq(2)
152
+ expect(response["puppetlabs/apache"][0]["file"]).to eq("/modules/puppetlabs-apache-1.0.0.tar.gz")
153
+ expect(response["puppetlabs/apache"][0]["version"]).to eq("1.0.0")
154
+ expect(response["puppetlabs/apache"][0]["version"]).to eq("1.0.0")
155
+ expect(last_response).to be_ok
156
+ end
157
+
158
+ context "when the module can't be found" do
159
+ it "returns an error" do
160
+ expect(module_repo).to receive(:get_metadata).with("nonexistant", "nonexistant").and_return([])
161
+
162
+ get "/api/v1/releases.json?module=nonexistant/nonexistant"
163
+
164
+ expect(last_response.body).to eq('{"error":"Module nonexistant/nonexistant not found"}')
165
+ expect(last_response.status).to eq(410)
166
+ end
167
+ end
168
+ end
169
+ end
170
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # Puppet Library
3
+ # Copyright (C) 2013 drrb
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ require 'simplecov'
19
+ require 'puppet_library'
20
+ require 'module_spec_helper'
21
+ require 'pry'
metadata ADDED
@@ -0,0 +1,208 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: puppet-library
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - drrb
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sinatra
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: coveralls
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mime-types
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - <
74
+ - !ruby/object:Gem::Version
75
+ version: '2'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - <
81
+ - !ruby/object:Gem::Version
82
+ version: '2'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rack-test
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rake
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: simplecov
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: A Puppet module server
154
+ email:
155
+ - drrrrrrrrrrrb@gmail.com
156
+ executables:
157
+ - puppet-library
158
+ extensions: []
159
+ extra_rdoc_files: []
160
+ files:
161
+ - .gitignore
162
+ - .licenseignore
163
+ - .simplecov
164
+ - .travis.yml
165
+ - Gemfile
166
+ - LICENSE.txt
167
+ - README.md
168
+ - Rakefile
169
+ - bin/puppet-library
170
+ - config.ru
171
+ - lib/puppet_library.rb
172
+ - lib/puppet_library/module_repo.rb
173
+ - lib/puppet_library/server.rb
174
+ - lib/puppet_library/version.rb
175
+ - puppet-library.gemspec
176
+ - spec/module_repo_spec.rb
177
+ - spec/module_spec_helper.rb
178
+ - spec/server_spec.rb
179
+ - spec/spec_helper.rb
180
+ homepage: https://github.com/drrb/puppet-library
181
+ licenses:
182
+ - GPL-3
183
+ metadata: {}
184
+ post_install_message:
185
+ rdoc_options: []
186
+ require_paths:
187
+ - lib
188
+ required_ruby_version: !ruby/object:Gem::Requirement
189
+ requirements:
190
+ - - '>='
191
+ - !ruby/object:Gem::Version
192
+ version: '0'
193
+ required_rubygems_version: !ruby/object:Gem::Requirement
194
+ requirements:
195
+ - - '>='
196
+ - !ruby/object:Gem::Version
197
+ version: '0'
198
+ requirements: []
199
+ rubyforge_project:
200
+ rubygems_version: 2.0.3
201
+ signing_key:
202
+ specification_version: 4
203
+ summary: Puppet Library is a private Puppet module server that's compatible with librarian-puppet.
204
+ test_files:
205
+ - spec/module_repo_spec.rb
206
+ - spec/module_spec_helper.rb
207
+ - spec/server_spec.rb
208
+ - spec/spec_helper.rb