Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-02-11 21:08:58 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-11 21:08:58 +0300
commit1ca9950d5f890cd8f185e1eda158b969a7244fe2 (patch)
tree6f62715938a4b2b001705c51c697609a8e0850ae /lib/gitlab/serverless
parentbcc77054ee9aefd1e332e04a4189390fd5a3112e (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/serverless')
-rw-r--r--lib/gitlab/serverless/service.rb98
1 files changed, 98 insertions, 0 deletions
diff --git a/lib/gitlab/serverless/service.rb b/lib/gitlab/serverless/service.rb
new file mode 100644
index 00000000000..643e076c587
--- /dev/null
+++ b/lib/gitlab/serverless/service.rb
@@ -0,0 +1,98 @@
+# frozen_string_literal: true
+
+class Gitlab::Serverless::Service
+ include Gitlab::Utils::StrongMemoize
+
+ def initialize(attributes)
+ @attributes = attributes
+ end
+
+ def name
+ @attributes.dig('metadata', 'name')
+ end
+
+ def namespace
+ @attributes.dig('metadata', 'namespace')
+ end
+
+ def environment_scope
+ @attributes.dig('environment_scope')
+ end
+
+ def environment
+ @attributes.dig('environment')
+ end
+
+ def podcount
+ @attributes.dig('podcount')
+ end
+
+ def created_at
+ strong_memoize(:created_at) do
+ timestamp = @attributes.dig('metadata', 'creationTimestamp')
+ DateTime.parse(timestamp) if timestamp
+ end
+ end
+
+ def image
+ @attributes.dig(
+ 'spec',
+ 'runLatest',
+ 'configuration',
+ 'build',
+ 'template',
+ 'name')
+ end
+
+ def description
+ knative_07_description || knative_05_06_description
+ end
+
+ def cluster
+ @attributes.dig('cluster')
+ end
+
+ def url
+ proxy_url || knative_06_07_url || knative_05_url
+ end
+
+ private
+
+ def proxy_url
+ if cluster&.serverless_domain
+ Gitlab::Serverless::FunctionURI.new(function: name, cluster: cluster.serverless_domain, environment: environment)
+ end
+ end
+
+ def knative_07_description
+ @attributes.dig(
+ 'spec',
+ 'template',
+ 'metadata',
+ 'annotations',
+ 'Description'
+ )
+ end
+
+ def knative_05_06_description
+ @attributes.dig(
+ 'spec',
+ 'runLatest',
+ 'configuration',
+ 'revisionTemplate',
+ 'metadata',
+ 'annotations',
+ 'Description')
+ end
+
+ def knative_05_url
+ domain = @attributes.dig('status', 'domain')
+ return unless domain
+
+ "http://#{domain}"
+ end
+
+ def knative_06_07_url
+ @attributes.dig('status', 'url')
+ end
+end