Module: VWO::Common::UUIDUtils
Constant Summary
collapse
- VWO_NAMESPACE =
uuid_v5(URL_NAMESPACE, 'https://vwo.com')
Constants included
from CONSTANTS
CONSTANTS::API_VERSION, CONSTANTS::HTTPS_PROTOCOL, CONSTANTS::HTTP_PROTOCOL, CONSTANTS::LIBRARY_PATH, CONSTANTS::MAX_TRAFFIC_PERCENT, CONSTANTS::MAX_TRAFFIC_VALUE, CONSTANTS::PLATFORM, CONSTANTS::SDK_VERSION, CONSTANTS::SEED_VALUE, CONSTANTS::STATUS_RUNNING, CONSTANTS::URL_NAMESPACE
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.parse(obj) ⇒ Object
15
16
17
18
19
|
# File 'lib/vwo/common/uuid_utils.rb', line 15
def self.parse(obj)
str = obj.to_s.sub(/\Aurn:uuid:/, '')
str.gsub!(/[^0-9A-Fa-f]/, '')
[str[0..31]].pack 'H*'
end
|
.uuid_v5(uuid_namespace, name) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/vwo/common/uuid_utils.rb', line 21
def self.uuid_v5(uuid_namespace, name)
uuid_namespace = parse(uuid_namespace)
hash_class = ::Digest::SHA1
version = 5
hash = hash_class.new
hash.update(uuid_namespace)
hash.update(name)
ary = hash.digest.unpack('NnnnnN')
ary[2] = (ary[2] & 0x0FFF) | (version << 12)
ary[3] = (ary[3] & 0x3FFF) | 0x8000
'%08x-%04x-%04x-%04x-%04x%08x' % ary
end
|
Instance Method Details
#generate(namespace, name) ⇒ Object
Generated uuid from namespace and name, uses uuid5
@param :namespace Namespace @param[String) :name Name
@return Uuid, nil if any of the arguments is empty
74
75
76
|
# File 'lib/vwo/common/uuid_utils.rb', line 74
def generate(namespace, name)
VWO::Common::UUIDUtils.uuid_v5(namespace, name) if name && namespace
end
|
#generator_for(user_id, account_id) ⇒ Object
Generates desired UUID
@param :user_id User identifier @param :account_id Account identifier
@return Desired UUID
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/vwo/common/uuid_utils.rb', line 47
def generator_for(user_id, account_id)
user_id = user_id.to_s
account_id = account_id.to_s
user_id_namespace = generate(VWO_NAMESPACE, account_id)
uuid_for_account_user_id = generate(user_id_namespace, user_id)
desired_uuid = uuid_for_account_user_id.delete('-').upcase
VWO::CustomLogger.get_instance.log(
LogLevelEnum::DEBUG,
format(
LogMessageEnum::DebugMessages::UUID_FOR_USER,
file: FileNameEnum::UuidUtil,
user_id: user_id,
account_id: account_id,
desired_uuid: desired_uuid
)
)
desired_uuid
end
|