X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/49a6ced3c7a540a7da7155ab1c3120a5227c620c..fb329a132418fd54a027d30277f31c73443840ab:/services/api/app/models/api_client.rb diff --git a/services/api/app/models/api_client.rb b/services/api/app/models/api_client.rb index 75a800ba45..015b61dc49 100644 --- a/services/api/app/models/api_client.rb +++ b/services/api/app/models/api_client.rb @@ -1,3 +1,7 @@ +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: AGPL-3.0 + class ApiClient < ArvadosModel include HasUuid include KindAndEtag @@ -9,4 +13,43 @@ class ApiClient < ArvadosModel t.add :url_prefix t.add :is_trusted end + + def is_trusted + (from_trusted_url && Rails.configuration.Login.TokenLifetime == 0) || super + end + + protected + + def from_trusted_url + norm_url_prefix = norm(self.url_prefix) + + [Rails.configuration.Services.Workbench1.ExternalURL, + Rails.configuration.Services.Workbench2.ExternalURL, + "https://controller.api.client.invalid"].each do |url| + if norm_url_prefix == norm(url) + return true + end + end + + Rails.configuration.Login.TrustedClients.keys.each do |url| + if norm_url_prefix == norm(url) + return true + end + end + + false + end + + def norm url + # normalize URL for comparison + url = URI(url.to_s) + if url.scheme == "https" + url.port == "443" + end + if url.scheme == "http" + url.port == "80" + end + url.path = "/" + url + end end