[ARVADOS] created: 24742cd39eff59df5d4ac17d7d39c437c79a456b

git at public.curoverse.com git at public.curoverse.com
Fri Mar 21 13:53:34 EDT 2014


        at  24742cd39eff59df5d4ac17d7d39c437c79a456b (commit)


commit 24742cd39eff59df5d4ac17d7d39c437c79a456b
Author: Peter Amstutz <peter.amstutz at curoverse.com>
Date:   Fri Mar 21 13:53:28 2014 -0400

    Working on re-using token per pipeline and expiring token when the pipeline is done.

diff --git a/services/api/script/crunch-dispatch.rb b/services/api/script/crunch-dispatch.rb
index 9eb1c28..0835e1f 100755
--- a/services/api/script/crunch-dispatch.rb
+++ b/services/api/script/crunch-dispatch.rb
@@ -310,7 +310,7 @@ class Dispatcher
 
     jobrecord = Job.find_by_uuid(job_done.uuid)
     jobrecord.running = false
-    jobrecord.finished_at ||= Time.now,
+    jobrecord.finished_at ||= Time.now
     # Don't set 'jobrecord.success = false' because if the job failed to run due to an
     # issue with crunch-job or slurm, we want the job to stay in the queue.
     jobrecord.save!
@@ -324,13 +324,28 @@ class Dispatcher
   end
 
   def update_pipelines
+    @pipe_auth_tokens ||= { }
+    expire_tokens = @pipe_auth_tokens.dup
+    puts "1 @pipe_auth_tokens #{@pipe_auth_tokens}"
+    puts "1 expire_tokens #{expire_tokens}"
     @todo_pipelines.each do |p|
-      pipe_auth = ApiClientAuthorization.
-        new(user: User.where('uuid=?', p.modified_by_user_uuid).first,
-            api_client_id: 0)
-      pipe_auth.save
-
+      if @pipe_auth_tokens[p.uuid].nil?
+        pipe_auth = ApiClientAuthorization.
+          new(user: User.where('uuid=?', p.modified_by_user_uuid).first,
+              api_client_id: 0)
+        pipe_auth.save
+        @pipe_auth_tokens[p.uuid] = pipe_auth
+      end
+      pipe_auth = @pipe_auth_tokens[p.uuid]
       puts `export ARVADOS_API_TOKEN=#{pipe_auth.api_token} && arv-run-pipeline-instance --run-here --no-wait --instance #{p.uuid}`
+      expire_tokens.delete p.uuid
+    end
+
+    puts "2 @pipe_auth_tokens #{@pipe_auth_tokens}"
+    puts "2 expire_tokens #{expire_tokens}"
+    expire_tokens.each do |k, v|
+      v.update_attributes expires_at: Time.now
+      @pipe_auth_tokens.delete k
     end
   end
 

commit 8fa6952e7aaf9afc6d72699b165a693962151a21
Merge: 0279533 f14fb30
Author: Peter Amstutz <peter.amstutz at curoverse.com>
Date:   Fri Mar 21 13:02:28 2014 -0400

    Merge branch 'master' of git.clinicalfuture.com:arvados
    
    # Please enter a commit message to explain why this merge is necessary,
    # especially if it merges an updated upstream into a topic branch.
    #
    # Lines starting with '#' will be ignored, and an empty message aborts
    # the commit.


commit 027953372c41b16b191d9a1124b82f1c21a759f9
Merge: 46e1645 354367a
Author: Peter Amstutz <peter.amstutz at curoverse.com>
Date:   Fri Mar 21 12:57:04 2014 -0400

    Merge branch 'master' of git.clinicalfuture.com:arvados
    
    # Please enter a commit message to explain why this merge is necessary,
    # especially if it merges an updated upstream into a topic branch.
    #
    # Lines starting with '#' will be ignored, and an empty message aborts
    # the commit.


commit 46e1645bb91debb3e4ad98b82895ada5329e9351
Author: Peter Amstutz <peter.amstutz at curoverse.com>
Date:   Fri Mar 21 10:25:19 2014 -0400

    Fixes bug loading API tokens page.
    Added test using our new workbench testing framework to make sure it doesn't happen again.

diff --git a/apps/workbench/app/controllers/api_client_authorizations_controller.rb b/apps/workbench/app/controllers/api_client_authorizations_controller.rb
index 81e324a..4a1256d 100644
--- a/apps/workbench/app/controllers/api_client_authorizations_controller.rb
+++ b/apps/workbench/app/controllers/api_client_authorizations_controller.rb
@@ -1,8 +1,15 @@
 class ApiClientAuthorizationsController < ApplicationController
   def index
-    @objects = model_class.all.to_ary.reject do |x|
+    m = model_class.all
+    items_available = m.items_available
+    offset = m.result_offset
+    limit = m.result_limit
+    filtered = m.to_ary.reject do |x|
       x.api_client_id == 0 or (x.expires_at and x.expires_at < Time.now) rescue false
     end
+    ArvadosApiClient.patch_paging_vars(filtered, items_available, offset, limit)
+    @objects = ArvadosResourceList.new(ApiClientAuthorization)
+    @objects.results= filtered
     super
   end
 
diff --git a/apps/workbench/app/models/arvados_api_client.rb b/apps/workbench/app/models/arvados_api_client.rb
index 6d9269e..093dd45 100644
--- a/apps/workbench/app/models/arvados_api_client.rb
+++ b/apps/workbench/app/models/arvados_api_client.rb
@@ -90,22 +90,26 @@ class ArvadosApiClient
     resp
   end
 
+  def self.patch_paging_vars(ary, items_available, offset, limit)
+    if items_available
+      (class << ary; self; end).class_eval { attr_accessor :items_available }
+      ary.items_available = items_available
+    end
+    if offset
+      (class << ary; self; end).class_eval { attr_accessor :offset }
+      ary.offset = offset
+    end
+    if limit
+      (class << ary; self; end).class_eval { attr_accessor :limit }
+      ary.limit = limit
+    end    
+    ary
+  end
+
   def unpack_api_response(j, kind=nil)
     if j.is_a? Hash and j[:items].is_a? Array and j[:kind].match(/(_list|List)$/)
       ary = j[:items].collect { |x| unpack_api_response x, j[:kind] }
-      if j[:items_available]
-        (class << ary; self; end).class_eval { attr_accessor :items_available }
-        ary.items_available = j[:items_available]
-      end
-      if j[:offset]
-        (class << ary; self; end).class_eval { attr_accessor :offset }
-        ary.offset = j[:offset]
-      end
-      if j[:limit]
-        (class << ary; self; end).class_eval { attr_accessor :limit }
-        ary.limit = j[:limit]
-      end
-      ary
+      ArvadosApiClient.patch_paging_vars(ary, j[:items_available], j[:offset], j[:limit])
     elsif j.is_a? Hash and (kind || j[:kind])
       oclass = self.kind_class(kind || j[:kind])
       if oclass
diff --git a/apps/workbench/app/models/arvados_resource_list.rb b/apps/workbench/app/models/arvados_resource_list.rb
index 3842c97..6b17ece 100644
--- a/apps/workbench/app/models/arvados_resource_list.rb
+++ b/apps/workbench/app/models/arvados_resource_list.rb
@@ -68,6 +68,10 @@ class ArvadosResourceList
     @results
   end
 
+  def results=(r)
+    @results = r
+  end
+
   def all
     where({})
   end
diff --git a/apps/workbench/app/views/layouts/application.html.erb b/apps/workbench/app/views/layouts/application.html.erb
index abef471..b5c75fc 100644
--- a/apps/workbench/app/views/layouts/application.html.erb
+++ b/apps/workbench/app/views/layouts/application.html.erb
@@ -149,7 +149,7 @@
         <% end %>
 
         <li class="dropdown">
-          <a href="#" class="dropdown-toggle" data-toggle="dropdown">
+          <a href="#" class="dropdown-toggle" data-toggle="dropdown" id="user-menu">
             <span class="glyphicon glyphicon-user"></span><span class="caret"></span>
           </a>
           <ul class="dropdown-menu" role="menu">
diff --git a/apps/workbench/test/integration/api_client_authorizations_test.rb b/apps/workbench/test/integration/api_client_authorizations_test.rb
new file mode 100644
index 0000000..6312034
--- /dev/null
+++ b/apps/workbench/test/integration/api_client_authorizations_test.rb
@@ -0,0 +1,11 @@
+require 'integration_helper'
+
+class ApiClientAuthorizationsTest < ActionDispatch::IntegrationTest
+  test "try loading Manage API tokens page" do
+    Capybara.current_driver = Capybara.javascript_driver
+    visit page_with_token('admin_trustedclient')
+    click_link 'user-menu'
+    click_link 'Manage API tokens'
+    assert_equal 200, status_code
+  end
+end

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list