Merge branch '16723-kill-vs-requeue'
[arvados.git] / services / api / app / models / api_client.rb
index 75a800ba4507c45022622b01b9308a5874699df0..c6c48a5b6b13c803d8d54d660a2d8fbd2a265740 100644 (file)
@@ -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,28 @@ 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(self.url_prefix) == norm(Rails.configuration.Services.Workbench1.ExternalURL) ||
+      norm(self.url_prefix) == norm(Rails.configuration.Services.Workbench2.ExternalURL)
+  end
+
+  def norm url
+    # normalize URL for comparison
+    url = URI(url)
+    if url.scheme == "https"
+      url.port == "443"
+    end
+    if url.scheme == "http"
+      url.port == "80"
+    end
+    url.path = "/"
+    url
+  end
 end