librarian-puppet-maestrodev 0.9.9.6 → 0.9.9.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/librarian/puppet/source/forge.rb +24 -46
- data/lib/librarian/puppet/version.rb +1 -1
- metadata +4 -4
@@ -1,6 +1,5 @@
|
|
1
|
-
require 'uri'
|
2
|
-
require 'net/http'
|
3
1
|
require 'json'
|
2
|
+
require 'open-uri'
|
4
3
|
|
5
4
|
module Librarian
|
6
5
|
module Puppet
|
@@ -8,35 +7,26 @@ module Librarian
|
|
8
7
|
class Forge
|
9
8
|
class Repo
|
10
9
|
|
11
|
-
attr_accessor :source, :name
|
12
|
-
private :source=, :name=
|
10
|
+
attr_accessor :source, :name, :versions, :api_data
|
11
|
+
private :source=, :name=, :versions=, :api_data, :api_data=
|
13
12
|
|
14
13
|
def initialize(source, name)
|
15
14
|
self.source = source
|
16
15
|
self.name = name
|
17
|
-
@dependencies = {}
|
18
|
-
end
|
19
16
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
if data.nil?
|
17
|
+
# call API and cache data
|
18
|
+
self.api_data = api_call(name)
|
19
|
+
if api_data.nil?
|
24
20
|
raise Error, "Unable to find module '#{name}' on #{source}"
|
25
21
|
end
|
26
|
-
|
27
|
-
versions = data['releases'].map { |r| r['version'] }
|
22
|
+
versions = api_data[name].map { |r| r['version'] }.reverse
|
28
23
|
debug { " Module #{name} found versions: #{versions.join(", ")}" }
|
29
24
|
versions.select { |v| ! Gem::Version.correct? v }.each { |v| debug { "Ignoring invalid version '#{v}' for module #{name}" } }
|
30
|
-
|
25
|
+
self.versions = versions.select { |v| Gem::Version.correct? v }
|
31
26
|
end
|
32
27
|
|
33
28
|
def dependencies(version)
|
34
|
-
|
35
|
-
data = api_call("api/v1/releases.json?module=#{name}&version=#{version}")
|
36
|
-
if data.nil?
|
37
|
-
raise Error, "Unable to find version #{version} for module '#{name}' on #{source}"
|
38
|
-
end
|
39
|
-
@dependencies[version] = data[name].first['dependencies']
|
29
|
+
api_data[name].detect{|x| x['version'] == version.to_s}['dependencies']
|
40
30
|
end
|
41
31
|
|
42
32
|
def manifests
|
@@ -133,46 +123,34 @@ module Librarian
|
|
133
123
|
end
|
134
124
|
|
135
125
|
def vendor_cache(name, version)
|
126
|
+
info = api_data[name].detect {|h| h['version'] == version.to_s }
|
136
127
|
File.open(vendored_path(name, version).to_s, 'w') do |f|
|
137
|
-
|
138
|
-
|
128
|
+
open("#{source}#{info['file']}") do |input|
|
129
|
+
while (buffer = input.read)
|
130
|
+
f.write(buffer)
|
131
|
+
end
|
139
132
|
end
|
140
133
|
end
|
141
134
|
end
|
142
135
|
|
143
|
-
def download(name, version, &block)
|
144
|
-
data = api_call("api/v1/releases.json?module=#{name}&version=#{version}")
|
145
|
-
|
146
|
-
info = data[name].detect {|h| h['version'] == version.to_s }
|
147
|
-
|
148
|
-
stream(info['file'], &block)
|
149
|
-
end
|
150
|
-
|
151
|
-
def stream(file, &block)
|
152
|
-
Net::HTTP.get_response(URI.parse("#{source}#{file}")) do |res|
|
153
|
-
res.code
|
154
|
-
|
155
|
-
res.read_body(&block)
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
136
|
def debug(*args, &block)
|
160
137
|
environment.logger.debug(*args, &block)
|
161
138
|
end
|
162
139
|
|
163
140
|
private
|
164
141
|
|
165
|
-
def api_call(
|
142
|
+
def api_call(module_name)
|
166
143
|
base_url = source.uri
|
167
|
-
|
168
|
-
|
169
|
-
when 404,410
|
170
|
-
nil
|
171
|
-
when 200
|
172
|
-
data = resp.body
|
144
|
+
begin
|
145
|
+
data = open("#{base_url}/api/v1/releases.json?module=#{module_name}") {|f| f.read}
|
173
146
|
JSON.parse(data)
|
174
|
-
|
175
|
-
|
147
|
+
rescue OpenURI::HTTPError => e
|
148
|
+
case e.io.status[0].to_i
|
149
|
+
when 404,410
|
150
|
+
nil
|
151
|
+
else
|
152
|
+
raise e, "Error requesting #{base_url}/#{path}: #{e.to_s}"
|
153
|
+
end
|
176
154
|
end
|
177
155
|
end
|
178
156
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: librarian-puppet-maestrodev
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.9.
|
4
|
+
version: 0.9.9.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-07-
|
12
|
+
date: 2013-07-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: librarian
|
@@ -149,7 +149,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
149
149
|
version: '0'
|
150
150
|
segments:
|
151
151
|
- 0
|
152
|
-
hash: -
|
152
|
+
hash: -3641701570484774639
|
153
153
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
154
|
none: false
|
155
155
|
requirements:
|
@@ -158,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
158
|
version: '0'
|
159
159
|
segments:
|
160
160
|
- 0
|
161
|
-
hash: -
|
161
|
+
hash: -3641701570484774639
|
162
162
|
requirements: []
|
163
163
|
rubyforge_project:
|
164
164
|
rubygems_version: 1.8.25
|