puppet-forge-server 1.4.3 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/puppet_forge_server.rb +1 -0
- data/lib/puppet_forge_server/api/v1/releases.rb +1 -3
- data/lib/puppet_forge_server/app/version3.rb +7 -4
- data/lib/puppet_forge_server/backends/directory.rb +8 -1
- data/lib/puppet_forge_server/backends/proxy.rb +8 -3
- data/lib/puppet_forge_server/backends/proxy_v1.rb +16 -5
- data/lib/puppet_forge_server/backends/proxy_v3.rb +16 -5
- data/lib/puppet_forge_server/logger.rb +2 -0
- data/lib/puppet_forge_server/models/builder.rb +10 -3
- data/lib/puppet_forge_server/models/dependency.rb +44 -0
- data/lib/puppet_forge_server/server.rb +8 -2
- data/lib/puppet_forge_server/version.rb +1 -1
- data/spec/unit/logger_spec.rb +1 -0
- data/spec/unit/models/dependency_spec.rb +46 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2f76a6ce28b85b7c576026282e4a7d17d98786c
|
4
|
+
data.tar.gz: 56f8489041c6e6e1dc255da8b1f258ae1fd6bc2e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5998e7d012207cc1acbfe5ae4b5e6cf9167c8839a591c29535016d7be70b1eacdfbd8d05c38c7e08861a9ecaa94f02eedf473fdf1c464c37620062490f7033ee
|
7
|
+
data.tar.gz: ba83a1f3d43b6a5b87910a4948decab146f9533a3bac2f5eebd91e4417cf0abec591772beca9ed4c5ccd5663fdbcc2d99640e529ad94000a9ed36bf1f7f4ba1a
|
data/lib/puppet_forge_server.rb
CHANGED
@@ -21,9 +21,7 @@ module PuppetForgeServer::Api::V1
|
|
21
21
|
{
|
22
22
|
:file => "/api/v1/files#{element[:path]}",
|
23
23
|
:version => element[:metadata].version,
|
24
|
-
:dependencies => element[:metadata].dependencies.map
|
25
|
-
[dependency['name'], dependency['version_requirement']]
|
26
|
-
end
|
24
|
+
:dependencies => element[:metadata].dependencies.map {|dep| [dep.name, dep.version_requirement]}
|
27
25
|
}
|
28
26
|
end.version_sort_by { |r| r[:version] }
|
29
27
|
end
|
@@ -44,8 +44,7 @@ module PuppetForgeServer::App
|
|
44
44
|
halt 400, json({:errors => ["'#{params[:module]}' is not a valid release slug"]}) unless author && name && version
|
45
45
|
releases = releases(author, name, version)
|
46
46
|
halt 404, json({:errors => ['404 Not found']}) unless releases
|
47
|
-
|
48
|
-
json releases.first
|
47
|
+
json releases.last
|
49
48
|
end
|
50
49
|
|
51
50
|
get '/v3/releases' do
|
@@ -73,8 +72,12 @@ module PuppetForgeServer::App
|
|
73
72
|
backend.get_metadata(author, name)
|
74
73
|
end.flatten.compact.uniq
|
75
74
|
halt 404, json({:errors => ['404 Not found']}) if metadata.empty?
|
76
|
-
|
77
|
-
|
75
|
+
modules = get_modules(metadata)
|
76
|
+
if modules.count > 1
|
77
|
+
PuppetForgeServer::Logger.get(:server).warn "There were more than oen module found for '#{author}-#{name}'"
|
78
|
+
PuppetForgeServer::Logger.get(:server).debug(modules.to_s)
|
79
|
+
end
|
80
|
+
json modules.first
|
78
81
|
end
|
79
82
|
|
80
83
|
get '/v3/modules' do
|
@@ -61,11 +61,18 @@ module PuppetForgeServer::Backends
|
|
61
61
|
return nil
|
62
62
|
end
|
63
63
|
|
64
|
+
def parse_dependencies(metadata)
|
65
|
+
metadata.dependencies = metadata.dependencies.dup.map do |dependency|
|
66
|
+
PuppetForgeServer::Models::Dependency.new({:name => dependency['name'], :version_requirement => dependency['version_requirement']})
|
67
|
+
end.flatten
|
68
|
+
metadata
|
69
|
+
end
|
70
|
+
|
64
71
|
def get_file_metadata(file_name, options)
|
65
72
|
options = ({:with_checksum => true}).merge(options)
|
66
73
|
Dir["#{@module_dir}/**/#{file_name}"].map do |path|
|
67
74
|
{
|
68
|
-
:metadata => PuppetForgeServer::Models::Metadata.new(read_metadata(path)),
|
75
|
+
:metadata => parse_dependencies(PuppetForgeServer::Models::Metadata.new(read_metadata(path))),
|
69
76
|
:checksum => options[:with_checksum] == true ? Digest::MD5.hexdigest(File.read(path)) : nil,
|
70
77
|
:path => "/#{Pathname.new(path).relative_path_from(Pathname.new(@module_dir))}"
|
71
78
|
}
|
@@ -24,6 +24,7 @@ module PuppetForgeServer::Backends
|
|
24
24
|
@url = url
|
25
25
|
@cache_dir = File.join(cache_dir, Digest::SHA1.hexdigest(@url))
|
26
26
|
@http_client = http_client
|
27
|
+
@log = PuppetForgeServer::Logger.get
|
27
28
|
|
28
29
|
# Create directory structure for all alphabetic letters
|
29
30
|
(10...36).each do |i|
|
@@ -43,16 +44,20 @@ module PuppetForgeServer::Backends
|
|
43
44
|
path = File.join(@cache_dir, file_name[0], file_name)
|
44
45
|
end
|
45
46
|
File.open(path, 'rb')
|
46
|
-
rescue
|
47
|
-
#
|
47
|
+
rescue => e
|
48
|
+
@log.error("#{self.class.name} failed downloading file '#{relative_path}'")
|
49
|
+
@log.error("Error: #{e}")
|
50
|
+
return nil
|
48
51
|
end
|
49
52
|
|
50
53
|
def upload(file_data)
|
51
|
-
|
54
|
+
@log.debug 'File upload is not supported by the proxy backends'
|
52
55
|
false
|
53
56
|
end
|
54
57
|
|
55
58
|
protected
|
59
|
+
attr_reader :log
|
60
|
+
|
56
61
|
def get(relative_url)
|
57
62
|
@http_client.get(url(relative_url))
|
58
63
|
end
|
@@ -33,8 +33,10 @@ module PuppetForgeServer::Backends
|
|
33
33
|
query ="#{author}/#{name}"
|
34
34
|
begin
|
35
35
|
get_module_metadata(JSON.parse(get("/modules.json?q=#{query}")).select { |e| e['full_name'].match("#{query}") }, options)
|
36
|
-
rescue
|
37
|
-
#
|
36
|
+
rescue => e
|
37
|
+
@log.debug("#{self.class.name} failed querying metadata for '#{query}' with options #{options}")
|
38
|
+
@log.debug("Error: #{e}")
|
39
|
+
return nil
|
38
40
|
end
|
39
41
|
end
|
40
42
|
|
@@ -42,8 +44,10 @@ module PuppetForgeServer::Backends
|
|
42
44
|
options = ({:with_checksum => true}).merge(options)
|
43
45
|
begin
|
44
46
|
get_module_metadata(JSON.parse(get("/modules.json?q=#{query}")).select { |e| e['full_name'].match("*#{query}*") }, options)
|
45
|
-
rescue
|
46
|
-
#
|
47
|
+
rescue => e
|
48
|
+
@log.debug("#{self.class.name} failed querying metadata for '#{query}' with options #{options}")
|
49
|
+
@log.debug("Error: #{e}")
|
50
|
+
return nil
|
47
51
|
end
|
48
52
|
end
|
49
53
|
|
@@ -58,6 +62,13 @@ module PuppetForgeServer::Backends
|
|
58
62
|
element
|
59
63
|
end
|
60
64
|
|
65
|
+
def parse_dependencies(metadata)
|
66
|
+
metadata.dependencies = metadata.dependencies.dup.map do |dependency|
|
67
|
+
PuppetForgeServer::Models::Dependency.new({:name => dependency[0], :version_requirement => dependency.length > 1 ? dependency[1] : nil})
|
68
|
+
end.flatten
|
69
|
+
metadata
|
70
|
+
end
|
71
|
+
|
61
72
|
def get_module_metadata(modules, options)
|
62
73
|
modules.map do |element|
|
63
74
|
version = options['version'] ? "&version=#{options['version']}" : ''
|
@@ -65,7 +76,7 @@ module PuppetForgeServer::Backends
|
|
65
76
|
tags = element['tag_list'] ? element['tag_list'] : nil
|
66
77
|
raw_metadata = read_metadata(element, release)
|
67
78
|
{
|
68
|
-
:metadata => PuppetForgeServer::Models::Metadata.new(raw_metadata),
|
79
|
+
:metadata => parse_dependencies(PuppetForgeServer::Models::Metadata.new(raw_metadata)),
|
69
80
|
:checksum => options[:with_checksum] ? Digest::MD5.hexdigest(File.read(get_file_buffer(release['file']))) : nil,
|
70
81
|
:path => "#{release['file']}",
|
71
82
|
:tags => tags
|
@@ -31,8 +31,10 @@ module PuppetForgeServer::Backends
|
|
31
31
|
begin
|
32
32
|
releases = options[:version] ? [JSON.parse(get("/v3/releases/#{query}-#{options[:version]}"))] : get_all_result_pages("/v3/releases?module=#{query}")
|
33
33
|
get_release_metadata(releases)
|
34
|
-
rescue
|
35
|
-
#
|
34
|
+
rescue => e
|
35
|
+
@log.debug("#{self.class.name} failed querying metadata for '#{query}' with options #{options}")
|
36
|
+
@log.debug("Error: #{e}")
|
37
|
+
nil
|
36
38
|
end
|
37
39
|
end
|
38
40
|
|
@@ -40,8 +42,10 @@ module PuppetForgeServer::Backends
|
|
40
42
|
begin
|
41
43
|
releases = get_all_result_pages("/v3/modules?query=#{query}").map {|element| element['current_release']}
|
42
44
|
get_release_metadata(releases)
|
43
|
-
rescue
|
44
|
-
#
|
45
|
+
rescue => e
|
46
|
+
@log.debug("#{self.class.name} failed querying metadata for '#{query}' with options #{options}")
|
47
|
+
@log.debug("Error: #{e}")
|
48
|
+
nil
|
45
49
|
end
|
46
50
|
end
|
47
51
|
|
@@ -61,10 +65,17 @@ module PuppetForgeServer::Backends
|
|
61
65
|
metadata
|
62
66
|
end
|
63
67
|
|
68
|
+
def parse_dependencies(metadata)
|
69
|
+
metadata.dependencies = metadata.dependencies.dup.map do |dependency|
|
70
|
+
PuppetForgeServer::Models::Dependency.new({:name => dependency['name'], :version_requirement => dependency['version_requirement']})
|
71
|
+
end.flatten
|
72
|
+
metadata
|
73
|
+
end
|
74
|
+
|
64
75
|
def get_release_metadata(releases)
|
65
76
|
releases.map do |element|
|
66
77
|
{
|
67
|
-
:metadata => PuppetForgeServer::Models::Metadata.new(normalize_metadata(element['metadata'])),
|
78
|
+
:metadata => parse_dependencies(PuppetForgeServer::Models::Metadata.new(normalize_metadata(element['metadata']))),
|
68
79
|
:checksum => element['file_md5'],
|
69
80
|
:path => element['file_uri'],
|
70
81
|
:tags => (element['tags'] + (element['metadata']['tags'] ? element['metadata']['tags'] : [])).flatten.uniq
|
@@ -19,6 +19,7 @@ require 'logger'
|
|
19
19
|
|
20
20
|
module PuppetForgeServer
|
21
21
|
class Logger
|
22
|
+
@@DEFAULT_LOG_LEVEL = ::Logger::INFO
|
22
23
|
@@DEFAULT_DESTINATION = STDERR
|
23
24
|
@@DEFAULT_DATETIME_FORMAT = '%Y-%m-%d %H:%M:%S'
|
24
25
|
@static_loggers = {:server => nil, :access => nil}
|
@@ -30,6 +31,7 @@ module PuppetForgeServer
|
|
30
31
|
datetime = datetime.strftime @@DEFAULT_DATETIME_FORMAT
|
31
32
|
"[#{datetime}] #{severity} #{msg}\n"
|
32
33
|
end
|
34
|
+
logger.level = @@DEFAULT_LOG_LEVEL
|
33
35
|
logger
|
34
36
|
end
|
35
37
|
end
|
@@ -26,10 +26,17 @@ module PuppetForgeServer::Models
|
|
26
26
|
PuppetForge::Logger.get.error "Method #{method_name} with args #{args} not found in #{self.class.to_s}" unless method_name == :to_ary
|
27
27
|
end
|
28
28
|
|
29
|
-
def to_hash
|
29
|
+
def to_hash(obj = self)
|
30
30
|
hash = {}
|
31
|
-
|
32
|
-
|
31
|
+
obj.instance_variables.each do |var|
|
32
|
+
var_value = obj.instance_variable_get(var)
|
33
|
+
hash[var.to_s.delete('@')] = if var_value.kind_of?(Array)
|
34
|
+
var_value.map {|v| to_hash(v)}
|
35
|
+
elsif var_value.respond_to?(:to_hash)
|
36
|
+
var_value.to_hash
|
37
|
+
else
|
38
|
+
var_value
|
39
|
+
end
|
33
40
|
end
|
34
41
|
hash
|
35
42
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright 2015 North Development AB
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
|
18
|
+
module PuppetForgeServer::Models
|
19
|
+
class Dependency < Builder
|
20
|
+
|
21
|
+
attr_accessor :name
|
22
|
+
attr_accessor :version_requirement
|
23
|
+
|
24
|
+
def initialize(attributes)
|
25
|
+
super(attributes)
|
26
|
+
end
|
27
|
+
|
28
|
+
def ==(other)
|
29
|
+
other && self.class.equal?(other.class) &&
|
30
|
+
@name == other.name &&
|
31
|
+
@version_requirement == other.version_requirement
|
32
|
+
end
|
33
|
+
|
34
|
+
def hash
|
35
|
+
@name.hash ^ @version_requirement.hash
|
36
|
+
end
|
37
|
+
|
38
|
+
def eql?(other)
|
39
|
+
other && self.class.equal?(other.class) &&
|
40
|
+
@name.eql?(other.name) &&
|
41
|
+
@version_requirement.eql?(other.version_requirement)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -40,11 +40,17 @@ module PuppetForgeServer
|
|
40
40
|
if options[:log_dir]
|
41
41
|
FileUtils.mkdir_p options[:log_dir]
|
42
42
|
server_loggers = [File.join(options[:log_dir], 'server.log')]
|
43
|
-
server_loggers << STDERR if options[:debug]
|
44
43
|
access_loggers = [File.join(options[:log_dir], 'access.log')]
|
45
|
-
|
44
|
+
if options[:debug]
|
45
|
+
server_loggers << STDERR
|
46
|
+
access_loggers << STDERR
|
47
|
+
end
|
46
48
|
PuppetForgeServer::Logger.set({:server => server_loggers, :access => access_loggers})
|
47
49
|
end
|
50
|
+
if options[:debug]
|
51
|
+
PuppetForgeServer::Logger.get(:server).level = ::Logger::DEBUG
|
52
|
+
PuppetForgeServer::Logger.get(:access).level = ::Logger::DEBUG
|
53
|
+
end
|
48
54
|
PuppetForgeServer::Logger.get
|
49
55
|
end
|
50
56
|
|
data/spec/unit/logger_spec.rb
CHANGED
@@ -0,0 +1,46 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright 2015 North Development AB
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require 'spec_helper'
|
18
|
+
|
19
|
+
module PuppetForgeServer::Models
|
20
|
+
describe Dependency do
|
21
|
+
let(:name) { 'dummy_name' }
|
22
|
+
let(:version_requirement) { '0.0.0' }
|
23
|
+
let(:dependency) { PuppetForgeServer::Models::Dependency.new({:name => name, :version_requirement => version_requirement}) }
|
24
|
+
describe '#initialize' do
|
25
|
+
it 'should create a dependency instance' do
|
26
|
+
expect(dependency.name).to eq name
|
27
|
+
expect(dependency.version_requirement).to eq version_requirement
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#hash' do
|
32
|
+
it 'should calculate hash from name and version_requirement' do
|
33
|
+
expect(dependency.hash).to eq(name.hash ^ version_requirement.hash)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#eql?' do
|
38
|
+
it 'should be equal based only on name and version_requirement' do
|
39
|
+
dependency2 = dependency.clone
|
40
|
+
expect(dependency).to eq dependency2
|
41
|
+
dependency2.name = 'something_else'
|
42
|
+
expect(dependency).not_to eq dependency2
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet-forge-server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ilja Bobkevic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|
@@ -188,6 +188,7 @@ files:
|
|
188
188
|
- lib/puppet_forge_server/http/http_client.rb
|
189
189
|
- lib/puppet_forge_server/logger.rb
|
190
190
|
- lib/puppet_forge_server/models/builder.rb
|
191
|
+
- lib/puppet_forge_server/models/dependency.rb
|
191
192
|
- lib/puppet_forge_server/models/metadata.rb
|
192
193
|
- lib/puppet_forge_server/patches.rb
|
193
194
|
- lib/puppet_forge_server/server.rb
|
@@ -202,6 +203,7 @@ files:
|
|
202
203
|
- spec/unit/app/version2_spec.rb
|
203
204
|
- spec/unit/backends/directory_spec.rb
|
204
205
|
- spec/unit/logger_spec.rb
|
206
|
+
- spec/unit/models/dependency_spec.rb
|
205
207
|
- spec/unit/models/metadata_spec.rb
|
206
208
|
- spec/unit/server_spec.rb
|
207
209
|
homepage: https://github.com/unibet/puppet-forge-server
|
@@ -233,5 +235,6 @@ test_files:
|
|
233
235
|
- spec/unit/app/version2_spec.rb
|
234
236
|
- spec/unit/backends/directory_spec.rb
|
235
237
|
- spec/unit/logger_spec.rb
|
238
|
+
- spec/unit/models/dependency_spec.rb
|
236
239
|
- spec/unit/models/metadata_spec.rb
|
237
240
|
- spec/unit/server_spec.rb
|