puppet-library 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -7
- data/.simplecov +2 -1
- data/CHANGELOG.yml +4 -0
- data/Guardfile +1 -1
- data/README.md +8 -0
- data/Rakefile +2 -2
- data/TODO.yml +2 -0
- data/lib/puppet_library/archive/archive_reader.rb +33 -0
- data/lib/puppet_library/archive/archiver.rb +92 -0
- data/lib/puppet_library/archive.rb +20 -0
- data/lib/puppet_library/forge/directory.rb +4 -6
- data/lib/puppet_library/forge/multi.rb +9 -10
- data/lib/puppet_library/forge/proxy.rb +2 -2
- data/lib/puppet_library/forge/source.rb +69 -0
- data/lib/puppet_library/forge.rb +1 -0
- data/lib/puppet_library/http/cache/noop.rb +3 -5
- data/lib/puppet_library/puppet_library.rb +6 -1
- data/lib/puppet_library/puppet_module/modulefile.rb +68 -0
- data/lib/puppet_library/puppet_module.rb +19 -0
- data/lib/puppet_library/server.rb +13 -10
- data/lib/puppet_library/version.rb +1 -1
- data/lib/puppet_library.rb +2 -0
- data/puppet-library.gemspec +2 -2
- data/spec/archive/archive_reader_spec.rb +64 -0
- data/spec/archive/archiver_spec.rb +66 -0
- data/spec/forge/source_spec.rb +133 -0
- data/spec/module_spec_helper.rb +6 -0
- data/spec/puppet_library_spec.rb +14 -0
- data/spec/puppet_module/modulefile_spec.rb +106 -0
- data/spec/spec_helper.rb +32 -0
- data/test/librarian_puppet_integration_test.rb +75 -2
- metadata +285 -114
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
5
|
-
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 957de9eb484e3ec881a524fe467b6ceab2575f34
|
4
|
+
data.tar.gz: b3a3dbc2610ec8fcdc1064f9b745ea5ba9539e3d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9c8bf309ca1363ea52d83d144a1aea682c236c10a00ee7520a62608771f37d2cbfb7d16eb9f1267fd06ad4127aae612b2b1c0d042532a64999bfae8d27d69040
|
7
|
+
data.tar.gz: 965b766bcc9d58bc6939ba454a937469a5db4fc9f23b82a2dfbce089bc5b3c4817583379a2444131b94a44506b74de66e2ba9bf2a53a2627639ceb18eef1093c
|
data/.simplecov
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
# Puppet Library
|
3
|
-
# Copyright (C)
|
3
|
+
# Copyright (C) 2014 drrb
|
4
4
|
#
|
5
5
|
# This program is free software: you can redistribute it and/or modify
|
6
6
|
# it under the terms of the GNU General Public License as published by
|
@@ -17,5 +17,6 @@
|
|
17
17
|
|
18
18
|
SimpleCov.start do
|
19
19
|
add_filter "/spec/"
|
20
|
+
add_filter "/test/"
|
20
21
|
add_filter "/features/"
|
21
22
|
end
|
data/CHANGELOG.yml
CHANGED
@@ -52,4 +52,8 @@
|
|
52
52
|
- Fixed issue with forge proxying (#1)
|
53
53
|
- tag: v0.8.0
|
54
54
|
changes:
|
55
|
+
- Fixed issue with downloads (#2)
|
55
56
|
- Fixed issue with directory-based forges on Ruby 1.8 (#3)
|
57
|
+
- tag: v0.9.0
|
58
|
+
changes:
|
59
|
+
- Added new source forge that serves modules from directories on disk
|
data/Guardfile
CHANGED
data/README.md
CHANGED
@@ -15,6 +15,7 @@ Plugins can be created to serve modules from arbitrary sources. Puppet Library c
|
|
15
15
|
- serving packaged (`.tar.gz`) modules from a directory (or directories) of your choosing
|
16
16
|
- proxying a remote forge (or forges)
|
17
17
|
- caching proxied forges to disk
|
18
|
+
- serving modules from source on disk
|
18
19
|
|
19
20
|
## Installation
|
20
21
|
|
@@ -71,6 +72,10 @@ Proxy a remote forge, caching downloaded modules on disk
|
|
71
72
|
|
72
73
|
$ puppet-library --proxy http://forge.puppetlabs.com --cache-basedir
|
73
74
|
|
75
|
+
Serve a module from source
|
76
|
+
|
77
|
+
$ puppet-library --source-dir ~/code/puppetlabs-apache
|
78
|
+
|
74
79
|
Serve modules on a specific port
|
75
80
|
|
76
81
|
$ puppet-library --port 8888
|
@@ -84,6 +89,7 @@ See all options
|
|
84
89
|
Puppet Library contains built-in support for:
|
85
90
|
- serving packaged (`.tar.gz`) modules from a directory (or directories) of your choosing
|
86
91
|
- proxying a remote forge (or forges)
|
92
|
+
- serving modules from source on disk
|
87
93
|
- serving modules from a combination of the above
|
88
94
|
|
89
95
|
## Compatibility with other tools
|
@@ -118,6 +124,8 @@ daemonize: true
|
|
118
124
|
pidfile: /var/run/puppetlibrary.pid
|
119
125
|
forges:
|
120
126
|
- Directory: /var/lib/modules
|
127
|
+
- Directory: /var/lib/other-modules
|
128
|
+
- Source: /var/code/puppetlabs-apache
|
121
129
|
- Proxy: http://forge.puppetlabs.com
|
122
130
|
```
|
123
131
|
|
data/Rakefile
CHANGED
@@ -23,10 +23,10 @@ require 'yaml'
|
|
23
23
|
require 'net/http'
|
24
24
|
|
25
25
|
SUPPORTED_RUBY_VERSIONS = %w[1.8 1.9 2.0 2.1 system]
|
26
|
-
#
|
26
|
+
# Puppet doesn't work on 2.1
|
27
27
|
INTEGRATION_TEST_INCOMPATIBLE_RUBY_VERSIONS = %w[2.1]
|
28
28
|
# Capybara needs Nokogiri, which needs 1.9+
|
29
|
-
ACCEPTANCE_TEST_INCOMPATIBLE_RUBY_VERSIONS = %w[1.8
|
29
|
+
ACCEPTANCE_TEST_INCOMPATIBLE_RUBY_VERSIONS = %w[1.8]
|
30
30
|
|
31
31
|
class String
|
32
32
|
def green
|
data/TODO.yml
CHANGED
@@ -9,8 +9,10 @@ features:
|
|
9
9
|
- clear proxy cache (web form and API)
|
10
10
|
- delete modules from disk (web form)
|
11
11
|
- Authentication
|
12
|
+
- Make imports work properly from pry, and other projects
|
12
13
|
|
13
14
|
dubious_features:
|
15
|
+
- Proxy modules' source in a directory (supported individually for now: should we just leave it that way?)
|
14
16
|
- Make proxy cache TTL configurable
|
15
17
|
- Allow failover between module repositories
|
16
18
|
- Look in /etc/puppet-library.yml for config by default
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# Puppet Library
|
2
|
+
# Copyright (C) 2014 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 'rubygems/package'
|
18
|
+
require 'zlib'
|
19
|
+
|
20
|
+
module PuppetLibrary::Archive
|
21
|
+
class ArchiveReader
|
22
|
+
def initialize(path)
|
23
|
+
@path = path
|
24
|
+
end
|
25
|
+
|
26
|
+
def read_entry(entry_name_regex)
|
27
|
+
tar = Gem::Package::TarReader.new(Zlib::GzipReader.open(@path))
|
28
|
+
tar.rewind
|
29
|
+
entry = tar.find {|e| e.full_name =~ entry_name_regex } or raise "Couldn't find entry in archive"
|
30
|
+
entry.read
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# Puppet Library
|
2
|
+
# Copyright (C) 2014 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 'rubygems/package'
|
18
|
+
require 'zlib'
|
19
|
+
|
20
|
+
module PuppetLibrary::Archive
|
21
|
+
# Adapted from https://gist.github.com/sinisterchipmunk/1335041
|
22
|
+
module Archiver
|
23
|
+
def self.archive_dir(dir, basedir, &block)
|
24
|
+
gzip(tar(dir, basedir, &block))
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
# gzips the underlying string in the given StringIO,
|
29
|
+
# returning a new StringIO representing the
|
30
|
+
# compressed file.
|
31
|
+
def self.gzip(tar_buffer)
|
32
|
+
zip_buffer = StringIO.new("")
|
33
|
+
zipper = Zlib::GzipWriter.new(zip_buffer)
|
34
|
+
zipper.write tar_buffer.string
|
35
|
+
zipper.close # this is necessary!
|
36
|
+
# z was closed to write the gzip footer, so
|
37
|
+
# now we need a new StringIO
|
38
|
+
StringIO.new zip_buffer.string
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.tar(path, basedir, &block)
|
42
|
+
tarfile = StringIO.new("")
|
43
|
+
Gem::Package::TarWriter.new(tarfile) do |tar|
|
44
|
+
walk_directory(path) do |file|
|
45
|
+
entry_name = file.sub /^#{Regexp::escape path}\/?/, "#{basedir}/"
|
46
|
+
TarEntry.from(file).add_to!(tar, entry_name)
|
47
|
+
end
|
48
|
+
yield(RebasedTar.new(tar, basedir)) if block_given?
|
49
|
+
end
|
50
|
+
tarfile.rewind
|
51
|
+
tarfile
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.walk_directory(basedir)
|
55
|
+
Dir[File.join(basedir, "**/*")].each do |file|
|
56
|
+
yield(file)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
class RebasedTar
|
61
|
+
def initialize(tar, basedir)
|
62
|
+
@tar, @basedir = tar, basedir
|
63
|
+
end
|
64
|
+
|
65
|
+
def add_file(name, mode, &block)
|
66
|
+
entry_name = name.sub /^\/?/, "#{@basedir}/"
|
67
|
+
@tar.add_file(entry_name, mode, &block)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
class TarEntry
|
72
|
+
def self.from(file)
|
73
|
+
TarEntry.new(file)
|
74
|
+
end
|
75
|
+
|
76
|
+
def initialize(file)
|
77
|
+
@file = file
|
78
|
+
end
|
79
|
+
|
80
|
+
def add_to!(tar, entry_name)
|
81
|
+
mode = File.stat(@file).mode
|
82
|
+
if File.directory?(@file)
|
83
|
+
tar.mkdir(entry_name, mode)
|
84
|
+
else
|
85
|
+
tar.add_file(entry_name, mode) do |entry|
|
86
|
+
File.open(@file, "rb") { |file| entry.write file.read }
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# Puppet Library
|
2
|
+
# Copyright (C) 2014 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
|
+
module PuppetLibrary::Archive
|
18
|
+
require 'puppet_library/archive/archiver'
|
19
|
+
require 'puppet_library/archive/archive_reader'
|
20
|
+
end
|
@@ -15,9 +15,8 @@
|
|
15
15
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
16
|
|
17
17
|
require 'json'
|
18
|
-
require 'rubygems/package'
|
19
|
-
require 'zlib'
|
20
18
|
require 'puppet_library/forge/abstract'
|
19
|
+
require 'puppet_library/archive/archive_reader'
|
21
20
|
|
22
21
|
module PuppetLibrary::Forge
|
23
22
|
class Directory < PuppetLibrary::Forge::Abstract
|
@@ -40,10 +39,9 @@ module PuppetLibrary::Forge
|
|
40
39
|
|
41
40
|
def get_metadata(author = "*", module_name = "")
|
42
41
|
Dir["#{@module_dir}/#{author}-#{module_name}*"].map do |module_path|
|
43
|
-
|
44
|
-
|
45
|
-
metadata_file
|
46
|
-
JSON.parse(metadata_file.read)
|
42
|
+
archive = PuppetLibrary::Archive::ArchiveReader.new(module_path)
|
43
|
+
metadata_file = archive.read_entry %r[[^/]+/metadata\.json$]
|
44
|
+
JSON.parse(metadata_file)
|
47
45
|
end
|
48
46
|
end
|
49
47
|
|
@@ -19,12 +19,16 @@ require 'puppet_library/forge/search_result'
|
|
19
19
|
|
20
20
|
module PuppetLibrary::Forge
|
21
21
|
class Multi
|
22
|
+
def initialize
|
23
|
+
@forges = []
|
24
|
+
end
|
25
|
+
|
22
26
|
def add_forge(forge)
|
23
|
-
forges << forge
|
27
|
+
@forges << forge
|
24
28
|
end
|
25
29
|
|
26
30
|
def search_modules(query)
|
27
|
-
all_results = forges.map do |forge|
|
31
|
+
all_results = @forges.map do |forge|
|
28
32
|
forge.search_modules(query)
|
29
33
|
end.flatten
|
30
34
|
|
@@ -32,7 +36,7 @@ module PuppetLibrary::Forge
|
|
32
36
|
end
|
33
37
|
|
34
38
|
def get_module_buffer(author, name, version)
|
35
|
-
forges.each do |forge|
|
39
|
+
@forges.each do |forge|
|
36
40
|
begin
|
37
41
|
return forge.get_module_buffer(author, name, version)
|
38
42
|
rescue ModuleNotFound
|
@@ -43,7 +47,7 @@ module PuppetLibrary::Forge
|
|
43
47
|
end
|
44
48
|
|
45
49
|
def get_module_metadata(author, name)
|
46
|
-
metadata_list = forges.inject([]) do |metadata_list, forge|
|
50
|
+
metadata_list = @forges.inject([]) do |metadata_list, forge|
|
47
51
|
begin
|
48
52
|
metadata_list << forge.get_module_metadata(author, name)
|
49
53
|
rescue ModuleNotFound
|
@@ -58,7 +62,7 @@ module PuppetLibrary::Forge
|
|
58
62
|
|
59
63
|
def get_module_metadata_with_dependencies(author, name, version)
|
60
64
|
metadata_list = []
|
61
|
-
forges.each do |forge|
|
65
|
+
@forges.each do |forge|
|
62
66
|
begin
|
63
67
|
metadata_list << forge.get_module_metadata_with_dependencies(author, name, version)
|
64
68
|
rescue ModuleNotFound
|
@@ -72,10 +76,5 @@ module PuppetLibrary::Forge
|
|
72
76
|
end
|
73
77
|
end
|
74
78
|
end
|
75
|
-
|
76
|
-
private
|
77
|
-
def forges
|
78
|
-
@forges ||= []
|
79
|
-
end
|
80
79
|
end
|
81
80
|
end
|
@@ -79,12 +79,12 @@ module PuppetLibrary::Forge
|
|
79
79
|
versions["#{author}/#{name}"]
|
80
80
|
end
|
81
81
|
|
82
|
-
def look_up_releases(author, name, version = nil, &
|
82
|
+
def look_up_releases(author, name, version = nil, &optional_processor)
|
83
83
|
version_query = version ? "&version=#{version}" : ""
|
84
84
|
url = "/api/v1/releases.json?module=#{author}/#{name}#{version_query}"
|
85
85
|
response_text = get(url)
|
86
86
|
response = JSON.parse(response_text)
|
87
|
-
process_releases_response(response, &
|
87
|
+
process_releases_response(response, &optional_processor)
|
88
88
|
end
|
89
89
|
|
90
90
|
def process_releases_response(response)
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# Puppet Library
|
2
|
+
# Copyright (C) 2014 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 'puppet_library/archive/archiver'
|
18
|
+
require 'puppet_library/puppet_module/modulefile'
|
19
|
+
require 'json'
|
20
|
+
|
21
|
+
module PuppetLibrary::Forge
|
22
|
+
class Source < PuppetLibrary::Forge::Abstract
|
23
|
+
CACHE_TTL_MILLIS = 500
|
24
|
+
def initialize(module_dir)
|
25
|
+
super(self)
|
26
|
+
module_dir = File.expand_path(module_dir)
|
27
|
+
raise "Module directory '#{module_dir}' doesn't exist" unless File.directory? module_dir
|
28
|
+
raise "Module directory '#{module_dir}' isn't readable" unless File.executable? module_dir
|
29
|
+
@module_dir = module_dir
|
30
|
+
@cache = PuppetLibrary::Http::Cache::InMemory.new(CACHE_TTL_MILLIS)
|
31
|
+
end
|
32
|
+
|
33
|
+
def get_module(author, name, version)
|
34
|
+
return nil unless this_module?(author, name, version)
|
35
|
+
PuppetLibrary::Archive::Archiver.archive_dir(@module_dir, "#{author}-#{name}-#{version}") do |archive|
|
36
|
+
archive.add_file("metadata.json", 0644) do |entry|
|
37
|
+
entry.write modulefile.to_metadata
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def get_metadata(author, module_name)
|
43
|
+
return [] unless this_module?(author, module_name)
|
44
|
+
[ modulefile.to_metadata ]
|
45
|
+
end
|
46
|
+
|
47
|
+
def get_all_metadata
|
48
|
+
get_metadata(modulefile.get_author, modulefile.get_simple_name)
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
def this_module?(author, module_name, version = nil)
|
53
|
+
same_module = modulefile.get_name == "#{author}-#{module_name}"
|
54
|
+
if version.nil?
|
55
|
+
return same_module
|
56
|
+
else
|
57
|
+
return same_module && modulefile.get_version == version
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def modulefile
|
62
|
+
modulefile_path = File.join(@module_dir, "Modulefile")
|
63
|
+
@cache.get modulefile_path do
|
64
|
+
PuppetLibrary::PuppetModule::Modulefile.read(modulefile_path)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
data/lib/puppet_library/forge.rb
CHANGED
@@ -18,11 +18,9 @@
|
|
18
18
|
require 'puppet_library/http/cache/in_memory'
|
19
19
|
|
20
20
|
module PuppetLibrary::Http::Cache
|
21
|
-
class NoOp
|
22
|
-
def
|
23
|
-
|
24
|
-
|
25
|
-
def retrieve(key)
|
21
|
+
class NoOp
|
22
|
+
def get(path)
|
23
|
+
yield
|
26
24
|
end
|
27
25
|
end
|
28
26
|
end
|
@@ -19,6 +19,8 @@ require 'rack'
|
|
19
19
|
require 'yaml'
|
20
20
|
require 'puppet_library/forge/directory'
|
21
21
|
require 'puppet_library/forge/multi'
|
22
|
+
require 'puppet_library/forge/proxy'
|
23
|
+
require 'puppet_library/forge/source'
|
22
24
|
require 'puppet_library/version'
|
23
25
|
|
24
26
|
module PuppetLibrary
|
@@ -70,12 +72,15 @@ module PuppetLibrary
|
|
70
72
|
end
|
71
73
|
|
72
74
|
options[:forges] = []
|
73
|
-
opts.on("-m", "--module-dir DIR", "Directory containing
|
75
|
+
opts.on("-m", "--module-dir DIR", "Directory containing packaged modules (can be specified multiple times)") do |module_dir|
|
74
76
|
options[:forges] << [Forge::Directory, module_dir]
|
75
77
|
end
|
76
78
|
opts.on("-x", "--proxy URL", "Remote forge to proxy (can be specified multiple times)") do |url|
|
77
79
|
options[:forges] << [Forge::Proxy, sanitize_url(url)]
|
78
80
|
end
|
81
|
+
opts.on("--source-dir DIR", "Directory containing a module's source (can be specified multiple times)") do |module_dir|
|
82
|
+
options[:forges] << [Forge::Source, module_dir]
|
83
|
+
end
|
79
84
|
|
80
85
|
opts.on("--cache-basedir DIR", "Cache all proxies' downloaded modules under this directory") do |cache_basedir|
|
81
86
|
options[:cache_basedir] = cache_basedir
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# Puppet Library
|
2
|
+
# Copyright (C) 2014 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
|
+
module PuppetLibrary::PuppetModule
|
18
|
+
class Modulefile
|
19
|
+
def self.read(modulefile_path)
|
20
|
+
Modulefile.new.tap do |modulefile|
|
21
|
+
modulefile.instance_eval(File.read(modulefile_path))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
%w[name version author source summary description project_page license].each do |property|
|
26
|
+
class_eval <<-EOF
|
27
|
+
def #{property}(value)
|
28
|
+
@#{property} = value
|
29
|
+
end
|
30
|
+
|
31
|
+
def get_#{property}
|
32
|
+
@#{property}
|
33
|
+
end
|
34
|
+
EOF
|
35
|
+
end
|
36
|
+
|
37
|
+
def dependency(name, spec)
|
38
|
+
get_dependencies.push("name" => name, "version_requirement" => spec)
|
39
|
+
end
|
40
|
+
|
41
|
+
def get_dependencies
|
42
|
+
@dependencies ||= []
|
43
|
+
end
|
44
|
+
|
45
|
+
def get_simple_name
|
46
|
+
@name.split("-").last
|
47
|
+
end
|
48
|
+
|
49
|
+
def method_missing(name, *args, &block)
|
50
|
+
Modulefile.log "Unsupported config parsed from Modulefile: #{name}(#{args.join", "})"
|
51
|
+
end
|
52
|
+
|
53
|
+
def to_metadata
|
54
|
+
{
|
55
|
+
"name" => get_name,
|
56
|
+
"version" => get_version,
|
57
|
+
"author" => get_author,
|
58
|
+
"description" => get_description,
|
59
|
+
"dependencies" => get_dependencies
|
60
|
+
}
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
def self.log(message)
|
65
|
+
puts message
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Puppet Library
|
2
|
+
# Copyright (C) 2014 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
|
+
module PuppetLibrary::PuppetModule
|
18
|
+
require 'puppet_library/puppet_module/modulefile'
|
19
|
+
end
|
@@ -82,8 +82,7 @@ module PuppetLibrary
|
|
82
82
|
begin
|
83
83
|
@forge.get_module_metadata_with_dependencies(author, module_name, version).to_json
|
84
84
|
rescue Forge::ModuleNotFound
|
85
|
-
|
86
|
-
{"error" => "Module #{author}/#{module_name} not found"}.to_json
|
85
|
+
halt 410, {"error" => "Module #{author}/#{module_name} not found"}.to_json
|
87
86
|
end
|
88
87
|
end
|
89
88
|
|
@@ -98,12 +97,7 @@ module PuppetLibrary
|
|
98
97
|
buffer = @forge.get_module_buffer(author, name, version).tap do
|
99
98
|
attachment "#{author}-#{name}-#{version}.tar.gz"
|
100
99
|
end
|
101
|
-
|
102
|
-
headers = { "Content-Length" => buffer.size.to_s }
|
103
|
-
else
|
104
|
-
headers = {}
|
105
|
-
end
|
106
|
-
[ 200, headers, buffer ]
|
100
|
+
download buffer
|
107
101
|
rescue Forge::ModuleNotFound
|
108
102
|
halt 404
|
109
103
|
end
|
@@ -117,9 +111,18 @@ module PuppetLibrary
|
|
117
111
|
metadata = @forge.get_module_metadata(author, module_name)
|
118
112
|
haml :module, { :locals => { "metadata" => metadata } }
|
119
113
|
rescue Forge::ModuleNotFound
|
120
|
-
|
121
|
-
|
114
|
+
halt 404, haml(:module_not_found, { :locals => { "author" => author, "name" => module_name } })
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
private
|
119
|
+
def download(buffer)
|
120
|
+
if buffer.respond_to?(:size)
|
121
|
+
headers = { "Content-Length" => buffer.size.to_s }
|
122
|
+
else
|
123
|
+
headers = {}
|
122
124
|
end
|
125
|
+
[ 200, headers, buffer ]
|
123
126
|
end
|
124
127
|
end
|
125
128
|
end
|
data/lib/puppet_library.rb
CHANGED
@@ -16,9 +16,11 @@
|
|
16
16
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
17
|
|
18
18
|
module PuppetLibrary
|
19
|
+
require 'puppet_library/archive'
|
19
20
|
require 'puppet_library/forge'
|
20
21
|
require 'puppet_library/http'
|
21
22
|
require 'puppet_library/puppet_library'
|
23
|
+
require 'puppet_library/puppet_module'
|
22
24
|
require 'puppet_library/server'
|
23
25
|
require 'puppet_library/util'
|
24
26
|
require 'puppet_library/version'
|
data/puppet-library.gemspec
CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.version = PuppetLibrary::VERSION
|
25
25
|
spec.authors = ["drrb"]
|
26
26
|
spec.email = ["drrrrrrrrrrrb@gmail.com"]
|
27
|
-
spec.description = "A Puppet
|
27
|
+
spec.description = "A private Puppet forge"
|
28
28
|
spec.summary = <<-EOF
|
29
29
|
Puppet Library is a private Puppet module server that's compatible with librarian-puppet.
|
30
30
|
EOF
|
@@ -43,7 +43,7 @@ Gem::Specification.new do |spec|
|
|
43
43
|
spec.add_development_dependency "bundler", "~> 1.3"
|
44
44
|
spec.add_development_dependency "coveralls"
|
45
45
|
spec.add_development_dependency "gitsu"
|
46
|
-
spec.add_development_dependency "librarian-puppet"
|
46
|
+
spec.add_development_dependency "librarian-puppet", "0.9.10" # 0.9.12 breaks on Ruby 1.8.7
|
47
47
|
spec.add_development_dependency "mime-types", "< 2"
|
48
48
|
spec.add_development_dependency "pry"
|
49
49
|
spec.add_development_dependency "puppet", "~> 3.3.0"
|