gaptool-server 0.7.4 → 0.8.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 01f73acc1996353bb8e20000d04b304807f18c76
4
- data.tar.gz: 47a25aecf0253dc011017ac5dcea184566dd9672
3
+ metadata.gz: 8f4f3e9c7ea6941ecfc204af4f0e3955084d2782
4
+ data.tar.gz: 46cdd65cd84a180d568fa842101e4e8d10898c23
5
5
  SHA512:
6
- metadata.gz: 2f1ad14a94e0e304f5677e20d3f056f12076a4dea5e7a6e756dc07c2029ff562b7c737ba4da51bfca9e0760dc01a39786de7cd7a24e0b2ff3f6590af99d14dda
7
- data.tar.gz: 053d1ed3010a379feac71e36ee63dae0c2736bb6ec359b0d8cbe83e5573ad8880ab053b1c2b41488ed705bda203237ae6bf3c48053dbefb25990751ad1bef828
6
+ metadata.gz: 7f0acc40c76b1715f4c509cafa4af7dfa33da130fd25c15f434f2e304ead95f436bff891554836ddf91aea91c1eafcd4bb93874f23426d775acd5fcfc136490e
7
+ data.tar.gz: 6a22c5aa7f579de53d1cfe08d650f3b30f458320d30bcb6eb84c57bdcaab2be1fe97db5e1e1f86325c2b01ca66e69fc4804358d33319b240a17ea43b3f90e764
data/Rakefile CHANGED
@@ -14,28 +14,26 @@ $stdout.sync = true
14
14
 
15
15
  def sys(cmd)
16
16
  IO.popen(cmd) do |f|
17
- until f.eof?
18
- puts f.gets
19
- end
17
+ puts f.gets until f.eof?
20
18
  end
21
- $?.to_i
19
+ $CHILD_STATUS.to_i
22
20
  end
23
21
 
24
- Dir.glob('tasks/*.rb').each { |r| load r}
22
+ Dir.glob('tasks/*.rb').each { |r| load r }
25
23
 
26
- unless File.exists?('/.dockerenv')
27
- desc "Start the shell"
24
+ unless File.exist?('/.dockerenv')
25
+ desc 'Start the shell'
28
26
  task :shell do
29
27
  exec "racksh #{Shellwords.join(ARGV[1..-1])}"
30
28
  end
31
- task :sh => :shell
29
+ task sh: :shell
32
30
 
33
- desc "Start the HTTP server"
31
+ desc 'Start the HTTP server'
34
32
  task :server do
35
33
  exec "puma -p 3000 --preload -t 8:32 -w 3 #{Shellwords.join(ARGV[1..-1])}"
36
34
  end
37
35
 
38
- desc "Bump the version"
36
+ desc 'Bump the version'
39
37
  task :bump do
40
38
  version = File.read('VERSION').strip
41
39
  nver = version.next
@@ -44,29 +42,29 @@ unless File.exists?('/.dockerenv')
44
42
  f.close
45
43
  puts "Bumped #{version} => #{nver}"
46
44
  exec "git commit -m 'Bump version to v#{nver}' VERSION"
47
- Rake::Task["tag"].invoke
48
- Rake::Task["gem:build"].invoke
45
+ Rake::Task['tag'].invoke
46
+ Rake::Task['gem:build'].invoke
49
47
  end
50
48
 
51
- desc "Tag git with VERSION"
49
+ desc 'Tag git with VERSION'
52
50
  task :tag do
53
- exec "git tag v$(cat VERSION)"
51
+ exec 'git tag v$(cat VERSION)'
54
52
  end
55
53
 
56
- desc "Push the git tag and the gem version"
57
- task :push => :tag do
58
- exec "git push origin v$(cat VERSION)"
59
- Rake::Task["gem:push"].invoke
54
+ desc 'Push the git tag and the gem version'
55
+ task push: :tag do
56
+ exec 'git push origin v$(cat VERSION)'
57
+ Rake::Task['gem:push'].invoke
60
58
  end
61
59
  end
62
60
 
63
61
  task :help do
64
- puts "Available tasks"
65
- exec "rake -T"
62
+ puts 'Available tasks'
63
+ exec 'rake -T'
66
64
  end
67
65
 
68
66
  RSpec::Core::RakeTask.new :test do |task|
69
67
  task.pattern = Dir['test/*_test.rb']
70
68
  end
71
69
 
72
- task :default => :help
70
+ task default: :help
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.4
1
+ 0.8.0
data/bin/gaptool-server CHANGED
@@ -5,7 +5,7 @@ begin
5
5
  require 'gaptool-server'
6
6
  root = Gem.loaded_specs['gaptool-server'].full_gem_path
7
7
  rescue LoadError
8
- root = File.realpath(File.join(File.dirname(__FILE__), ".."))
8
+ root = File.realpath(File.join(File.dirname(__FILE__), '..'))
9
9
  end
10
10
  Dir.chdir(root)
11
- exec "puma #{ARGV.join(" ")}"
11
+ exec "puma #{ARGV.join(' ')}"
data/bin/gaptool-shell CHANGED
@@ -5,8 +5,8 @@ begin
5
5
  require 'gaptool-server'
6
6
  root = Gem.loaded_specs['gaptool-server'].full_gem_path
7
7
  rescue LoadError
8
- root = File.realpath(File.join(File.dirname(__FILE__), ".."))
8
+ root = File.realpath(File.join(File.dirname(__FILE__), '..'))
9
9
  end
10
10
  Dir.chdir(root)
11
11
 
12
- exec "racksh #{ARGV.join(" ")}"
12
+ exec "racksh #{ARGV.join(' ')}"
data/config.ru CHANGED
@@ -2,9 +2,8 @@
2
2
 
3
3
  ENV['DRYRUN'] = nil unless ENV['DRYRUN'] == 'true'
4
4
 
5
- libpath = File.expand_path(File.join(File.dirname(__FILE__), "lib"))
6
- $:.unshift(libpath)
7
- require "#{libpath}/helpers/redis"
5
+ libpath = File.expand_path(File.join(File.dirname(__FILE__), 'lib'))
6
+ $LOAD_PATH.unshift(libpath)
8
7
  require "#{libpath}/app.rb"
9
8
 
10
- run GaptoolServer
9
+ run Gaptool::Server
data/lib/app.rb CHANGED
@@ -13,87 +13,97 @@ require 'logger'
13
13
  require 'versionomy'
14
14
  require_relative 'exceptions'
15
15
 
16
- class GaptoolServer < Sinatra::Application
17
- helpers Sinatra::JSON
18
- use Airbrake::Sinatra
16
+ module Gaptool
17
+ class Server < Sinatra::Application
18
+ @versions = {}
19
+ class << self
20
+ attr_reader :versions
21
+ end
19
22
 
20
- def error_response msg=''
21
- message = env['sinatra_error'].nil? ? "" : " #{env['sinatra.error'].message}"
22
- message = "#{msg}#{message}" unless msg.empty?
23
- json result: 'error', message: message
24
- end
23
+ def versions
24
+ self.class.versions
25
+ end
25
26
 
26
- error JSON::ParserError do
27
- status 400
28
- error_response "Invalid data."
29
- end
27
+ helpers Sinatra::JSON
28
+ use Airbrake::Sinatra
30
29
 
31
- error HTTPError do
32
- status env['sinatra.error'].code
33
- error_response
34
- end
30
+ def error_response(msg = '')
31
+ message = env['sinatra_error'].nil? ? '' : " #{env['sinatra.error'].message}"
32
+ message = "#{msg}#{message}" unless msg.empty?
33
+ json result: 'error', message: message
34
+ end
35
35
 
36
- def unauthenticated
37
- halt(401, error_response("Unauthenticated"))
38
- end
36
+ error JSON::ParserError do
37
+ status 400
38
+ error_response 'Invalid data.'
39
+ end
39
40
 
40
- def check_version(server, client)
41
- @@client_versions ||= {}
42
- cl_v = @@client_versions[client]
43
- if cl_v.nil?
44
- begin
45
- @@client_versions[client] = Versionomy.parse(client)
46
- cl_v = @@client_versions[client]
47
- rescue
48
- return false
49
- end
41
+ error HTTPError do
42
+ status env['sinatra.error'].code
43
+ error_response
50
44
  end
51
- cl_v.major == server.major && cl_v.minor == server.minor
52
- end
53
45
 
54
- def invalid_version(server, client)
55
- halt(400, error_response("Invalid version #{client} (server: #{server})"))
56
- end
46
+ def unauthenticated
47
+ halt(401, error_response('Unauthenticated'))
48
+ end
57
49
 
58
- error do
59
- status 500
60
- error_response
61
- end
50
+ def client_version
51
+ client = env['HTTP_X_GAPTOOL_VERSION']
52
+ versions[client] ||= Versionomy.parse(client)
53
+ rescue
54
+ nil
55
+ end
56
+
57
+ def check_version
58
+ server = settings.version_parsed
59
+ client_version.major >= server.major && \
60
+ client_version.minor >= server.minor
61
+ rescue
62
+ false
63
+ end
64
+
65
+ def invalid_version
66
+ halt(400, error_response("Invalid version #{client_version} (server: #{settings.version})"))
67
+ end
62
68
 
63
- configure do
64
- unless ENV['AIRBRAKE_API_KEY'].nil?
65
- Airbrake.configure do |cfg|
66
- cfg.api_key = ENV['AIRBRAKE_API_KEY']
67
- cfg.logger = Logger.new(STDOUT)
69
+ error do
70
+ status 500
71
+ error_response
72
+ end
73
+
74
+ configure do
75
+ unless ENV['AIRBRAKE_API_KEY'].nil?
76
+ Airbrake.configure do |cfg|
77
+ cfg.api_key = ENV['AIRBRAKE_API_KEY']
78
+ cfg.logger = Logger.new(STDOUT)
79
+ end
68
80
  end
81
+ disable :sessions
82
+ enable :dump_errors
83
+ disable :show_exceptions
84
+ version = File.read(File.realpath(
85
+ File.join(File.dirname(__FILE__), '..', 'VERSION')
86
+ )).strip
87
+ set(:version, version)
88
+ set(:version_parsed, Versionomy.parse(version))
69
89
  end
70
- disable :sessions
71
- enable :dump_errors
72
- disable :show_exceptions
73
- version = File.read(File.realpath(
74
- File.join(File.dirname(__FILE__), "..", 'VERSION')
75
- )).strip
76
- set(:version, version)
77
- set(:version_parsed, Versionomy.parse(version))
78
- end
79
90
 
80
- before do
81
- if request.path_info != '/ping' && ENV['GAPTOOL_DISABLE_AUTH'].nil?
82
- user = Gaptool::Data.user(env['HTTP_X_GAPTOOL_USER'])
83
- return unauthenticated if user.nil?
84
- return unauthenticated unless user[:key] == env['HTTP_X_GAPTOOL_KEY']
85
- if !ENV['GAPTOOL_CHECK_CLIENT_VERSION'].nil? && !check_version(settings.version_parsed, env['HTTP_X_GAPTOOL_VERSION'])
86
- return invalid_version(settings.version, env['HTTP_X_GAPTOOL_VERSION'])
91
+ before do
92
+ if request.path_info != '/ping' && ENV['GAPTOOL_DISABLE_AUTH'].nil?
93
+ user = Gaptool::Data.user(env['HTTP_X_GAPTOOL_USER'])
94
+ return unauthenticated if user.nil?
95
+ return unauthenticated unless user[:key] == env['HTTP_X_GAPTOOL_KEY']
96
+ return invalid_version if !ENV['GAPTOOL_CHECK_CLIENT_VERSION'].nil? && !check_version
87
97
  end
88
98
  end
89
- end
90
99
 
91
- after do
92
- # Fix for old versions of gaptool-api
93
- if request.preferred_type.to_str == "application/json"
94
- content_type "application/json"
95
- else
96
- content_type 'text/html'
100
+ after do
101
+ # Fix for old versions of gaptool-api
102
+ if request.preferred_type.to_str == 'application/json'
103
+ content_type 'application/json'
104
+ else
105
+ content_type 'text/html'
106
+ end
97
107
  end
98
108
  end
99
109
  end
data/lib/exceptions.rb CHANGED
@@ -1,13 +1,13 @@
1
1
  class HTTPError < StandardError
2
2
  @code = 500
3
3
 
4
- def self.code
5
- @code
4
+ class << self
5
+ attr_reader :code
6
6
  end
7
7
 
8
- def code
8
+ def code
9
9
  self.class.code
10
- end
10
+ end
11
11
  end
12
12
 
13
13
  class ClientError < HTTPError