BigW Consortium Gitlab

regex.rb 1.81 KB
Newer Older
1 2 3 4
module Gitlab
  module Regex
    extend self

5
    def namespace_name_regex
6
      @namespace_name_regex ||= /\A[\p{Alnum}\p{Pd}_\. ]*\z/.freeze
7 8
    end

9
    def namespace_name_regex_message
10
      "can contain only letters, digits, '_', '.', dash and space."
11 12
    end

13
    def project_name_regex
14
      @project_name_regex ||= /\A[\p{Alnum}\u{00A9}-\u{1f9c0}_][\p{Alnum}\p{Pd}\u{00A9}-\u{1f9c0}_\. ]*\z/.freeze
15 16
    end

17
    def project_name_regex_message
18 19
      "can contain only letters, digits, emojis, '_', '.', dash, space. " \
      "It must start with letter, digit, emoji or '_'."
20 21
    end

22
    def file_name_regex
23
      @file_name_regex ||= /\A[[[:alnum:]]_\-\.\@\+]*\z/.freeze
24
    end
25

26
    def file_name_regex_message
27
      "can contain only letters, digits, '_', '-', '@', '+' and '.'."
28 29
    end

Kamil Trzcinski committed
30
    def container_registry_reference_regex
31
      Gitlab::PathRegex.git_reference_regex
32
    end
33

34 35 36 37 38 39 40
    ##
    # Docker Distribution Registry 2.4.1 repository name rules
    #
    def container_repository_name_regex
      @container_repository_regex ||= %r{\A[a-z0-9]+(?:[-._/][a-z0-9]+)*\Z}
    end

41
    def environment_name_regex
42
      @environment_name_regex ||= /\A[a-zA-Z0-9_\\\/\${}. -]+\z/.freeze
43 44 45
    end

    def environment_name_regex_message
46
      "can contain only letters, digits, '-', '_', '/', '$', '{', '}', '.' and spaces"
47
    end
48 49 50 51 52 53 54 55

    def kubernetes_namespace_regex
      /\A[a-z0-9]([-a-z0-9]*[a-z0-9])?\z/
    end

    def kubernetes_namespace_regex_message
      "can contain only letters, digits or '-', and cannot start or end with '-'"
    end
Nick Thomas committed
56 57 58 59 60 61 62 63 64

    def environment_slug_regex
      @environment_slug_regex ||= /\A[a-z]([a-z0-9-]*[a-z0-9])?\z/.freeze
    end

    def environment_slug_regex_message
      "can contain only lowercase letters, digits, and '-'. " \
      "Must start with a letter, and cannot end with '-'"
    end
65 66
  end
end