Class: Gitlab::Pages::RandomDomain

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/pages/random_domain.rb

Constant Summary collapse

PROJECT_PATH_LIMIT =
56

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_path:) ⇒ RandomDomain

Returns a new instance of RandomDomain.



12
13
14
# File 'lib/gitlab/pages/random_domain.rb', line 12

def initialize(project_path:)
  @project_path = project_path
end

Class Method Details

.generate(project_path:) ⇒ Object



8
9
10
# File 'lib/gitlab/pages/random_domain.rb', line 8

def self.generate(project_path:)
  new(project_path: project_path).generate
end

Instance Method Details

#generateObject

Subdomains have a limit of 63 bytes (www.freesoft.org/CIE/RFC/1035/9.htm) For this reason we’re limiting each part of the unique subdomain

The domain is made up of 2 parts, like: projectpath-randomstring

  • project path: between 1 and 56 chars

  • random hexadecimal: to ensure a random value of length 6



22
23
24
25
26
27
28
29
30
# File 'lib/gitlab/pages/random_domain.rb', line 22

def generate
  domain = project_path.byteslice(0, PROJECT_PATH_LIMIT)

  # PS.: SecureRandom.hex return an string twice the size passed as argument.
  domain.concat('-', SecureRandom.hex(3))

  # Slugify ensures the format and size (63 chars) of the given string
  Gitlab::Utils.slugify(domain)
end