qm 1.2.1 → 1.2.2

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: df2e09fa4efffc09c430a3b09adbd272e75aa8b7
4
- data.tar.gz: 69673e6ad48389d7a5add4bbacd7398e8ea79cad
3
+ metadata.gz: da264638d70859692298a689d2a92d025733719f
4
+ data.tar.gz: 10ed26e4b45118477d7b48ac2adc611e9e4a3093
5
5
  SHA512:
6
- metadata.gz: b11d41f038f63a42226953b69a6db5e779479f669ab57c39a4a36a0732f4fc287685018d4a87dd88fe52ef929c4c950da0d6f96e794d5e14b74dd18343d8b89e
7
- data.tar.gz: 0a3e11577bb084ad0bdb06ef7dadfc3057f51b6e47853b319c822ae7813fbd2a3c9ed9147659260929ace1f58d4f1b460e4ae229b1a1639020e385fe5f485a8e
6
+ metadata.gz: fef5c587e41035dbaa90bb16a1320f3f41b7ab9f306fb454ae5bb662b7ca5f8a5fbd83b275767e58484a9167fafbbf7afd8c727513b96dff3257cda93eefd374
7
+ data.tar.gz: 3b43abf641787cc89a3730899c1ce44ef665d6b597079190b871d35545f0665ac9f90491f18a029d77fb4a5c0736a43a848a0d08ce4c566ff2bf611b5b0f6fda
data/README.md CHANGED
@@ -1,14 +1,17 @@
1
- # qm
1
+ qm
2
+ ==
3
+
2
4
 
3
5
  The `qm` gem for [Ruby](http://www.ruby-lang.org/) includes a
4
6
  [QMachine](https://www.qmachine.org) API server and a web server. It uses
5
7
  [MongoDB](http://www.mongodb.org/) for persistent storage, and it can
6
8
  optionally log traffic data into a different MongoDB collection instead of
7
- logging to stdout. A client is planned.
9
+ logging to stdout. A client is also in development.
8
10
 
9
- The repository contains vestigial definitions for using
10
- [SQLite](https://www.sqlite.org/), but these may "evolve away" in the future,
11
- primarily due to the
11
+ Note that the original [SQLite](https://www.sqlite.org/) definitions are now
12
+ only available in the
13
+ [`sqlite3` branch](https://github.com/qmachine/qm-ruby/tree/sqlite3). This
14
+ decision was motivated primarily by the
12
15
  [obstacle it poses](https://devcenter.heroku.com/articles/sqlite3)
13
16
  to deploying on [Heroku](https://www.heroku.com). If you are absolutely in love
14
17
  with SQLite (or just hate MongoDB), consider trying the
@@ -21,4 +24,3 @@ For more information, please see the
21
24
 
22
25
  [![Gem Version](https://badge.fury.io/rb/qm.svg)](http://badge.fury.io/rb/qm) [![Dependency Status](https://gemnasium.com/qmachine/qm-ruby.png)](https://gemnasium.com/qmachine/qm-ruby)
23
26
 
24
- <!-- vim:set syntax=markdown: -->
@@ -2,7 +2,7 @@
2
2
 
3
3
  #- defs-mongo.rb ~~
4
4
  # ~~ (c) SRW, 16 Jul 2014
5
- # ~~ last updated 21 Aug 2014
5
+ # ~~ last updated 14 Dec 2014
6
6
 
7
7
  require 'json'
8
8
  require 'mongo'
@@ -99,7 +99,7 @@ module Sinatra
99
99
  host: request.host,
100
100
  ip: request.ip,
101
101
  method: request.request_method,
102
- #status_code: response.status,
102
+ status_code: response.status,
103
103
  timestamp: Time.now,
104
104
  url: request.fullpath
105
105
  })
data/lib/qm.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  #- qm.rb ~~
4
4
  # ~~ (c) SRW, 12 Apr 2013
5
- # ~~ last updated 17 Nov 2014
5
+ # ~~ last updated 07 Dec 2014
6
6
 
7
7
  module QM
8
8
 
@@ -22,7 +22,7 @@ module QM
22
22
  configure do
23
23
  convert = lambda do |x|
24
24
  # This converts all keys in a hash to symbols recursively.
25
- if (x.is_a?(Hash)) then
25
+ if x.is_a?(Hash) then
26
26
  x = x.inject({}) do |memo, (k, v)|
27
27
  memo[k.to_sym] = convert.call(v)
28
28
  memo
@@ -32,11 +32,11 @@ module QM
32
32
  end
33
33
  options = convert.call(options)
34
34
  set options
35
- if (settings.persistent_storage.has_key?(:mongo)) then
35
+ if settings.persistent_storage.has_key?(:mongo) then
36
36
  helpers Sinatra::MongoAPIDefs
37
37
  mongo_api_connect
38
38
  end
39
- if (settings.trafficlog_storage.has_key?(:mongo)) then
39
+ if settings.trafficlog_storage.has_key?(:mongo) then
40
40
  helpers Sinatra::MongoLogDefs
41
41
  mongo_log_connect
42
42
  after do
@@ -16,7 +16,7 @@
16
16
  # of a 'box', 'key', or 'status' value.
17
17
  #
18
18
  # ~~ (c) SRW, 24 Apr 2013
19
- # ~~ last updated 28 Aug 2014
19
+ # ~~ last updated 12 Jan 2015
20
20
 
21
21
  require 'sinatra'
22
22
  require 'sinatra/cross_origin'
@@ -34,6 +34,7 @@ class QMachineService < Sinatra::Base
34
34
  enable_cors: false,
35
35
  enable_web_server: false,
36
36
  hostname: '0.0.0.0',
37
+ max_body_size: 1048576, # 1024 * 1024 = 1 MB
37
38
  persistent_storage: {},
38
39
  port: 8177,
39
40
  public_folder: 'public',
@@ -41,12 +42,15 @@ class QMachineService < Sinatra::Base
41
42
 
42
43
  # Sinatra mappings and options needed by QMachine.
43
44
 
44
- mime_type webapp: 'application/x-web-app-manifest+json'
45
+ mime_type :webapp, 'application/x-web-app-manifest+json'
45
46
 
46
47
  set bind: lambda { settings.hostname },
47
48
  logging: true,
49
+ raise_errors: false,
48
50
  run: false,
49
- static: lambda { settings.enable_web_server }
51
+ show_exceptions: false,
52
+ static: lambda { settings.enable_web_server },
53
+ x_cascade: false
50
54
 
51
55
  # See also: http://www.sinatrarb.com/configuration.html
52
56
 
@@ -65,9 +69,14 @@ class QMachineService < Sinatra::Base
65
69
  # that are loaded at runtime by `QM::launch_service`.
66
70
 
67
71
  def hang_up
68
- # This helper method "hangs up" on a request by sending a nondescript
69
- # 444 response back to the client, a convention taken from nginx.
70
- halt [444, {'Content-Type' => 'text/plain'}, ['']]
72
+ # This helper literally "hangs up" on the request by immediately
73
+ # halting further processing, responding with a nondescript 444
74
+ # status code and an empty body, and then closing the connection.
75
+ # Unfortunately, closing the connection in this way caused problems
76
+ # in the Node.js implementation, which suggests that this is not the
77
+ # correct solution for all concurrency models ... argh.
78
+ headers = {'Connection' => 'close', 'Content-Type' => 'text/plain'}
79
+ halt [444, headers, ['']]
71
80
  end
72
81
 
73
82
  end
@@ -88,8 +97,9 @@ class QMachineService < Sinatra::Base
88
97
  hang_up unless (settings.enable_api_server?) and
89
98
  ((version == 'box') or (version == 'v1')) and
90
99
  (@box.match(/^[\w\-]+$/)) and
91
- ((@key.is_a?(String) and @key.match(/^[A-Za-z0-9]+$/)) or
92
- (@status.is_a?(String) and @status.match(/^[A-Za-z0-9]+$/)))
100
+ ((@key.is_a?(String) and @key.match(/^[\w\-]+$/)) or
101
+ (@status.is_a?(String) and @status.match(/^[\w\-]+$/))) and
102
+ (request.content_length.to_s.to_i(10) < settings.max_body_size)
93
103
  cross_origin if settings.enable_cors?
94
104
  end
95
105
 
@@ -112,12 +122,16 @@ class QMachineService < Sinatra::Base
112
122
  # such as when uploading results or submitting new tasks.
113
123
  hang_up unless @key.is_a?(String) and not @status.is_a?(String)
114
124
  body = request.body.read
115
- x = JSON.parse(body)
125
+ begin
126
+ x = JSON.parse(body)
127
+ rescue JSON::ParserError
128
+ hang_up
129
+ end
116
130
  hang_up unless (@box == x['box']) and (@key == x['key'])
117
131
  if x['status'].is_a?(String) then
118
132
  # This arm runs only when a client writes an avar which represents a
119
133
  # task description.
120
- hang_up unless x['status'].match(/^[A-Za-z0-9]+$/)
134
+ hang_up unless x['status'].match(/^[\w\-]+$/)
121
135
  set_avar([@box, @key, x['status'], body])
122
136
  else
123
137
  # This arm runs when a client is writing a "regular avar".
@@ -127,10 +141,16 @@ class QMachineService < Sinatra::Base
127
141
  end
128
142
 
129
143
  get '/robots.txt' do
130
- # This route tells web crawlers to keep out of an API server, but it
131
- # delegates to a static file if the web server is enabled.
132
- pass if settings.enable_web_server?
133
- y = "User-agent: *\nDisallow: /\n"
144
+ # This route delegates to the web server, if it was enabled at launch and
145
+ # if the appropriate file exists; otherwise, it returns a message to web
146
+ # crawlers instructing them to keep out.
147
+ robots_file = File.join(settings.public_folder, 'robots.txt')
148
+ if settings.enable_web_server? then
149
+ pass if File.exists?(robots_file)
150
+ y = "User-agent: *\nDisallow: /box/\nDisallow: /v1/\n"
151
+ else
152
+ y = "User-agent: *\nDisallow: /\n"
153
+ end
134
154
  return [200, {'Content-Type' => 'text/plain'}, [y]]
135
155
  end
136
156
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Wilkinson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-24 00:00:00.000000000 Z
11
+ date: 2015-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bson_ext
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 1.8.1
33
+ version: 1.8.2
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 1.8.1
40
+ version: 1.8.2
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: httparty
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -94,7 +94,7 @@ dependencies:
94
94
  - - '='
95
95
  - !ruby/object:Gem::Version
96
96
  version: 0.3.2
97
- description: This is a port of the QMachine web service.
97
+ description: Ruby port of QMachine web service + in-progress client
98
98
  email: sean@mathbiol.org
99
99
  executables: []
100
100
  extensions: []
@@ -129,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
129
  version: '0'
130
130
  requirements: []
131
131
  rubyforge_project:
132
- rubygems_version: 2.4.4
132
+ rubygems_version: 2.4.5
133
133
  signing_key:
134
134
  specification_version: 4
135
135
  summary: 'QMachine: A platform for World Wide Computing'