Merge branch '15828-trust-wb' refs #15828
[arvados.git] / services / api / app / models / api_client.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 class ApiClient < ArvadosModel
6   include HasUuid
7   include KindAndEtag
8   include CommonApiTemplate
9   has_many :api_client_authorizations
10
11   api_accessible :user, extend: :common do |t|
12     t.add :name
13     t.add :url_prefix
14     t.add :is_trusted
15   end
16
17   def is_trusted
18     norm(self.url_prefix) == norm(Rails.configuration.Services.Workbench1.ExternalURL) ||
19       norm(self.url_prefix) == norm(Rails.configuration.Services.Workbench2.ExternalURL) ||
20       super
21   end
22
23   protected
24
25   def norm url
26     # normalize URL for comparison
27     url = URI(url)
28     if url.scheme == "https"
29       url.port == "443"
30     end
31     if url.scheme == "http"
32       url.port == "80"
33     end
34     url.path = "/"
35     url
36   end
37 end