def show
if @object
- render json: @object.as_api_response(:superuser)
+ render json: @object.as_api_response
else
render_not_found("object not found")
end
:self_link => "",
:next_page_token => "",
:next_link => "",
- :items => @objects.as_api_response(:superuser)
+ :items => @objects.as_api_response(nil)
}
render json: @object_list
end
ec2_instance_id: params[:instance_id] })
show
end
+
+ def index
+ if current_user.andand.is_admin
+ super
+ else
+ @objects = model_class.where('last_ping_at >= ?', Time.now - 1.hours)
+ render_list
+ end
+ end
end
include CommonApiTemplate
has_many :api_client_authorizations
- api_accessible :superuser, :extend => :common do |t|
+ api_accessible :user, extend: :common do |t|
t.add :name
t.add :url_prefix
t.add :is_trusted
after_initialize :assign_random_api_token
serialize :scopes, Array
- api_accessible :superuser, :extend => :common do |t|
+ api_accessible :user, extend: :common do |t|
t.add :owner_uuid
t.add :user_id
t.add :api_client_id
belongs_to :authorized_user, :foreign_key => :authorized_user_uuid, :class_name => 'User', :primary_key => :uuid
- api_accessible :superuser, :extend => :common do |t|
+ api_accessible :user, extend: :common do |t|
t.add :name
t.add :key_type
t.add :authorized_user_uuid
include KindAndEtag
include CommonApiTemplate
- api_accessible :superuser, :extend => :common do |t|
+ api_accessible :user, extend: :common do |t|
t.add :data_size
t.add :files
end
include KindAndEtag
include CommonApiTemplate
- api_accessible :superuser, :extend => :common do |t|
+ api_accessible :user, extend: :common do |t|
t.add :name
t.add :description
end
include CommonApiTemplate
serialize :properties, Hash
- api_accessible :superuser, :extend => :common do |t|
+ api_accessible :user, extend: :common do |t|
t.add :properties
end
end
class SubmitIdReused < StandardError
end
- api_accessible :superuser, :extend => :common do |t|
+ api_accessible :user, extend: :common do |t|
t.add :submit_id
t.add :priority
t.add :script
after_update :delete_created_job_tasks_if_failed
after_update :assign_created_job_tasks_qsequence_if_succeeded
- api_accessible :superuser, :extend => :common do |t|
+ api_accessible :user, extend: :common do |t|
t.add :job_uuid
t.add :created_by_job_task_uuid
t.add :sequence
include CommonApiTemplate
before_validation :ensure_ping_secret
- api_accessible :superuser, :extend => :common do |t|
+ api_accessible :user, extend: :common do |t|
t.add :node_uuid
t.add :filesystem_uuid
t.add :ping_secret
attr_accessor :head
attr_accessor :tail
- api_accessible :superuser, :extend => :common do |t|
+ api_accessible :user, extend: :common do |t|
t.add :tail_kind
t.add :tail_uuid
t.add :link_class
before_validation :set_default_event_at
attr_accessor :object
- api_accessible :superuser, :extend => :common do |t|
+ api_accessible :user, extend: :common do |t|
t.add :object_kind
t.add :object_uuid
t.add :object, :if => :object
@@domain = Rails.configuration.compute_node_domain rescue `hostname --domain`.strip
@@nameservers = Rails.configuration.compute_node_nameservers
- api_accessible :superuser, :extend => :common do |t|
+ api_accessible :user, :extend => :common do |t|
t.add :hostname
t.add :domain
t.add :ip_address
- t.add :first_ping_at
t.add :last_ping_at
- t.add :info
t.add :slot_number
t.add :status
+ end
+ api_accessible :superuser, :extend => :user do |t|
+ t.add :first_ping_at
+ t.add :info
t.add lambda { |x| @@nameservers }, :as => :nameservers
end
before_validation :bootstrap_components
before_validation :update_success
- api_accessible :superuser, :extend => :common do |t|
+ api_accessible :user, extend: :common do |t|
t.add :pipeline_template_uuid
t.add :pipeline_template, :if => :pipeline_template
t.add :name
include CommonApiTemplate
serialize :components, Hash
- api_accessible :superuser, :extend => :common do |t|
+ api_accessible :user, extend: :common do |t|
t.add :name
t.add :components
end
include KindAndEtag
include CommonApiTemplate
- api_accessible :superuser, :extend => :common do |t|
+ api_accessible :user, extend: :common do |t|
t.add :name
t.add :fetch_url
t.add :push_url
include CommonApiTemplate
serialize :properties, Hash
- api_accessible :superuser, :extend => :common do |t|
+ api_accessible :user, extend: :common do |t|
t.add :material
t.add :properties
end
include CommonApiTemplate
serialize :properties, Hash
- api_accessible :superuser, :extend => :common do |t|
+ api_accessible :user, extend: :common do |t|
t.add :name
t.add :properties
end
has_many :authorized_keys, :foreign_key => :authorized_user_uuid, :primary_key => :uuid
- api_accessible :superuser, :extend => :common do |t|
+ api_accessible :user, extend: :common do |t|
t.add :email
t.add :full_name
t.add :first_name
has_many :login_permissions, :foreign_key => :head_uuid, :class_name => 'Link', :primary_key => :uuid, :conditions => "link_class = 'permission' and name = 'can_login'"
- api_accessible :superuser, :extend => :common do |t|
+ api_accessible :user, extend: :common do |t|
t.add :hostname
end
module CommonApiTemplate
def self.included(base)
- base.extend(ClassMethods)
base.acts_as_api
+ base.class_eval do
+ alias_method :as_api_response_orig, :as_api_response
+ include InstanceMethods
+ end
+ base.extend(ClassMethods)
base.api_accessible :common do |t|
t.add :href
t.add :kind
end
end
+ module InstanceMethods
+ # choose template based on opts[:for_user]
+ def as_api_response(template=nil, opts={})
+ if template.nil?
+ user = opts[:for_user] || current_user
+ if user.is_admin and self.respond_to? :api_accessible_superuser
+ template = :superuser
+ else
+ template = :user
+ end
+ end
+ self.as_api_response_orig(template, opts)
+ end
+ end
+
module ClassMethods
end
end
--- /dev/null
+running:
+ uuid: zzzzz-7ekkf-53y36l1lu5ijveb
+ owner_uuid: zzzzz-tpzed-d9tiejq69daie8f
+ hostname: compute0
+ domain: ""
+ ip_address: 172.17.2.172
+ last_ping_at: <%= 1.minute.ago.to_s(:db) %>
+ first_ping_at: <%= 23.hour.ago.to_s(:db) %>
+ info: {ping_secret: "48dpm3b8ijyj3jkr2yczxw0844dqd2752bhll7klodvgz9bg80"}
+
+down:
+ uuid: zzzzz-7ekkf-2vbompg3ecc6e2s
+ owner_uuid: zzzzz-tpzed-d9tiejq69daie8f
+ hostname: compute1
+ domain: ""
+ ip_address: 172.17.2.173
+ last_ping_at: <%= 1.hour.ago.to_s(:db) %>
+ first_ping_at: <%= 23.hour.ago.to_s(:db) %>
+ info: {ping_secret: "2k3i71depad36ugwmlgzilbi4e8n0illb2r8l4efg9mzkb3a1k"}
class Arvados::V1::NodesControllerTest < ActionController::TestCase
- test "should get index" do
+ test "should get index with ping_secret" do
authorize_with :admin
get :index
assert_response :success
assert_not_nil assigns(:objects)
+ node_items = JSON.parse(@response.body)['items']
+ assert_not_equal 0, node_items.size
+ assert_not_nil node_items[0]['info'].andand['ping_secret']
end
# inactive user should not see any nodes
- test "should get empty index" do
+ test "should get index without ping_secret" do
authorize_with :inactive
get :index
assert_response :success
- assert_equal 0, JSON.parse(@response.body)['items'].size
+ node_items = JSON.parse(@response.body)['items']
+ assert_not_equal 0, node_items.size
+ assert_nil node_items[0]['info'].andand['ping_secret']
end
end