Require only email and openid prefix in the setup popup. The other fields are optional.
[arvados.git] / services / api / app / models / keep_disk.rb
1 class KeepDisk < ArvadosModel
2   include AssignUuid
3   include KindAndEtag
4   include CommonApiTemplate
5   before_validation :ensure_ping_secret
6
7   api_accessible :user, extend: :common do |t|
8     t.add :node_uuid
9     t.add :filesystem_uuid
10     t.add :bytes_total
11     t.add :bytes_free
12     t.add :is_readable
13     t.add :is_writable
14     t.add :last_read_at
15     t.add :last_write_at
16     t.add :last_ping_at
17     t.add :service_host
18     t.add :service_port
19     t.add :service_ssl_flag
20   end
21   api_accessible :superuser, :extend => :user do |t|
22     t.add :ping_secret
23   end
24
25   def ping(o)
26     raise "must have :service_host and :ping_secret" unless o[:service_host] and o[:ping_secret]
27
28     if o[:ping_secret] != self.ping_secret
29       logger.info "Ping: secret mismatch: received \"#{o[:ping_secret]}\" != \"#{self.ping_secret}\""
30       return nil
31     end
32
33     @bypass_arvados_authorization = true
34     self.update_attributes(o.select { |k,v|
35                              [:service_host,
36                               :service_port,
37                               :service_ssl_flag,
38                               :bytes_total,
39                               :bytes_free,
40                               :is_readable,
41                               :is_writable,
42                               :last_read_at,
43                               :last_write_at
44                              ].collect(&:to_s).index k
45                            }.merge(last_ping_at: Time.now))
46   end
47
48   protected
49
50   def ensure_ping_secret
51     self.ping_secret ||= rand(2**256).to_s(36)
52   end
53
54   def permission_to_update
55     @bypass_arvados_authorization or super
56   end
57
58   def permission_to_create
59     current_user and current_user.is_admin
60   end
61 end