summaryrefslogtreecommitdiff
path: root/qa/qa/runtime/namespace.rb
blob: 6b4cbe6af6e87a148ad067f01bb0fac9b616c3fe (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
# frozen_string_literal: true

module QA
  module Runtime
    module Namespace
      extend self

      def time
        @time ||= Time.now
      end

      def name(reset_cache: !Runtime::Env.cache_namespace_name?)
        # If any changes are made to the name tag, following script has to be considered:
        # https://ops.gitlab.net/gitlab-com/gl-infra/traffic-generator/blob/master/bin/janitor.bash
        reset_name_cache if reset_cache
        @name ||= Runtime::Env.namespace_name || "qa-test-#{time.strftime('%Y-%m-%d-%H-%M-%S')}-#{SecureRandom.hex(8)}" # rubocop:disable Gitlab/ModuleWithInstanceVariables
      end

      def reset_name_cache
        @name = nil # rubocop:disable Gitlab/ModuleWithInstanceVariables
      end

      def path
        "#{sandbox_name}/#{name(reset_cache: false)}"
      end

      def sandbox_name
        Runtime::Env.sandbox_name || 'gitlab-qa-sandbox-group'
      end
    end
  end
end