hyper-operation 0.99.6 → 1.0.alpha1
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 +4 -4
- data/Gemfile +2 -2
- data/Gemfile.lock +44 -35
- data/hyper-operation.gemspec +7 -7
- data/lib/hyper-operation.rb +6 -5
- data/lib/hyper-operation/api.rb +2 -2
- data/lib/hyper-operation/boot.rb +3 -2
- data/lib/hyper-operation/engine.rb +2 -2
- data/lib/hyper-operation/exception.rb +2 -2
- data/lib/hyper-operation/filters/acting_user.rb +1 -1
- data/lib/hyper-operation/http.rb +2 -2
- data/lib/hyper-operation/railway.rb +1 -1
- data/lib/hyper-operation/railway/dispatcher.rb +8 -4
- data/lib/hyper-operation/railway/params_wrapper.rb +2 -2
- data/lib/hyper-operation/railway/run.rb +1 -1
- data/lib/hyper-operation/railway/validations.rb +1 -1
- data/lib/hyper-operation/server_op.rb +15 -15
- data/lib/hyper-operation/transport/action_cable.rb +8 -8
- data/lib/hyper-operation/transport/client_drivers.rb +36 -36
- data/lib/hyper-operation/transport/connection.rb +10 -10
- data/lib/hyper-operation/transport/{hyperloop.rb → hyperstack.rb} +13 -13
- data/lib/hyper-operation/transport/{hyperloop_controller.rb → hyperstack_controller.rb} +51 -51
- data/lib/hyper-operation/transport/policy.rb +25 -25
- data/lib/hyper-operation/version.rb +2 -2
- data/lib/sources/{hyperloop → hyperstack}/pusher.js +0 -0
- metadata +15 -18
- data/DOCS-POLICIES.md +0 -582
- data/DOCS.md +0 -869
- data/LICENSE.txt +0 -21
- data/README.md +0 -77
@@ -3,7 +3,7 @@ module ApplicationCable
|
|
3
3
|
class Connection < ActionCable::Connection::Base; end
|
4
4
|
end
|
5
5
|
|
6
|
-
module
|
6
|
+
module Hyperstack
|
7
7
|
class ActionCableChannel < ApplicationCable::Channel
|
8
8
|
class << self
|
9
9
|
def subscriptions
|
@@ -12,28 +12,28 @@ module Hyperloop
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def inc_subscription
|
15
|
-
self.class.subscriptions[params[:
|
16
|
-
self.class.subscriptions[params[:
|
15
|
+
self.class.subscriptions[params[:hyperstack_channel]] =
|
16
|
+
self.class.subscriptions[params[:hyperstack_channel]] + 1
|
17
17
|
end
|
18
18
|
|
19
19
|
def dec_subscription
|
20
|
-
self.class.subscriptions[params[:
|
21
|
-
self.class.subscriptions[params[:
|
20
|
+
self.class.subscriptions[params[:hyperstack_channel]] =
|
21
|
+
self.class.subscriptions[params[:hyperstack_channel]] - 1
|
22
22
|
end
|
23
23
|
|
24
24
|
def subscribed
|
25
25
|
session_id = params["client_id"]
|
26
|
-
authorization =
|
26
|
+
authorization = Hyperstack.authorization(params["salt"], params["hyperstack_channel"], session_id)
|
27
27
|
if params["authorization"] == authorization
|
28
28
|
inc_subscription
|
29
|
-
stream_from "
|
29
|
+
stream_from "hyperstack-#{params[:hyperstack_channel]}"
|
30
30
|
else
|
31
31
|
reject
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
35
|
def unsubscribed
|
36
|
-
|
36
|
+
Hyperstack::Connection.disconnect(params[:hyperstack_channel]) if dec_subscription == 0
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
#### this is going to need some refactoring so that HyperMesh can add its methods in here...
|
2
2
|
|
3
|
-
module
|
3
|
+
module Hyperstack
|
4
4
|
# Client side handling of synchronization messages
|
5
5
|
# When a synchronization message comes in, the client will sync_dispatch
|
6
6
|
# We use ERB to determine the configuration and implement the appropriate
|
7
7
|
# client interface to sync_change or sync_destroy
|
8
8
|
|
9
9
|
class Application
|
10
|
-
extend
|
10
|
+
extend Component::IsomorphicHelpers::ClassMethods
|
11
11
|
|
12
12
|
if on_opal_client?
|
13
13
|
def self.acting_user_id
|
@@ -46,7 +46,7 @@ module Hyperloop
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def self.connect_session
|
49
|
-
connect(['
|
49
|
+
connect(['Hyperstack::Session', ClientDrivers.opts[:id].split('-').last])
|
50
50
|
end
|
51
51
|
|
52
52
|
def self.action_cable_consumer
|
@@ -76,14 +76,14 @@ module Hyperloop
|
|
76
76
|
}
|
77
77
|
elsif ClientDrivers.opts[:transport] == :action_cable
|
78
78
|
channel = "#{ClientDrivers.opts[:channel]}-#{channel_string}"
|
79
|
-
|
79
|
+
Hyperstack::HTTP.post(ClientDrivers.polling_path('action-cable-auth', channel), headers: { 'X-CSRF-Token' => ClientDrivers.opts[:form_authenticity_token] }).then do |response|
|
80
80
|
%x{
|
81
81
|
var fix_opal_0110 = 'return';
|
82
|
-
#{
|
82
|
+
#{Hyperstack.action_cable_consumer}.subscriptions.create(
|
83
83
|
{
|
84
|
-
channel: "
|
84
|
+
channel: "Hyperstack::ActionCableChannel",
|
85
85
|
client_id: #{ClientDrivers.opts[:id]},
|
86
|
-
|
86
|
+
hyperstack_channel: #{channel_string},
|
87
87
|
authorization: #{response.json[:authorization]},
|
88
88
|
salt: #{response.json[:salt]}
|
89
89
|
},
|
@@ -101,14 +101,14 @@ module Hyperloop
|
|
101
101
|
}
|
102
102
|
end
|
103
103
|
else
|
104
|
-
|
104
|
+
Hyperstack::HTTP.get(ClientDrivers.polling_path(:subscribe, channel_string))
|
105
105
|
end
|
106
106
|
end
|
107
107
|
end
|
108
108
|
end
|
109
109
|
|
110
110
|
class ClientDrivers
|
111
|
-
include
|
111
|
+
include Hyperstack::Component::IsomorphicHelpers
|
112
112
|
|
113
113
|
def self.sync_dispatch(data)
|
114
114
|
# TODO old synchromesh double checked at this point to make sure that this client
|
@@ -116,7 +116,7 @@ module Hyperloop
|
|
116
116
|
data[:operation].constantize.dispatch_from_server(data[:params])
|
117
117
|
end
|
118
118
|
|
119
|
-
# save the configuration info needed in window.
|
119
|
+
# save the configuration info needed in window.HyperstackOpts
|
120
120
|
|
121
121
|
# we keep a list of all channels by session with connections in progress
|
122
122
|
# for each broadcast we check the list, and add the message to a queue for that
|
@@ -125,45 +125,45 @@ module Hyperloop
|
|
125
125
|
# will remove the session from the list.
|
126
126
|
|
127
127
|
prerender_footer do |controller|
|
128
|
-
unless
|
128
|
+
unless Hyperstack.transport == :none
|
129
129
|
if defined?(PusherFake)
|
130
130
|
path = ::Rails.application.routes.routes.detect do |route|
|
131
|
-
route.app ==
|
132
|
-
(route.app.respond_to?(:app) && route.app.app ==
|
131
|
+
route.app == Hyperstack::Engine ||
|
132
|
+
(route.app.respond_to?(:app) && route.app.app == Hyperstack::Engine)
|
133
133
|
end.path.spec
|
134
134
|
pusher_fake_js = PusherFake.javascript(
|
135
135
|
auth: { headers: { 'X-CSRF-Token' => controller.send(:form_authenticity_token) } },
|
136
|
-
authEndpoint: "#{path}/
|
136
|
+
authEndpoint: "#{path}/hyperstack-pusher-auth"
|
137
137
|
)
|
138
138
|
end
|
139
|
-
controller.session.delete '
|
139
|
+
controller.session.delete 'hyperstack-dummy-init' unless controller.session.id
|
140
140
|
id = "#{SecureRandom.uuid}-#{controller.session.id}"
|
141
|
-
auto_connections =
|
141
|
+
auto_connections = Hyperstack::AutoConnect.channels(id, controller.acting_user) rescue []
|
142
142
|
end
|
143
143
|
config_hash = {
|
144
|
-
transport:
|
144
|
+
transport: Hyperstack.transport,
|
145
145
|
id: id,
|
146
146
|
acting_user_id: (controller.acting_user && controller.acting_user.id),
|
147
147
|
env: ::Rails.env,
|
148
|
-
client_logging:
|
148
|
+
client_logging: Hyperstack.client_logging,
|
149
149
|
pusher_fake_js: pusher_fake_js,
|
150
|
-
key:
|
151
|
-
cluster:
|
152
|
-
encrypted:
|
153
|
-
channel:
|
150
|
+
key: Hyperstack.key,
|
151
|
+
cluster: Hyperstack.cluster,
|
152
|
+
encrypted: Hyperstack.encrypted,
|
153
|
+
channel: Hyperstack.channel,
|
154
154
|
form_authenticity_token: controller.send(:form_authenticity_token),
|
155
|
-
seconds_between_poll:
|
155
|
+
seconds_between_poll: Hyperstack.seconds_between_poll,
|
156
156
|
auto_connect: auto_connections
|
157
157
|
}
|
158
158
|
path = ::Rails.application.routes.routes.detect do |route|
|
159
159
|
# not sure why the second check is needed. It happens in the test app
|
160
|
-
route.app ==
|
160
|
+
route.app == Hyperstack::Engine or (route.app.respond_to?(:app) and route.app.app == Hyperstack::Engine)
|
161
161
|
end
|
162
|
-
raise '
|
162
|
+
raise 'Hyperstack::Engine mount point not found. Check your config/routes.rb file' unless path
|
163
163
|
path = path.path.spec
|
164
164
|
"<script type='text/javascript'>\n"\
|
165
|
-
"window.
|
166
|
-
"window.
|
165
|
+
"window.HyperstackEnginePath = '#{path}';\n"\
|
166
|
+
"window.HyperstackOpts = #{config_hash.to_json}\n"\
|
167
167
|
"</script>\n"
|
168
168
|
end if RUBY_ENGINE != 'opal'
|
169
169
|
|
@@ -189,7 +189,7 @@ module Hyperloop
|
|
189
189
|
end
|
190
190
|
|
191
191
|
def self.get_queued_data(operation, channel = nil, opts = {})
|
192
|
-
|
192
|
+
Hyperstack::HTTP.get(polling_path(operation, channel), opts).then do |response|
|
193
193
|
response.json.each do |data|
|
194
194
|
`console.log("simple_poller received: ", data)` if ClientDrivers.env == 'development'
|
195
195
|
sync_dispatch(data[1])
|
@@ -201,11 +201,11 @@ module Hyperloop
|
|
201
201
|
|
202
202
|
if @initialized
|
203
203
|
# 1) skip initialization if already initialized
|
204
|
-
if on_opal_client? &&
|
204
|
+
if on_opal_client? && Hyperstack.action_cable_consumer
|
205
205
|
# 2) if running action_cable make sure connection is up after pinging the server_up
|
206
206
|
# action cable closes the connection if files change on the server
|
207
|
-
|
208
|
-
`#{
|
207
|
+
Hyperstack::HTTP.get("#{`window.HyperstackEnginePath`}/server_up") do
|
208
|
+
`#{Hyperstack.action_cable_consumer}.connection.open()` if `#{Hyperstack.action_cable_consumer}.connection.disconnected`
|
209
209
|
end
|
210
210
|
end
|
211
211
|
return
|
@@ -216,7 +216,7 @@ module Hyperloop
|
|
216
216
|
|
217
217
|
if on_opal_client?
|
218
218
|
|
219
|
-
@opts = Hash.new(`window.
|
219
|
+
@opts = Hash.new(`window.HyperstackOpts`)
|
220
220
|
|
221
221
|
|
222
222
|
if opts[:transport] == :pusher
|
@@ -237,18 +237,18 @@ module Hyperloop
|
|
237
237
|
h = {
|
238
238
|
encrypted: #{opts[:encrypted]},
|
239
239
|
cluster: #{opts[:cluster]},
|
240
|
-
authEndpoint: window.
|
240
|
+
authEndpoint: window.HyperstackEnginePath+'/hyperstack-pusher-auth',
|
241
241
|
auth: {headers: {'X-CSRF-Token': #{opts[:form_authenticity_token]}}}
|
242
242
|
};
|
243
243
|
pusher_api = new Pusher(#{opts[:key]}, h)
|
244
244
|
}
|
245
245
|
opts[:pusher_api] = pusher_api
|
246
246
|
end
|
247
|
-
|
247
|
+
Hyperstack.connect(*opts[:auto_connect])
|
248
248
|
elsif opts[:transport] == :action_cable
|
249
249
|
opts[:action_cable_consumer] =
|
250
250
|
`ActionCable.createConsumer.apply(ActionCable, #{[*opts[:action_cable_consumer_url]]})`
|
251
|
-
|
251
|
+
Hyperstack.connect(*opts[:auto_connect])
|
252
252
|
elsif opts[:transport] == :simple_poller
|
253
253
|
opts[:auto_connect].each { |channel| IncomingBroadcast.add_connection(*channel) }
|
254
254
|
every(opts[:seconds_between_poll]) do
|
@@ -259,7 +259,7 @@ module Hyperloop
|
|
259
259
|
end
|
260
260
|
|
261
261
|
def self.polling_path(to, id = nil)
|
262
|
-
s = "#{`window.
|
262
|
+
s = "#{`window.HyperstackEnginePath`}/hyperstack-#{to}/#{opts[:id]}"
|
263
263
|
s = "#{s}/#{id}" if id
|
264
264
|
s
|
265
265
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Hyperstack
|
2
2
|
module AutoCreate
|
3
3
|
def table_exists?
|
4
4
|
# works with both rails 4 and 5 without deprecation warnings
|
@@ -10,7 +10,7 @@ module Hyperloop
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def needs_init?
|
13
|
-
|
13
|
+
Hyperstack.transport != :none && Hyperstack.on_server? && !table_exists?
|
14
14
|
end
|
15
15
|
|
16
16
|
def create_table(*args, &block)
|
@@ -23,18 +23,18 @@ module Hyperloop
|
|
23
23
|
|
24
24
|
extend AutoCreate
|
25
25
|
|
26
|
-
self.table_name = '
|
26
|
+
self.table_name = 'hyperstack_queued_messages'
|
27
27
|
|
28
28
|
do_not_synchronize
|
29
29
|
|
30
30
|
serialize :data
|
31
31
|
|
32
|
-
belongs_to :
|
33
|
-
class_name: '
|
32
|
+
belongs_to :hyperstack_connection,
|
33
|
+
class_name: 'Hyperstack::Connection',
|
34
34
|
foreign_key: 'connection_id'
|
35
35
|
|
36
36
|
scope :for_session,
|
37
|
-
->(session) { joins(:
|
37
|
+
->(session) { joins(:hyperstack_connection).where('session = ?', session) }
|
38
38
|
|
39
39
|
# For simplicity we use QueuedMessage with connection_id 0
|
40
40
|
# to store the current path which is used by consoles to
|
@@ -69,11 +69,11 @@ module Hyperloop
|
|
69
69
|
|
70
70
|
do_not_synchronize
|
71
71
|
|
72
|
-
self.table_name = '
|
72
|
+
self.table_name = 'hyperstack_connections'
|
73
73
|
|
74
74
|
has_many :messages,
|
75
75
|
foreign_key: 'connection_id',
|
76
|
-
class_name: '
|
76
|
+
class_name: 'Hyperstack::Connection::QueuedMessage',
|
77
77
|
dependent: :destroy
|
78
78
|
scope :expired,
|
79
79
|
-> { where('expires_at IS NOT NULL AND expires_at < ?', Time.zone.now) }
|
@@ -106,7 +106,7 @@ module Hyperloop
|
|
106
106
|
# a migration or from a console before the server has ever started
|
107
107
|
# in these cases there are no channels so we return nothing
|
108
108
|
return [] unless table_exists?
|
109
|
-
if
|
109
|
+
if Hyperstack.on_server?
|
110
110
|
expired.delete_all
|
111
111
|
refresh_connections if needs_refresh?
|
112
112
|
end
|
@@ -120,7 +120,7 @@ module Hyperloop
|
|
120
120
|
|
121
121
|
def send_to_channel(channel, data)
|
122
122
|
pending_for(channel).each do |connection|
|
123
|
-
QueuedMessage.create(data: data,
|
123
|
+
QueuedMessage.create(data: data, hyperstack_connection: connection)
|
124
124
|
end
|
125
125
|
transport.send_data(channel, data) if exists?(channel: channel, session: nil)
|
126
126
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# Provides the configuration and the two basic routines for the server
|
2
2
|
# to indicate that records have changed: after_change and after_destroy
|
3
|
-
module
|
3
|
+
module Hyperstack
|
4
4
|
|
5
5
|
def self.initialize_policies
|
6
6
|
reset_operations unless @config_reset_called
|
@@ -13,9 +13,9 @@ module Hyperloop
|
|
13
13
|
def self.reset_operations
|
14
14
|
@config_reset_called = true
|
15
15
|
Rails.configuration.tap do |config|
|
16
|
-
# config.eager_load_paths += %W(#{config.root}/app/
|
17
|
-
# config.autoload_paths += %W(#{config.root}/app/
|
18
|
-
# config.assets.paths << ::Rails.root.join('app', '
|
16
|
+
# config.eager_load_paths += %W(#{config.root}/app/hyperstack/models)
|
17
|
+
# config.autoload_paths += %W(#{config.root}/app/hyperstack/models)
|
18
|
+
# config.assets.paths << ::Rails.root.join('app', 'hyperstack').to_s
|
19
19
|
config.after_initialize { Connection.build_tables }
|
20
20
|
end
|
21
21
|
Object.send(:remove_const, :Application) if @fake_application_defined
|
@@ -37,10 +37,10 @@ module Hyperloop
|
|
37
37
|
@fake_application_defined = true
|
38
38
|
end
|
39
39
|
begin
|
40
|
-
Object.const_get '
|
40
|
+
Object.const_get 'Hyperstack::ApplicationPolicy'
|
41
41
|
rescue LoadError
|
42
42
|
rescue NameError => e
|
43
|
-
raise e unless e.message =~ /uninitialized constant
|
43
|
+
raise e unless e.message =~ /uninitialized constant Hyperstack::ApplicationPolicy/
|
44
44
|
end
|
45
45
|
@pusher = nil
|
46
46
|
end
|
@@ -49,10 +49,10 @@ module Hyperloop
|
|
49
49
|
if transport == :action_cable
|
50
50
|
require 'hyper-operation/transport/action_cable'
|
51
51
|
opts[:refresh_channels_every] = :never
|
52
|
-
import 'action_cable', client_only: true if Rails.configuration.
|
52
|
+
import 'action_cable', client_only: true if Rails.configuration.hyperstack.auto_config
|
53
53
|
elsif transport == :pusher
|
54
54
|
require 'pusher'
|
55
|
-
import '
|
55
|
+
import 'hyperstack/pusher', client_only: true if Rails.configuration.hyperstack.auto_config
|
56
56
|
opts[:refresh_channels_every] = nil if opts[:refresh_channels_every] == :never
|
57
57
|
else
|
58
58
|
opts[:refresh_channels_every] = nil if opts[:refresh_channels_every] == :never
|
@@ -107,7 +107,7 @@ module Hyperloop
|
|
107
107
|
|
108
108
|
def self.refresh_channels
|
109
109
|
new_channels = pusher.channels[:channels].collect do |channel, _etc|
|
110
|
-
channel.gsub(/^#{Regexp.quote(
|
110
|
+
channel.gsub(/^#{Regexp.quote(Hyperstack.channel)}\-/, '').gsub('==', '::')
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
@@ -115,9 +115,9 @@ module Hyperloop
|
|
115
115
|
if !on_server?
|
116
116
|
send_to_server(channel, data)
|
117
117
|
elsif transport == :pusher
|
118
|
-
pusher.trigger("#{
|
118
|
+
pusher.trigger("#{Hyperstack.channel}-#{data[1][:channel].gsub('::', '==')}", *data)
|
119
119
|
elsif transport == :action_cable
|
120
|
-
ActionCable.server.broadcast("
|
120
|
+
ActionCable.server.broadcast("hyperstack-#{channel}", message: data[0], data: data[1])
|
121
121
|
end
|
122
122
|
end
|
123
123
|
|
@@ -167,8 +167,8 @@ module Hyperloop
|
|
167
167
|
end
|
168
168
|
|
169
169
|
def self.dispatch(data)
|
170
|
-
if !
|
171
|
-
|
170
|
+
if !Hyperstack.on_server? && Connection.root_path
|
171
|
+
Hyperstack.send_to_server(data[:channel], [:dispatch, data])
|
172
172
|
else
|
173
173
|
Connection.send_to_channel(data[:channel], [:dispatch, data])
|
174
174
|
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
module
|
2
|
-
::
|
3
|
-
|
1
|
+
module Hyperstack
|
2
|
+
::Hyperstack::Engine.routes.append do
|
3
|
+
Hyperstack.initialize_policies
|
4
4
|
|
5
5
|
module ::WebConsole
|
6
6
|
class Middleware
|
@@ -14,15 +14,15 @@ module Hyperloop
|
|
14
14
|
module ::Rails
|
15
15
|
module Rack
|
16
16
|
class Logger < ActiveSupport::LogSubscriber
|
17
|
-
unless method_defined? :
|
18
|
-
alias
|
17
|
+
unless method_defined? :pre_hyperstack_call
|
18
|
+
alias pre_hyperstack_call call
|
19
19
|
def call(env)
|
20
|
-
if
|
20
|
+
if Hyperstack.transport == :simple_poller && env['PATH_INFO'] && env['PATH_INFO'].include?('/hyperstack-read/')
|
21
21
|
Rails.logger.silence do
|
22
|
-
|
22
|
+
pre_hyperstack_call(env)
|
23
23
|
end
|
24
24
|
else
|
25
|
-
|
25
|
+
pre_hyperstack_call(env)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
@@ -30,7 +30,7 @@ module Hyperloop
|
|
30
30
|
end
|
31
31
|
end if defined?(::Rails::Rack::Logger)
|
32
32
|
|
33
|
-
class
|
33
|
+
class HyperstackController < ::ApplicationController
|
34
34
|
|
35
35
|
protect_from_forgery except: [:console_update, :execute_remote_api]
|
36
36
|
|
@@ -39,28 +39,28 @@ module Hyperloop
|
|
39
39
|
end
|
40
40
|
|
41
41
|
before_action do
|
42
|
-
session.delete '
|
42
|
+
session.delete 'hyperstack-dummy-init' unless session.id
|
43
43
|
end
|
44
44
|
|
45
45
|
def session_channel
|
46
|
-
"
|
46
|
+
"Hyperstack::Session-#{session.id}"
|
47
47
|
end
|
48
48
|
|
49
49
|
def regulate(channel)
|
50
|
-
unless channel == session_channel # "
|
51
|
-
|
50
|
+
unless channel == session_channel # "Hyperstack::Session-#{client_id.split('-').last}"
|
51
|
+
Hyperstack::InternalPolicy.regulate_connection(try(:acting_user), channel)
|
52
52
|
end
|
53
53
|
channel
|
54
54
|
end
|
55
55
|
|
56
56
|
def channels(user = acting_user, session_id = session.id)
|
57
|
-
|
57
|
+
Hyperstack::AutoConnect.channels(session_id, user)
|
58
58
|
end
|
59
59
|
|
60
60
|
def can_connect?(channel, user = acting_user)
|
61
|
-
|
61
|
+
Hyperstack::InternalPolicy.regulate_connection(
|
62
62
|
user,
|
63
|
-
|
63
|
+
Hyperstack::InternalPolicy.channel_to_string(channel)
|
64
64
|
)
|
65
65
|
true
|
66
66
|
rescue
|
@@ -101,41 +101,41 @@ module Hyperloop
|
|
101
101
|
|
102
102
|
def subscribe
|
103
103
|
channel = regulate params[:channel].gsub('==', '::')
|
104
|
-
root_path = request.original_url.gsub(/
|
105
|
-
|
104
|
+
root_path = request.original_url.gsub(/hyperstack-subscribe.*$/, '')
|
105
|
+
Hyperstack::Connection.open(channel, client_id, root_path)
|
106
106
|
head :ok
|
107
107
|
rescue Exception
|
108
108
|
head :unauthorized
|
109
109
|
end
|
110
110
|
|
111
111
|
def read
|
112
|
-
root_path = request.original_url.gsub(/
|
113
|
-
data =
|
112
|
+
root_path = request.original_url.gsub(/hyperstack-read.*$/, '')
|
113
|
+
data = Hyperstack::Connection.read(client_id, root_path)
|
114
114
|
render json: data
|
115
115
|
end
|
116
116
|
|
117
117
|
def pusher_auth
|
118
|
-
raise unless
|
119
|
-
channel = regulate params[:channel_name].gsub(/^#{Regexp.quote(
|
120
|
-
response =
|
118
|
+
raise unless Hyperstack.transport == :pusher
|
119
|
+
channel = regulate params[:channel_name].gsub(/^#{Regexp.quote(Hyperstack.channel)}\-/,'').gsub('==', '::')
|
120
|
+
response = Hyperstack.pusher.authenticate(params[:channel_name], params[:socket_id])
|
121
121
|
render json: response
|
122
122
|
rescue Exception => e
|
123
123
|
head :unauthorized
|
124
124
|
end
|
125
125
|
|
126
126
|
def action_cable_auth
|
127
|
-
raise unless
|
128
|
-
channel = regulate params[:channel_name].gsub(/^#{Regexp.quote(
|
127
|
+
raise unless Hyperstack.transport == :action_cable
|
128
|
+
channel = regulate params[:channel_name].gsub(/^#{Regexp.quote(Hyperstack.channel)}\-/,'')
|
129
129
|
salt = SecureRandom.hex
|
130
|
-
authorization =
|
130
|
+
authorization = Hyperstack.authorization(salt, channel, client_id)
|
131
131
|
render json: {authorization: authorization, salt: salt}
|
132
132
|
rescue Exception
|
133
133
|
head :unauthorized
|
134
134
|
end
|
135
135
|
|
136
136
|
def connect_to_transport
|
137
|
-
root_path = request.original_url.gsub(/
|
138
|
-
render json:
|
137
|
+
root_path = request.original_url.gsub(/hyperstack-connect-to-transport.*$/, '')
|
138
|
+
render json: Hyperstack::Connection.connect_to_transport(params[:channel], client_id, root_path)
|
139
139
|
rescue Exception => e
|
140
140
|
render status: :service_unavailable, json: {error: e}
|
141
141
|
end
|
@@ -159,9 +159,9 @@ module Hyperloop
|
|
159
159
|
|
160
160
|
def console_update # TODO this should just become an execute-remote-api call
|
161
161
|
raise unless Rails.env.development?
|
162
|
-
authorization =
|
162
|
+
authorization = Hyperstack.authorization(params[:salt], params[:channel], params[:data][1][:broadcast_id]) #params[:data].to_json)
|
163
163
|
return head :unauthorized if authorization != params[:authorization]
|
164
|
-
|
164
|
+
Hyperstack::Connection.send_to_channel(params[:channel], params[:data])
|
165
165
|
head :no_content
|
166
166
|
rescue
|
167
167
|
head :unauthorized
|
@@ -171,32 +171,32 @@ module Hyperloop
|
|
171
171
|
head :no_content
|
172
172
|
end
|
173
173
|
|
174
|
-
end unless defined?
|
174
|
+
end unless defined? Hyperstack::HyperstackController
|
175
175
|
|
176
176
|
match 'execute_remote',
|
177
|
-
to: '
|
177
|
+
to: 'hyperstack#execute_remote', via: :post
|
178
178
|
match 'execute_remote_api',
|
179
|
-
to: '
|
180
|
-
|
181
|
-
# match '
|
182
|
-
# to: '
|
183
|
-
# match '
|
184
|
-
# to: '
|
185
|
-
match '
|
186
|
-
to: '
|
187
|
-
match '
|
188
|
-
to: '
|
189
|
-
match '
|
190
|
-
to: '
|
191
|
-
match '
|
192
|
-
to: '
|
193
|
-
match '
|
194
|
-
to: '
|
179
|
+
to: 'hyperstack#execute_remote_api', via: :post
|
180
|
+
|
181
|
+
# match 'hyperstack-subscribe',
|
182
|
+
# to: 'hyperstack#subscribe', via: :get
|
183
|
+
# match 'hyperstack-read/:subscriber',
|
184
|
+
# to: 'hyperstack#read', via: :get
|
185
|
+
match 'hyperstack-subscribe/:client_id/:channel',
|
186
|
+
to: 'hyperstack#subscribe', via: :get
|
187
|
+
match 'hyperstack-read/:client_id',
|
188
|
+
to: 'hyperstack#read', via: :get
|
189
|
+
match 'hyperstack-pusher-auth',
|
190
|
+
to: 'hyperstack#pusher_auth', via: :post
|
191
|
+
match 'hyperstack-action-cable-auth/:client_id/:channel_name',
|
192
|
+
to: 'hyperstack#action_cable_auth', via: :post
|
193
|
+
match 'hyperstack-connect-to-transport/:client_id/:channel',
|
194
|
+
to: 'hyperstack#connect_to_transport', via: :get
|
195
195
|
match 'console',
|
196
|
-
to: '
|
196
|
+
to: 'hyperstack#debug_console', via: :get
|
197
197
|
match 'console_update',
|
198
|
-
to: '
|
198
|
+
to: 'hyperstack#console_update', via: :post
|
199
199
|
match 'server_up',
|
200
|
-
to: '
|
200
|
+
to: 'hyperstack#server_up', via: :get
|
201
201
|
end
|
202
202
|
end
|