debian-mirror-gitlab/lib/gitlab/uuid.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

38 lines
1.1 KiB
Ruby
Raw Normal View History

2021-02-22 17:27:13 +05:30
# frozen_string_literal: true
module Gitlab
class UUID
NAMESPACE_IDS = {
development: "a143e9e2-41b3-47bc-9a19-081d089229f4",
test: "a143e9e2-41b3-47bc-9a19-081d089229f4",
staging: "a6930898-a1b2-4365-ab18-12aa474d9b26",
production: "58dc0f06-936c-43b3-93bb-71693f1b6570"
}.freeze
2021-04-29 21:17:54 +05:30
UUID_V5_PATTERN = /\h{8}-\h{4}-5\h{3}-\h{4}-\h{12}/.freeze
2021-02-22 17:27:13 +05:30
NAMESPACE_REGEX = /(\h{8})-(\h{4})-(\h{4})-(\h{4})-(\h{4})(\h{8})/.freeze
2021-04-29 21:17:54 +05:30
PACK_PATTERN = "NnnnnN"
2021-02-22 17:27:13 +05:30
class << self
def v5(name, namespace_id: default_namespace_id)
Digest::UUID.uuid_v5(namespace_id, name)
end
2021-03-08 18:12:59 +05:30
def v5?(string)
string.match(UUID_V5_PATTERN).present?
end
2021-02-22 17:27:13 +05:30
private
def default_namespace_id
@default_namespace_id ||= begin
namespace_uuid = NAMESPACE_IDS.fetch(Rails.env.to_sym)
# Digest::UUID is broken when using a UUID as a namespace_id
# https://github.com/rails/rails/issues/37681#issue-520718028
namespace_uuid.scan(NAMESPACE_REGEX).flatten.map { |s| s.to_i(16) }.pack(PACK_PATTERN)
end
end
end
end
end