puppet-forge-server 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7534f17808255a66c9f45677758540784f88dd49
4
- data.tar.gz: 45e2900ea2f35918116c89b813dfa7465a713f41
3
+ metadata.gz: 973bfb424267e3db596e1568f4781d7ef102e46a
4
+ data.tar.gz: aaaba8e6de5e1a55e7842e92b28caab624df37c1
5
5
  SHA512:
6
- metadata.gz: 4edc8df5081d8244aac83af9a3064a8787ce1d57b023a8b5f90125e440407e3650f2010fa560caabcb46dacce974abb56dde156ae348b792d959cb1b6a7dce1e
7
- data.tar.gz: 995943485154d7772395495fcb91b162629491e4ba0e7f98a429847f9fe2ae5eaeef8d68170e6318dc23074eaee805f0d1c94be6faca8457a4f5032671e49087
6
+ metadata.gz: e01143d845d1c664ff7490ac231cae20e0616de8dcad0ccd745695c04279384763433b3b998bba6546dc57e634d0dcf6f9bb98d045704f55d1f6ec982bac7a09
7
+ data.tar.gz: be411f8e681736089b3026ba66f1a7c132b75f338f8dd02fca8fa5c8c831af3a404461ef66c99ff12826c72134165fa091ce29c4c2e95e2fc06c7f8b75ce4e5c
@@ -20,6 +20,7 @@ require 'puppet_forge_server/version'
20
20
  module PuppetForgeServer
21
21
  autoload :Server, 'puppet_forge_server/server'
22
22
  autoload :Errors, 'puppet_forge_server/errors'
23
+ autoload :Logger, 'puppet_forge_server/logger'
23
24
 
24
25
  module Api
25
26
  module V1
@@ -23,6 +23,14 @@ module PuppetForgeServer::App
23
23
  include PuppetForgeServer::Api::V1::Modules
24
24
  include PuppetForgeServer::Utils::Buffer
25
25
 
26
+ configure do
27
+ use ::Rack::CommonLogger, PuppetForgeServer::Logger.get(:access)
28
+ end
29
+
30
+ before {
31
+ env['rack.errors'] = PuppetForgeServer::Logger.get(:server)
32
+ }
33
+
26
34
  def initialize(backends)
27
35
  super(nil)
28
36
  @backends = backends
@@ -22,6 +22,14 @@ module PuppetForgeServer::App
22
22
  include PuppetForgeServer::Api::V3::Modules
23
23
  include PuppetForgeServer::Utils::Buffer
24
24
 
25
+ configure do
26
+ use ::Rack::CommonLogger, PuppetForgeServer::Logger.get(:access)
27
+ end
28
+
29
+ before {
30
+ env['rack.errors'] = PuppetForgeServer::Logger.get(:server)
31
+ }
32
+
25
33
  def initialize(backends)
26
34
  super(nil)
27
35
  @backends = backends
@@ -0,0 +1,56 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ # Copyright 2014 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
+ require 'logger'
19
+
20
+ module PuppetForgeServer
21
+ class Logger
22
+ @@DEFAULT_DESTINATION = STDERR
23
+ @@DEFAULT_DATETIME_FORMAT = '%Y-%m-%d %H:%M:%S'
24
+ @static_loggers = {:server => nil, :access => nil}
25
+
26
+ def initialize(destinations = [@@DEFAULT_LOGGER])
27
+ @loggers = Array.new(destinations).flatten.map do |dest|
28
+ logger = ::Logger.new(dest)
29
+ logger.formatter = proc do |severity, datetime, progname, msg|
30
+ datetime = datetime.strftime @@DEFAULT_DATETIME_FORMAT
31
+ "[#{datetime}] #{severity} #{msg}\n"
32
+ end
33
+ logger
34
+ end
35
+ end
36
+
37
+ def method_missing (method_name, *args, &block)
38
+ method_name = method_name == :write ? :'<<' : method_name
39
+ @loggers.each { |logger| logger.send(method_name, args.first) }
40
+ end
41
+
42
+ class << self
43
+ def get(type = :server)
44
+ set unless @static_loggers[type]
45
+ @static_loggers[type]
46
+ end
47
+
48
+ def set(loggers= {})
49
+ loggers = {:server => [@@DEFAULT_DESTINATION], :access => [@@DEFAULT_DESTINATION]}.merge(loggers)
50
+ loggers.each do |type, destinations|
51
+ @static_loggers[type] = PuppetForgeServer::Logger.new(destinations)
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -21,40 +21,49 @@ module PuppetForgeServer
21
21
  include PuppetForgeServer::Utils::OptionParser
22
22
  include PuppetForgeServer::Utils::Http
23
23
 
24
- def initialize(log = STDERR)
25
- @log = log
26
- end
27
-
28
24
  def go(args)
29
25
  begin
30
26
  options = parse_options(args)
27
+ @log = logging(options)
31
28
  backends = backends(options)
32
29
  server = build(backends)
33
30
  announce(options, backends)
34
31
  start(server, options)
35
32
  rescue PuppetForgeServer::Errors::Expected
36
- @log.puts "Error: #{error}"
33
+ @log.error error
34
+ end
35
+ end
36
+
37
+ def logging(options)
38
+ if options[:log_dir]
39
+ FileUtils.mkdir_p options[:log_dir]
40
+ server_loggers = [File.join(options[:log_dir], 'server.log')]
41
+ server_loggers << STDERR if options[:debug]
42
+ access_loggers = [File.join(options[:log_dir], 'access.log')]
43
+ access_loggers << STDERR if options[:debug]
44
+ PuppetForgeServer::Logger.set({:server => server_loggers, :access => access_loggers})
37
45
  end
46
+ PuppetForgeServer::Logger.get
38
47
  end
39
48
 
40
49
  def build(backends)
41
50
  Rack::Mount::RouteSet.new do |set|
42
51
  set.add_route PuppetForgeServer::App::Version1.new(backends)
43
- set.add_route ::PuppetForgeServer::App::Version3.new(backends)
52
+ set.add_route PuppetForgeServer::App::Version3.new(backends)
44
53
  end
45
54
  end
46
55
 
47
56
  def announce(options, backends)
48
57
  options = options.clone
49
58
  options.default = 'default'
50
- @log.puts " +- Daemonizing: #{options[:daemonize]}"
51
- @log.puts " |- Port: #{options[:port]}"
52
- @log.puts " |- Host: #{options[:hostname]}"
53
- @log.puts " |- Pidfile: #{options[:pidfile]}" if options[:pidfile]
54
- @log.puts " |- Server: #{options[:server]}"
55
- @log.puts ' `- Backends:'
59
+ @log.info " +- Daemonizing: #{options[:daemonize]}"
60
+ @log.info " |- Port: #{options[:port]}"
61
+ @log.info " |- Host: #{options[:hostname]}"
62
+ @log.info " |- Pidfile: #{options[:pidfile]}" if options[:pidfile]
63
+ @log.info " |- Server: #{options[:server]}"
64
+ @log.info ' `- Backends:'
56
65
  backends.each do |backend|
57
- @log.puts " - #{backend.inspect}"
66
+ @log.info " - #{backend.inspect}"
58
67
  end
59
68
  end
60
69
 
@@ -76,7 +85,7 @@ module PuppetForgeServer
76
85
  typed_backends.map do |url|
77
86
  case type
78
87
  when 'Proxy'
79
- @log.puts "Detecting API version for #{url}..."
88
+ @log.info "Detecting API version for #{url}..."
80
89
  PuppetForgeServer::Backends.const_get("#{type}V#{get_api_version(url)}").new(url.chomp('/'), options[:cache_basedir])
81
90
  else
82
91
  PuppetForgeServer::Backends.const_get(type).new(url)
@@ -26,6 +26,7 @@ module PuppetForgeServer::Utils
26
26
  @@DEFAULT_PORT = 8080
27
27
  @@DEFAULT_PID_FILE = File.join(Dir.tmpdir.to_s, 'puppet-forge-server', 'server.pid')
28
28
  @@DEFAULT_CACHE_DIR = File.join(Dir.tmpdir.to_s, 'puppet-forge-server', 'cache')
29
+ @@DEFAULT_LOG_DIR = File.join(Dir.tmpdir.to_s, 'puppet-forge-server', 'log')
29
30
 
30
31
  def parse_options(args)
31
32
  options = {:daemonize => @@DEFAULT_DAEMONIZE, :cache_basedir => @@DEFAULT_CACHE_DIR, :port => @@DEFAULT_PORT}
@@ -43,7 +44,6 @@ module PuppetForgeServer::Utils
43
44
 
44
45
  opts.on('-D', '--daemonize', "Run the server in the background (default: #{@@DEFAULT_DAEMONIZE})") do
45
46
  options[:daemonize] = true
46
- options[:pidfile] = @@DEFAULT_PID_FILE unless options[:pidfile]
47
47
  end
48
48
 
49
49
  opts.on('--pidfile FILE', 'Write a pidfile to this location after starting') do |pidfile|
@@ -61,12 +61,31 @@ module PuppetForgeServer::Utils
61
61
  opts.on('--cache-basedir DIR', "Cache all proxies' downloaded modules under this directory (default: #{@@DEFAULT_CACHE_DIR})") do |cache_basedir|
62
62
  options[:cache_basedir] = cache_basedir
63
63
  end
64
+
65
+ opts.on('--log-dir DIR', "Directory containing all server logs (if daemonized default: #{@@DEFAULT_LOG_DIR})") do |log_dir|
66
+ options[:log_dir] = log_dir
67
+ end
68
+
69
+ opts.on('--debug', 'Log everything into STDERR') do
70
+ options[:debug] = true
71
+ end
64
72
  end
65
73
  begin
66
74
  option_parser.parse(args)
67
75
  rescue ::OptionParser::InvalidOption => parse_error
68
76
  raise PuppetForgeServer::Errors::Expected, parse_error.message + "\n" + option_parser.help
69
77
  end
78
+
79
+ # Handle option dependencies
80
+ if options[:daemonize]
81
+ options[:pidfile] = @@DEFAULT_PID_FILE unless options[:pidfile]
82
+ options[:log_dir] = @@DEFAULT_LOG_DIR unless options[:log_dir]
83
+ end
84
+
85
+ if options[:log_dir] && !options[:daemonize]
86
+ options[:debug] = true
87
+ end
88
+
70
89
  return options
71
90
  end
72
91
  end
@@ -15,5 +15,5 @@
15
15
  # limitations under the License.
16
16
 
17
17
  module PuppetForgeServer
18
- VERSION = '1.0.2'
18
+ VERSION = '1.0.3'
19
19
  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.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ilja Bobkevic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-12 00:00:00.000000000 Z
11
+ date: 2014-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -134,6 +134,7 @@ files:
134
134
  - lib/puppet_forge_server/backends/proxy_v3.rb
135
135
  - lib/puppet_forge_server/errors.rb
136
136
  - lib/puppet_forge_server/http/http_client.rb
137
+ - lib/puppet_forge_server/logger.rb
137
138
  - lib/puppet_forge_server/models/builder.rb
138
139
  - lib/puppet_forge_server/models/metadata.rb
139
140
  - lib/puppet_forge_server/patches.rb