rhoconnect 3.2.1 → 3.3.1.beta2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +24 -5
- data/Gemfile +2 -2
- data/Gemfile.lock +20 -20
- data/bench/benchapp/Gemfile +17 -20
- data/bench/benchapp/config.ru +2 -2
- data/bench/benchapp/settings/settings.yml +3 -3
- data/bench/blobapp/Gemfile +16 -13
- data/bench/blobapp/config.ru +2 -2
- data/bench/blobapp/settings/settings.yml +5 -3
- data/bench/lib/bench.rb +35 -32
- data/bench/lib/bench/session.rb +9 -1
- data/bench/scripts/blob_cud_script.rb +13 -17
- data/bench/scripts/cud_script.rb +11 -12
- data/bench/scripts/helpers.rb +5 -7
- data/bench/scripts/query_md_script.rb +18 -12
- data/bench/scripts/query_only_script.rb +19 -11
- data/bench/scripts/query_script.rb +17 -13
- data/bench/scripts/test_query_script.rb +46 -17
- data/bench/scripts/test_source_script.rb +7 -7
- data/commands/commands/dtach_commands/dtach_install.rb +44 -16
- data/commands/commands/rhoconnect/spec.rb +13 -9
- data/commands/commands/rhoconnect/version.rb +6 -0
- data/commands/execute.rb +10 -6
- data/doc/deploying.txt +75 -13
- data/doc/install.txt +3 -3
- data/doc/push-client-setup.txt +1 -1
- data/doc/rest-api.txt +4 -23
- data/doc/rhoconnect-redis-stack.txt +26 -7
- data/doc/settings.txt +9 -3
- data/examples/simple/Gemfile +3 -1
- data/examples/simple/application.rb +5 -0
- data/examples/simple/config.ru +3 -2
- data/examples/simple/my_server.rb +14 -0
- data/examples/simple/settings/settings.yml +1 -0
- data/generators/templates/application/Gemfile +4 -4
- data/generators/templates/application/application.rb +4 -0
- data/generators/templates/application/settings/settings.yml +4 -1
- data/installer/unix-like/create_texts.rb +39 -1
- data/installer/unix-like/rho_connect_install_constants.rb +1 -1
- data/installer/utils/package_upload/repos.rake +7 -5
- data/lib/rhoconnect.rb +3 -2
- data/lib/rhoconnect/api/app/ans_login.rb +3 -0
- data/lib/rhoconnect/api/app/bulk_data.rb +6 -0
- data/lib/rhoconnect/api/{source → app}/fast_delete.rb +1 -1
- data/lib/rhoconnect/api/{source → app}/fast_insert.rb +2 -2
- data/lib/rhoconnect/api/{source → app}/fast_update.rb +2 -2
- data/lib/rhoconnect/api/app/login.rb +5 -0
- data/lib/rhoconnect/api/{source → app}/push_deletes.rb +1 -1
- data/lib/rhoconnect/api/{source → app}/push_objects.rb +1 -1
- data/lib/rhoconnect/api/app/query.rb +4 -0
- data/lib/rhoconnect/api/app/queue_updates.rb +94 -0
- data/lib/rhoconnect/api/app/search.rb +4 -0
- data/lib/rhoconnect/api/client/client_get_db_doc.rb +5 -0
- data/lib/rhoconnect/api/client/client_set_db_doc.rb +8 -0
- data/lib/rhoconnect/api/client/create.rb +7 -0
- data/lib/rhoconnect/api/client/get_client_params.rb +2 -1
- data/lib/rhoconnect/api/client/list_client_docs.rb +2 -1
- data/lib/rhoconnect/api/client/register.rb +12 -0
- data/lib/rhoconnect/api/client/reset.rb +5 -0
- data/lib/rhoconnect/api/{source → readstate}/set_refresh_time.rb +2 -1
- data/lib/rhoconnect/api/source/get_source_params.rb +3 -2
- data/lib/rhoconnect/api/source/list_sources.rb +2 -1
- data/lib/rhoconnect/api/source/update_source_params.rb +3 -3
- data/lib/rhoconnect/api/store/get_db_doc.rb +4 -0
- data/lib/rhoconnect/api/store/set_db_doc.rb +7 -0
- data/lib/rhoconnect/api/system/get_adapter.rb +4 -0
- data/lib/rhoconnect/api/{admin → system}/get_license_info.rb +2 -1
- data/lib/rhoconnect/api/system/login.rb +15 -0
- data/lib/rhoconnect/api/{admin → system}/reset.rb +3 -2
- data/lib/rhoconnect/api/system/save_adapter.rb +4 -0
- data/lib/rhoconnect/api/{admin → system}/stats.rb +2 -1
- data/lib/rhoconnect/api/user/create_user.rb +2 -2
- data/lib/rhoconnect/api/user/delete_client.rb +6 -0
- data/lib/rhoconnect/api/user/delete_user.rb +2 -1
- data/lib/rhoconnect/api/user/list_clients.rb +4 -0
- data/lib/rhoconnect/api/user/list_source_docs.rb +11 -0
- data/lib/rhoconnect/api/user/list_users.rb +1 -1
- data/lib/rhoconnect/api/user/ping.rb +7 -0
- data/lib/rhoconnect/api/user/show_user.rb +3 -0
- data/lib/rhoconnect/api/user/update_user.rb +3 -2
- data/lib/rhoconnect/api/user/user_get_db_doc.rb +5 -0
- data/lib/rhoconnect/api/user/user_set_db_doc.rb +10 -0
- data/lib/rhoconnect/app.rb +12 -2
- data/lib/rhoconnect/async.rb +6 -10
- data/lib/rhoconnect/bulk_data/bulk_data.rb +4 -4
- data/lib/rhoconnect/client.rb +10 -9
- data/lib/rhoconnect/client_sync.rb +24 -19
- data/lib/rhoconnect/document.rb +18 -4
- data/lib/rhoconnect/graph_helper.rb +4 -2
- data/lib/rhoconnect/jobs/bulk_data_job.rb +1 -1
- data/lib/rhoconnect/jobs/ping_job.rb +39 -29
- data/lib/rhoconnect/middleware/admin_user.rb +23 -0
- data/lib/rhoconnect/middleware/body_content_type_parser.rb +35 -0
- data/lib/rhoconnect/{cors.rb → middleware/cors.rb} +1 -0
- data/lib/rhoconnect/middleware/current_app.rb +16 -0
- data/lib/rhoconnect/middleware/current_request.rb +16 -0
- data/lib/rhoconnect/middleware/current_user.rb +17 -0
- data/lib/rhoconnect/middleware/helpers.rb +105 -0
- data/lib/rhoconnect/middleware/login_required.rb +22 -0
- data/lib/rhoconnect/{stats/middleware.rb → middleware/stats.rb} +5 -3
- data/lib/rhoconnect/middleware/x_domain_session_wrapper.rb +58 -0
- data/lib/rhoconnect/ping.rb +1 -0
- data/lib/rhoconnect/ping/apple.rb +18 -16
- data/lib/rhoconnect/ping/blackberry.rb +9 -9
- data/lib/rhoconnect/ping/rhoconnect_push.rb +45 -0
- data/lib/rhoconnect/server.rb +98 -91
- data/lib/rhoconnect/source.rb +5 -1
- data/lib/rhoconnect/source_sync.rb +4 -3
- data/lib/rhoconnect/stats/record.rb +15 -15
- data/lib/rhoconnect/store.rb +253 -75
- data/lib/rhoconnect/tasks.rb +3 -3
- data/lib/rhoconnect/version.rb +1 -1
- data/lib/rhoconnect/web-console/controllers/admins.js +1 -14
- data/lib/rhoconnect/web-console/models/adapter.js +18 -8
- data/lib/rhoconnect/web-console/models/client.js +15 -9
- data/lib/rhoconnect/web-console/models/doc.js +7 -11
- data/lib/rhoconnect/web-console/models/session.js +5 -2
- data/lib/rhoconnect/web-console/models/source.js +55 -36
- data/lib/rhoconnect/web-console/models/user.js +20 -11
- data/lib/rhoconnect/web-console/public/backbone.js +8 -2
- data/lib/rhoconnect/web-console/templates/index.erb +11 -5
- data/lib/rhoconnect/web-console/views/doc.js +6 -8
- data/lib/rhoconnect/web-console/views/edit_user.js +6 -3
- data/lib/rhoconnect/web-console/views/home.js +98 -25
- data/lib/rhoconnect/web-console/views/index.js +1 -1
- data/lib/rhoconnect/web-console/views/new_ping.js +6 -3
- data/lib/rhoconnect/web-console/views/server_doc.js +12 -4
- data/lib/rhoconnect/web-console/views/show_device.js +6 -3
- data/rhoconnect.gemspec +1 -2
- data/spec/api/{source → app}/fast_delete_spec.rb +4 -4
- data/spec/api/{source → app}/fast_insert_spec.rb +4 -4
- data/spec/api/{source → app}/fast_update_spec.rb +22 -6
- data/spec/api/{source → app}/push_deletes_spec.rb +2 -2
- data/spec/api/app/push_objects_spec.rb +45 -0
- data/spec/api/client/client_get_db_doc_spec.rb +31 -0
- data/spec/api/client/client_set_db_doc_spec.rb +14 -0
- data/spec/api/client/get_client_params_spec.rb +3 -2
- data/spec/api/client/list_client_docs_spec.rb +2 -2
- data/spec/api/{source → readstate}/set_refresh_time_spec.rb +15 -9
- data/spec/api/source/get_source_params_spec.rb +3 -2
- data/spec/api/source/list_sources_spec.rb +3 -9
- data/spec/api/source/update_source_params_spec.rb +4 -4
- data/spec/api/store/get_db_doc_spec.rb +32 -0
- data/spec/api/store/set_db_doc_spec.rb +43 -0
- data/spec/api/system/adapter_spec.rb +33 -0
- data/spec/api/{admin → system}/get_license_info_spec.rb +2 -5
- data/spec/api/{admin/get_api_token_spec.rb → system/login_spec.rb} +4 -11
- data/spec/api/{admin → system}/reset_spec.rb +2 -2
- data/spec/api/{admin → system}/stats_spec.rb +19 -13
- data/spec/api/user/create_user_spec.rb +15 -8
- data/spec/api/{client → user}/delete_client_spec.rb +3 -4
- data/spec/api/user/delete_user_spec.rb +33 -4
- data/spec/api/user/list_clients_spec.rb +30 -0
- data/spec/api/user/list_source_docs_spec.rb +35 -0
- data/spec/api/user/list_users_spec.rb +5 -6
- data/spec/api/{client → user}/ping_spec.rb +4 -6
- data/spec/api/user/show_user_spec.rb +14 -0
- data/spec/api/user/update_user_spec.rb +28 -10
- data/spec/api/user/user_get_db_doc_spec.rb +16 -0
- data/spec/api/user/user_set_db_doc_spec.rb +41 -0
- data/spec/apps/rhotestapp/application.rb +4 -0
- data/spec/apps/rhotestapp/settings/settings.yml +3 -1
- data/spec/bulk_data/bulk_data_spec.rb +13 -0
- data/spec/client_sync_spec.rb +41 -59
- data/spec/document_spec.rb +23 -0
- data/spec/javascripts/doc_view_spec.js +1 -1
- data/spec/javascripts/home_view_spec.js +10 -5
- data/spec/javascripts/index_view_spec.js +1 -1
- data/spec/jobs/ping_job_spec.rb +26 -0
- data/spec/perf/store_perf_spec.rb +1 -1
- data/spec/ping/android_spec.rb +0 -7
- data/spec/ping/apple_spec.rb +7 -0
- data/spec/ping/blackberry_spec.rb +10 -0
- data/spec/ping/rhoconnect_push_spec.rb +58 -0
- data/spec/server/cors_spec.rb +1 -1
- data/spec/server/server_spec.rb +152 -104
- data/spec/{stats/middleware_spec.rb → server/stats_spec.rb} +4 -5
- data/spec/server/x_domain_session_wrapper_spec.rb +3 -3
- data/spec/source_spec.rb +2 -2
- data/spec/source_sync_spec.rb +2 -0
- data/spec/spec_helper.rb +17 -3
- data/spec/stats/record_spec.rb +18 -19
- data/spec/store_spec.rb +51 -26
- data/spec/support/shared_examples.rb +4 -0
- data/spec/sync_states_spec.rb +2 -2
- metadata +104 -88
- data/bench/benchapp/Gemfile.lock +0 -87
- data/bench/blobapp/Gemfile.lock +0 -107
- data/bench/lib/testdata/5-data.txt +0 -8
- data/doc/release.txt +0 -41
- data/lib/rhoconnect/api/admin/get_api_token.rb +0 -14
- data/lib/rhoconnect/api/admin/login.rb +0 -6
- data/lib/rhoconnect/api/application/bulk_data.rb +0 -7
- data/lib/rhoconnect/api/application/clientcreate.rb +0 -8
- data/lib/rhoconnect/api/application/clientlogin.rb +0 -6
- data/lib/rhoconnect/api/application/clientregister.rb +0 -13
- data/lib/rhoconnect/api/application/clientreset.rb +0 -6
- data/lib/rhoconnect/api/application/query.rb +0 -7
- data/lib/rhoconnect/api/application/queue_updates.rb +0 -20
- data/lib/rhoconnect/api/application/search.rb +0 -6
- data/lib/rhoconnect/api/client/create_client.rb +0 -3
- data/lib/rhoconnect/api/client/delete_client.rb +0 -5
- data/lib/rhoconnect/api/client/list_clients.rb +0 -3
- data/lib/rhoconnect/api/client/ping.rb +0 -7
- data/lib/rhoconnect/api/source/get_adapter.rb +0 -3
- data/lib/rhoconnect/api/source/get_db_doc.rb +0 -7
- data/lib/rhoconnect/api/source/list_source_docs.rb +0 -10
- data/lib/rhoconnect/api/source/save_adapter.rb +0 -3
- data/lib/rhoconnect/api/source/set_db_doc.rb +0 -10
- data/lib/rhoconnect/api/source/upload_file.rb +0 -4
- data/lib/rhoconnect/body_content_type_parser.rb +0 -32
- data/lib/rhoconnect/x_domain_session_wrapper.rb +0 -53
- data/spec/api/admin/api_token_spec.rb +0 -13
- data/spec/api/client/create_client_spec.rb +0 -13
- data/spec/api/client/list_clients_spec.rb +0 -22
- data/spec/api/source/adapter_spec.rb +0 -29
- data/spec/api/source/get_db_doc_spec.rb +0 -21
- data/spec/api/source/list_source_docs_spec.rb +0 -25
- data/spec/api/source/push_objects_spec.rb +0 -27
- data/spec/api/source/set_db_doc_spec.rb +0 -32
- data/spec/api/source/upload_file_spec.rb +0 -26
@@ -7,17 +7,17 @@ module Rhoconnect
|
|
7
7
|
settings = get_config(Rhoconnect.base_directory)[Rhoconnect.environment]
|
8
8
|
host = settings[:mdsserver]
|
9
9
|
port = settings[:mdsserverport]
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
if (host and port)
|
11
|
+
headers = { "X-WAP-APPLICATION-ID" => "/",
|
12
|
+
"X-RIM-PUSH-DEST-PORT" => params['device_port'],
|
13
|
+
"CONTENT-TYPE" => 'multipart/related; type="application/xml"; boundary=asdlfkjiurwghasf'}
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
Net::HTTP.new(host,port).start do |http|
|
16
|
+
request = Net::HTTP::Post.new('/pap',headers)
|
17
|
+
request.body = pap_message(params)
|
18
|
+
http.request(request)
|
19
|
+
end
|
19
20
|
end
|
20
|
-
|
21
21
|
rescue Exception => error
|
22
22
|
log "Error while sending ping: #{error}"
|
23
23
|
raise error
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
module Rhoconnect
|
4
|
+
class RhoconnectPush
|
5
|
+
class InvalidPushServer < Exception; end
|
6
|
+
class InvalidPushRequest < Exception; end
|
7
|
+
|
8
|
+
def self.ping(params)
|
9
|
+
begin
|
10
|
+
settings = get_config(Rhoconnect.base_directory)[Rhoconnect.environment]
|
11
|
+
if settings and settings[:push_server]
|
12
|
+
server = URI.join(settings[:push_server], "/messageQueue/#{params['device_pin']}")
|
13
|
+
RestClient.post(
|
14
|
+
server.to_s,self.push_message(params),:content_type => :json
|
15
|
+
) do |response, request, result, &block|
|
16
|
+
case response.code
|
17
|
+
when 200, 204
|
18
|
+
response.return!(request, result, &block)
|
19
|
+
when 400
|
20
|
+
raise InvalidPushRequest.new("Invalid push request.")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
else
|
24
|
+
raise InvalidPushServer.new("Missing or invalid `:push_server` in settings/settings.yml.")
|
25
|
+
end
|
26
|
+
rescue Exception => error
|
27
|
+
log "RhoConnect Push Error: #{error}"
|
28
|
+
log error.backtrace.join("\n")
|
29
|
+
raise error
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Generates push package
|
34
|
+
def self.push_message(params)
|
35
|
+
data = {}
|
36
|
+
data['collapseId'] = params['badge'].to_i if params['badge']
|
37
|
+
data['data'] = {}
|
38
|
+
data['data']['message'] = params['message'] if params['message']
|
39
|
+
data['data']['sound'] = params['sound'] if params['sound']
|
40
|
+
data['data']['vibrate'] = params['vibrate'] if params['vibrate']
|
41
|
+
data['data']['do_sync'] = params['sources'] if params['sources']
|
42
|
+
data.to_json
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/rhoconnect/server.rb
CHANGED
@@ -4,9 +4,9 @@ require 'erb'
|
|
4
4
|
require 'json'
|
5
5
|
require 'fileutils'
|
6
6
|
require 'rhoconnect'
|
7
|
-
|
8
|
-
|
9
|
-
require
|
7
|
+
|
8
|
+
# all middlewares
|
9
|
+
Dir[File.join(File.dirname(__FILE__),'middleware','**','*.rb')].each { |mw| require mw }
|
10
10
|
|
11
11
|
module Rhoconnect
|
12
12
|
|
@@ -34,23 +34,30 @@ module Rhoconnect
|
|
34
34
|
set :use_middleware, Proc.new {
|
35
35
|
return false if @middleware_configured # Middleware might be configured only once!
|
36
36
|
|
37
|
-
use XDomainSessionWrapper
|
37
|
+
use Rhoconnect::Middleware::XDomainSessionWrapper
|
38
38
|
use Rack::Cors do |cfg|
|
39
39
|
cfg.allow do |allow|
|
40
|
-
allow.origins
|
40
|
+
allow.origins(/.*/)
|
41
41
|
allow.resource '/application', :headers => :any, :methods => [:get, :post, :put, :delete], :credentials => true
|
42
42
|
allow.resource '/application/*', :headers => :any, :methods => [:get, :post, :put, :delete], :credentials => true
|
43
43
|
allow.resource '/api/application', :headers => :any, :methods => [:get, :post, :put, :delete], :credentials => true
|
44
44
|
allow.resource '/api/application/*', :headers => :any, :methods => [:get, :post, :put, :delete], :credentials => true
|
45
|
+
allow.resource "/app/#{Rhoconnect::API_VERSION}/*", :headers => :any, :methods => [:get, :post, :put, :delete], :credentials => true
|
46
|
+
allow.resource "/rc/#{Rhoconnect::API_VERSION}/app/*", :headers => :any, :methods => [:get, :post, :put, :delete], :credentials => true
|
45
47
|
end
|
46
48
|
end
|
47
|
-
use Rhoconnect::BodyContentTypeParser
|
48
|
-
use Rhoconnect::Stats
|
49
|
+
use Rhoconnect::Middleware::BodyContentTypeParser
|
50
|
+
use Rhoconnect::Middleware::Stats
|
49
51
|
Rhoconnect::Server.set :secret, @secret unless settings.respond_to?(:secret)
|
50
52
|
use Rack::Session::Cookie,
|
51
53
|
:key => 'rhoconnect_session', :expire_after => Rhoconnect.cookie_expire,
|
52
54
|
:secret => Rhoconnect::Server.secret
|
53
|
-
|
55
|
+
use Rhoconnect::Middleware::CurrentRequest
|
56
|
+
use Rhoconnect::Middleware::CurrentApp
|
57
|
+
use Rhoconnect::Middleware::CurrentUser
|
58
|
+
use Rhoconnect::Middleware::AdminUser
|
59
|
+
use Rhoconnect::Middleware::LoginRequired
|
60
|
+
|
54
61
|
@middleware_configured ||= true
|
55
62
|
}
|
56
63
|
|
@@ -59,14 +66,9 @@ module Rhoconnect
|
|
59
66
|
request.env['PATH_INFO'].split('/').last
|
60
67
|
end
|
61
68
|
|
62
|
-
def
|
63
|
-
request_action == 'login' or request_action == 'get_api_token' or
|
64
|
-
(params[:api_token] and ApiToken.is_exist?(params[:api_token]))
|
65
|
-
end
|
66
|
-
|
67
|
-
def do_login
|
69
|
+
def check_login
|
68
70
|
begin
|
69
|
-
|
71
|
+
yield
|
70
72
|
rescue LoginException => le
|
71
73
|
throw :halt, [401, le.message]
|
72
74
|
rescue Exception => e
|
@@ -74,9 +76,21 @@ module Rhoconnect
|
|
74
76
|
end
|
75
77
|
end
|
76
78
|
|
77
|
-
def
|
78
|
-
|
79
|
-
|
79
|
+
def do_login
|
80
|
+
check_login do
|
81
|
+
if login
|
82
|
+
status(200)
|
83
|
+
else
|
84
|
+
raise LoginException.new("Unable to authenticate '#{params[:login]}'")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def do_ans_login
|
90
|
+
check_login do
|
91
|
+
ans_login ? status(204) : status(401)
|
92
|
+
end
|
93
|
+
end
|
80
94
|
|
81
95
|
def login
|
82
96
|
if params[:login].nil? or params[:login].empty?
|
@@ -95,33 +109,42 @@ module Rhoconnect
|
|
95
109
|
end
|
96
110
|
end
|
97
111
|
|
112
|
+
def ans_login
|
113
|
+
if current_app and current_app.can_ans_authenticate?
|
114
|
+
auth = Rack::Auth::Basic::Request.new(request.env)
|
115
|
+
current_app.ans_authenticate(
|
116
|
+
auth.credentials.first, auth.credentials.last
|
117
|
+
) if auth.provided? and auth.basic? and auth.credentials
|
118
|
+
else
|
119
|
+
false
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
98
123
|
def logout
|
99
124
|
session[:login] = nil
|
100
125
|
end
|
101
126
|
|
102
127
|
def current_user
|
103
|
-
|
104
|
-
@user = User.load(session[:login])
|
105
|
-
end
|
106
|
-
if @user and (@user.admin == 1 || session[:app_name] == APP_NAME)
|
107
|
-
@user
|
108
|
-
else
|
109
|
-
nil
|
110
|
-
end
|
128
|
+
@env[Rhoconnect::CURRENT_USER]
|
111
129
|
end
|
112
130
|
|
113
|
-
def
|
114
|
-
|
115
|
-
current_user
|
116
|
-
else
|
117
|
-
u = ApiToken.load(params[:api_token])
|
118
|
-
raise "Wrong API token - #{params[:api_token].inspect}" unless u
|
119
|
-
u.user
|
120
|
-
end
|
131
|
+
def current_app
|
132
|
+
@env[Rhoconnect::CURRENT_APP]
|
121
133
|
end
|
122
134
|
|
123
|
-
def
|
124
|
-
|
135
|
+
def current_client
|
136
|
+
if @client.nil?
|
137
|
+
client_id = @env[Rhoconnect::CLIENT_ID_HEADER]
|
138
|
+
client_id = params[:client_id] unless client_id
|
139
|
+
if client_id
|
140
|
+
@client = Client.load(client_id.to_s,
|
141
|
+
params[:source_name] ? {:source_name => current_source.name} : {:source_name => '*'})
|
142
|
+
if @client and current_user and @client.user_id != current_user.login
|
143
|
+
@client.switch_user(current_user.login)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
@client
|
125
148
|
end
|
126
149
|
|
127
150
|
def current_source
|
@@ -144,17 +167,6 @@ module Rhoconnect
|
|
144
167
|
end
|
145
168
|
end
|
146
169
|
|
147
|
-
def current_client
|
148
|
-
if @client.nil? and params[:client_id]
|
149
|
-
@client = Client.load(params[:client_id].to_s,
|
150
|
-
params[:source_name] ? {:source_name => current_source.name} : {:source_name => '*'})
|
151
|
-
if @client and current_user and @client.user_id != current_user.login
|
152
|
-
@client.switch_user(current_user.login)
|
153
|
-
end
|
154
|
-
@client
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
170
|
def current_client_sync
|
159
171
|
ClientSync.new(current_source,current_client,params[:p_size])
|
160
172
|
end
|
@@ -183,18 +195,22 @@ module Rhoconnect
|
|
183
195
|
end
|
184
196
|
end
|
185
197
|
|
198
|
+
def mark_deprecated_call_and_reroute_api4(verb, new_route, old_verb, old_route, client_call, &block)
|
199
|
+
warning_message = "Use of the #{old_verb.to_s.upcase} #{old_route} is deprecated. Use Rhoconnect API #{Rhoconnect::API_VERSION} instead."
|
200
|
+
response.headers['Warning'] = warning_message
|
201
|
+
Rhoconnect.log warning_message
|
202
|
+
|
203
|
+
execute_api_call(client_call, &block)
|
204
|
+
end
|
205
|
+
|
186
206
|
def execute_api_call(client_call = false)
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
response.headers['Warning'] = params[:warning]
|
193
|
-
end
|
194
|
-
res
|
207
|
+
catch_all do
|
208
|
+
res = yield params, current_user, self
|
209
|
+
if params.has_key? :warning
|
210
|
+
Rhoconnect.log params[:warning]
|
211
|
+
response.headers['Warning'] = params[:warning]
|
195
212
|
end
|
196
|
-
|
197
|
-
throw :halt, [422, "No API token provided"]
|
213
|
+
res
|
198
214
|
end
|
199
215
|
end
|
200
216
|
end
|
@@ -269,47 +285,24 @@ _INSTALL_ASYNC_GEMS
|
|
269
285
|
before do
|
270
286
|
cache_control :no_cache
|
271
287
|
headers({'pragma'=>'no-cache'})
|
272
|
-
|
273
|
-
if params[:version] and params[:version].to_i < 3
|
274
|
-
throw :halt, [404, "Server supports version 3 or higher of the protocol."]
|
275
|
-
end
|
276
288
|
end
|
277
|
-
|
289
|
+
|
278
290
|
get '/' do
|
279
291
|
redirect "/console/"
|
280
292
|
end
|
281
293
|
|
282
|
-
%w[get post].each do |verb|
|
283
|
-
send(verb, "/*application*") do
|
284
|
-
unless request_action == 'clientlogin'
|
285
|
-
throw :halt, [401, "Not authenticated"] if login_required
|
286
|
-
end
|
287
|
-
pass
|
288
|
-
end
|
289
|
-
end
|
290
|
-
|
291
|
-
# old routes
|
292
|
-
post '/login' do
|
293
|
-
mark_deprecated_call_and_reroute(:login, :admin, self, params)
|
294
|
-
end
|
295
|
-
get '/application' do
|
296
|
-
mark_deprecated_call_and_reroute(:query, :application, self, params)
|
297
|
-
end
|
298
|
-
post '/application' do
|
299
|
-
mark_deprecated_call_and_reroute(:queue_updates, :application, self, params)
|
300
|
-
end
|
301
|
-
# confusion routes - only because Rhodes didn't switch
|
302
|
-
# to new style API yet
|
303
|
-
get '/api/application' do
|
304
|
-
mark_deprecated_call_and_reroute(:query, :application, self, params)
|
305
|
-
end
|
306
|
-
post '/api/application' do
|
307
|
-
mark_deprecated_call_and_reroute(:queue_updates, :application, self, params)
|
308
|
-
end
|
309
|
-
|
310
294
|
def self.api(name, namespace = nil, verb = :post, &block)
|
295
|
+
# this method is deprecated - so we should warn the users
|
296
|
+
# that it will be removed in 4.0
|
297
|
+
warning_for_server_api = <<_DEPRECATE_SERVER_API
|
298
|
+
***** WARNING *****
|
299
|
+
Server.api method is deprecated and will be removed in Rhoconnect 4.0
|
300
|
+
Please change your implementation to Server.api4
|
301
|
+
_DEPRECATE_SERVER_API
|
302
|
+
puts warning_for_server_api
|
303
|
+
|
311
304
|
old_api_prefix = (namespace == :application) ? :application : :api
|
312
|
-
client_call = (namespace == :application) ? true : false
|
305
|
+
client_call = (namespace == :application) ? true : false
|
313
306
|
send verb, "/#{old_api_prefix}/#{name}" do
|
314
307
|
mark_deprecated_call_and_reroute(name, namespace, params, &block)
|
315
308
|
end
|
@@ -318,6 +311,20 @@ _INSTALL_ASYNC_GEMS
|
|
318
311
|
execute_api_call(client_call, &block)
|
319
312
|
end
|
320
313
|
end
|
314
|
+
|
315
|
+
def self.api4(method_name, verb, route, admin = true, deprecated_route = nil, &block)
|
316
|
+
unless deprecated_route.nil?
|
317
|
+
deprecated_urls = deprecated_route[:url].is_a?(String) ? [deprecated_route[:url]] : deprecated_route[:url]
|
318
|
+
deprecated_urls.each do |deprecated_url|
|
319
|
+
send deprecated_route[:verb], deprecated_url do
|
320
|
+
mark_deprecated_call_and_reroute_api4(verb, route, deprecated_route[:verb], deprecated_url, !admin, &block)
|
321
|
+
end
|
322
|
+
end
|
323
|
+
end
|
324
|
+
send verb, route do
|
325
|
+
execute_api_call(!admin, &block)
|
326
|
+
end
|
327
|
+
end
|
321
328
|
end
|
322
329
|
end
|
323
330
|
|
data/lib/rhoconnect/source.rb
CHANGED
@@ -186,7 +186,11 @@ module Rhoconnect
|
|
186
186
|
blob_attribs = []
|
187
187
|
schema['property'].each do |key,value|
|
188
188
|
values = value ? value.split(',') : []
|
189
|
-
|
189
|
+
if values.include?('blob')
|
190
|
+
attrib = key.dup
|
191
|
+
attrib << "," + (values.include?('overwrite') ? '1' : '0')
|
192
|
+
blob_attribs << attrib
|
193
|
+
end
|
190
194
|
end
|
191
195
|
blob_attribs.sort.join(',')
|
192
196
|
end
|
@@ -91,7 +91,7 @@ module Rhoconnect
|
|
91
91
|
def do_query(params=nil)
|
92
92
|
result = nil
|
93
93
|
@source.if_need_refresh do
|
94
|
-
Stats::Record.update("source:query:#{@source.name}") do
|
94
|
+
Rhoconnect::Stats::Record.update("source:query:#{@source.name}") do
|
95
95
|
if _auth_op('login')
|
96
96
|
result = self.read(nil,params)
|
97
97
|
_auth_op('logoff')
|
@@ -239,7 +239,7 @@ module Rhoconnect
|
|
239
239
|
end
|
240
240
|
|
241
241
|
def _measure_and_process_cud(operation)
|
242
|
-
Stats::Record.update("source:#{operation}:#{@source.name}") do
|
242
|
+
Rhoconnect::Stats::Record.update("source:#{operation}:#{@source.name}") do
|
243
243
|
_process_cud(operation)
|
244
244
|
end
|
245
245
|
end
|
@@ -354,9 +354,10 @@ module Rhoconnect
|
|
354
354
|
if operation == 'delete'
|
355
355
|
# Clean up deleted objects from master document and corresponding client document
|
356
356
|
total_dels = {}
|
357
|
+
objs = {}
|
357
358
|
dels.each do |client_id,client_doc|
|
358
359
|
next if client_doc.empty?
|
359
|
-
client = processed_clients[client_id]
|
360
|
+
client = processed_clients[client_id]
|
360
361
|
client.delete_data(:cd,client_doc)
|
361
362
|
client.update_count(:cd_size,-client_doc.size)
|
362
363
|
total_dels.merge!(client_doc)
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module Rhoconnect
|
2
|
-
|
2
|
+
class Stats
|
3
3
|
class Record
|
4
4
|
class << self
|
5
|
-
|
5
|
+
|
6
6
|
# Add a value to a metric. If zset already has a member,
|
7
7
|
# update the existing member with an incremented value by default.
|
8
8
|
# Also supports updating the value with a block (useful for averages)
|
@@ -25,11 +25,11 @@ module Rhoconnect
|
|
25
25
|
Store.db.zremrangebyscore(key(metric), 0, start - record_size(metric))
|
26
26
|
end
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
def add(metric, value = 1)
|
30
30
|
set(metric,value) { |current,value| current.to_i + value }
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
# Saves the accumulated average for a resolution in a metric
|
34
34
|
def save_average(metric, value)
|
35
35
|
set(metric,value) do |current,value|
|
@@ -42,7 +42,7 @@ module Rhoconnect
|
|
42
42
|
"#{current + 1},#{sum}"
|
43
43
|
end
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
def update(metric)
|
47
47
|
if Rhoconnect.stats
|
48
48
|
start = Time.now.to_f
|
@@ -54,51 +54,51 @@ module Rhoconnect
|
|
54
54
|
yield
|
55
55
|
end
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
def keys(glob='*')
|
59
59
|
Store.db.keys(key(glob)).collect {|c| c[5..-1]}
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
def reset(metric)
|
63
63
|
Store.db.del(key(metric))
|
64
64
|
end
|
65
|
-
|
65
|
+
|
66
66
|
def reset_all
|
67
67
|
Store.flash_data('stat:*')
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
# Returns simple string metric
|
71
71
|
def get_value(metric)
|
72
72
|
Store.get_value(key(metric))
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
# Sets a string metric
|
76
76
|
def set_value(metric, value)
|
77
77
|
Store.set_value(key(metric), value)
|
78
78
|
end
|
79
|
-
|
79
|
+
|
80
80
|
# Returns the metric data, uses array indexing
|
81
81
|
def range(metric, start, finish = -1)
|
82
82
|
Store.db.zrange(key(metric), start, finish)
|
83
83
|
end
|
84
|
-
|
84
|
+
|
85
85
|
# Returns the resolution for a given metric, default 60 seconds
|
86
86
|
def resolution(metric)
|
87
87
|
resolution = STATS_RECORD_RESOLUTION rescue nil
|
88
88
|
resolution || 60 #=> 1 minute aggregate
|
89
89
|
end
|
90
|
-
|
90
|
+
|
91
91
|
# Returns the # of records to save for a given metric
|
92
92
|
def record_size(metric)
|
93
93
|
size = STATS_RECORD_SIZE rescue nil
|
94
94
|
size || 60 * 24 * 31 #=> 44640 minutes
|
95
95
|
end
|
96
|
-
|
96
|
+
|
97
97
|
# Returns redis object type for a record
|
98
98
|
def rtype(metric)
|
99
99
|
Store.db.type(key(metric))
|
100
100
|
end
|
101
|
-
|
101
|
+
|
102
102
|
def key(metric)
|
103
103
|
"stat:#{metric}"
|
104
104
|
end
|