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

serverless_domain_finder.rb « finders « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 661cd0ca363f1627eaa6afa93a58e080ffb468a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# frozen_string_literal: true

class ServerlessDomainFinder
  attr_reader :match, :serverless_domain_cluster, :environment

  def initialize(uri)
    @match = ::Serverless::Domain::REGEXP.match(uri)
  end

  def execute
    return unless serverless?

    @serverless_domain_cluster = ::Serverless::DomainCluster.for_uuid(serverless_domain_cluster_uuid)
    return unless serverless_domain_cluster&.knative&.external_ip

    @environment = ::Environment.for_id_and_slug(match[:environment_id].to_i(16), match[:environment_slug])
    return unless environment

    ::Serverless::Domain.new(
      function_name: match[:function_name],
      serverless_domain_cluster: serverless_domain_cluster,
      environment: environment
    )
  end

  def serverless_domain_cluster_uuid
    return unless serverless?

    match[:cluster_left] + match[:cluster_middle] + match[:cluster_right]
  end

  def serverless?
    !!match
  end
end