Module: Kameleoon::Utils::Domain

Defined in:
lib/kameleoon/utils.rb

Constant Summary collapse

HTTP =
'http://'
HTTPS =
'https://'
REGEX_DOMAIN =
/^(\.?(([a-zA-Z\d][a-zA-Z\d-]*[a-zA-Z\d])|[a-zA-Z\d]))
(\.(([a-zA-Z\d][a-zA-Z\d-]*[a-zA-Z\d])|[a-zA-Z\d])){1,126}$/x.freeze
LOCALHOST =
'localhost'

Class Method Summary collapse

Class Method Details

.validate_network_domain(network_domain) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/kameleoon/utils.rb', line 110

def self.validate_network_domain(network_domain)
  return nil if network_domain.nil? || network_domain.empty?

  network_domain = check_and_trim_protocol(network_domain.downcase)

  # remove first and last dot
  network_domain = network_domain.gsub(/^\.+|\.+$/, '')

  if !REGEX_DOMAIN.match?(network_domain) && network_domain != LOCALHOST
    Logging::KameleoonLogger.error(
      "The network domain '%s' is invalid.",
      network_domain
    )
    return nil
  end

  network_domain
end

.validate_top_level_domain(top_level_domain) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/kameleoon/utils.rb', line 93

def self.validate_top_level_domain(top_level_domain)
  return nil if top_level_domain.nil? || top_level_domain.empty?

  top_level_domain = check_and_trim_protocol(top_level_domain.downcase)

  if !REGEX_DOMAIN.match?(top_level_domain) && top_level_domain != LOCALHOST
    Logging::KameleoonLogger.error(
      "The top-level domain '%s' is invalid. The value has been set as provided, but it does not meet " \
        'the required format for proper SDK functionality. Please check the domain for correctness.',
      top_level_domain
    )
    return top_level_domain
  end

  top_level_domain
end