[ARVADOS] updated: fa257c28461627fe6700dd8fd2152e380f8725d4

git at public.curoverse.com git at public.curoverse.com
Tue Apr 22 15:49:54 EDT 2014


Summary of changes:
 apps/workbench/app/views/websocket/index.html.erb  |    2 +-
 .../controllers/arvados/v1/schema_controller.rb    |    5 +++--
 services/api/app/middlewares/rack_socket.rb        |    5 ++++-
 services/api/config/application.default.yml        |    3 +++
 services/api/config/initializers/eventbus.rb       |    4 +++-
 5 files changed, 14 insertions(+), 5 deletions(-)

       via  fa257c28461627fe6700dd8fd2152e380f8725d4 (commit)
      from  cb52a672642bdec7c6a97868a68bbb9b8daa0efb (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit fa257c28461627fe6700dd8fd2152e380f8725d4
Author: Peter Amstutz <peter.amstutz at curoverse.com>
Date:   Tue Apr 22 15:49:51 2014 -0400

    Added websocketUrl to discovery document.  Workbench websockets testing page
    now uses endpoint from discovery discovery document.  Also added
    ARVADOS_WEBSOCKETS environment variable.  If set, server will accept websocket
    connections only and do not pass on any other type of requests.

diff --git a/apps/workbench/app/views/websocket/index.html.erb b/apps/workbench/app/views/websocket/index.html.erb
index 425ddd4..85202b8 100644
--- a/apps/workbench/app/views/websocket/index.html.erb
+++ b/apps/workbench/app/views/websocket/index.html.erb
@@ -18,7 +18,7 @@ putStuffThere = function (content) {
   $("#PutStuffHere").append(content + "<br>");
 };
 
-var dispatcher = new WebSocket('ws://localhost:3001/websocket?api_token=<%= Thread.current[:arvados_api_token] %>');
+var dispatcher = new WebSocket('<%= $arvados_api_client.discovery[:websocketUrl] %>?api_token=<%= Thread.current[:arvados_api_token] %>');
 dispatcher.onmessage = function(event) {
   //putStuffThere(JSON.parse(event.data));
   putStuffThere(event.data);
diff --git a/services/api/app/controllers/arvados/v1/schema_controller.rb b/services/api/app/controllers/arvados/v1/schema_controller.rb
index 1cc8496..b8f0594 100644
--- a/services/api/app/controllers/arvados/v1/schema_controller.rb
+++ b/services/api/app/controllers/arvados/v1/schema_controller.rb
@@ -21,6 +21,7 @@ class Arvados::V1::SchemaController < ApplicationController
         documentationLink: "http://doc.arvados.org/api/index.html",
         protocol: "rest",
         baseUrl: root_url + "/arvados/v1/",
+        websocketUrl: Rails.application.config.websocket_address,
         basePath: "/arvados/v1/",
         rootUrl: root_url,
         servicePath: "arvados/v1/",
@@ -69,7 +70,7 @@ class Arvados::V1::SchemaController < ApplicationController
         schemas: {},
         resources: {}
       }
-      
+
       ActiveRecord::Base.descendants.reject(&:abstract_class?).each do |k|
         begin
           ctl_class = "Arvados::V1::#{k.to_s.pluralize}Controller".constantize
@@ -175,7 +176,7 @@ class Arvados::V1::SchemaController < ApplicationController
               description:
                  %|List #{k.to_s.pluralize}.
 
-                   The <code>list</code> method returns a 
+                   The <code>list</code> method returns a
                    <a href="/api/resources.html">resource list</a> of
                    matching #{k.to_s.pluralize}. For example:
 
diff --git a/services/api/app/middlewares/rack_socket.rb b/services/api/app/middlewares/rack_socket.rb
index f13316f..e2ca570 100644
--- a/services/api/app/middlewares/rack_socket.rb
+++ b/services/api/app/middlewares/rack_socket.rb
@@ -15,6 +15,7 @@ class RackSocket
     @app = app if app.respond_to?(:call)
     @options = [app, options].grep(Hash).first || {}
     @endpoint = @options[:mount] || DEFAULT_ENDPOINT
+    @websocket_only = @options[:websocket_only] || false
 
     # from https://gist.github.com/eatenbyagrue/1338545#file-eventmachine-rb
     if defined?(PhusionPassenger)
@@ -49,8 +50,10 @@ class RackSocket
 
       # Return async Rack response
       ws.rack_response
-    else
+    elsif not @websocket_only
       @app.call env
+    else
+      [406, {"Content-Type" => "text/plain"}, ["Only websocket connections are permitted on this port."]]
     end
   end
 
diff --git a/services/api/config/application.default.yml b/services/api/config/application.default.yml
index 37bb1c3..c05b4af 100644
--- a/services/api/config/application.default.yml
+++ b/services/api/config/application.default.yml
@@ -90,6 +90,9 @@ common:
   # Visitors to the API server will be redirected to the workbench
   workbench_address: https://workbench.local:3001/
 
+  # Websocket endpoint
+  websocket_address: wss://localhost:3002/websocket
+
   # The e-mail address of the user you would like to become marked as an admin
   # user on their first login.
   # In the default configuration, authentication happens through the Arvados SSO
diff --git a/services/api/config/initializers/eventbus.rb b/services/api/config/initializers/eventbus.rb
index 31d8fac..2d2b7bc 100644
--- a/services/api/config/initializers/eventbus.rb
+++ b/services/api/config/initializers/eventbus.rb
@@ -1,5 +1,7 @@
 require 'eventbus'
 
 Server::Application.configure do
-  config.middleware.insert_after ArvadosApiToken, RackSocket, {:handler => EventBus}
+  if ENV['ARVADOS_WEBSOCKETS']
+    config.middleware.insert_after ArvadosApiToken, RackSocket, {:handler => EventBus, :websocket_only => true }
+  end
 end

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list