Class: WiseOMFUtils::UIDHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/wise_omf/uid_helper.rb

Class Method Summary collapse

Class Method Details

.from_uid(uid) ⇒ Object



46
47
48
# File 'lib/wise_omf/uid_helper.rb', line 46

def self.from_uid(uid)
  return JSON.parse(Base64.decode64(uid.gsub("-","\n")))
end

.node_group_uid(reservation, nodeUrns) ⇒ Object



15
16
17
# File 'lib/wise_omf/uid_helper.rb', line 15

def self.node_group_uid(reservation, nodeUrns)
  return to_uid([sort_secret_reservation_keys(reservation), sort_node_urns(nodeUrns)])
end

.reservation_uid(reservation) ⇒ Object



11
12
13
# File 'lib/wise_omf/uid_helper.rb', line 11

def self.reservation_uid(reservation)
  return to_uid(sort_secret_reservation_keys(reservation))
end

.sort_node_urns(nodeUrns) ⇒ Object



20
21
22
23
# File 'lib/wise_omf/uid_helper.rb', line 20

def self.sort_node_urns(nodeUrns)
  result = nodeUrns.to_a.sort!{|a,b| a <=> b}
  return result
end

.sort_secret_reservation_keys(reservation) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/wise_omf/uid_helper.rb', line 25

def self.sort_secret_reservation_keys(reservation)
  keys = reservation.to_hash[:secretReservationKeys]
  # we don't need the username. Delete it from al SRKs:
  keys.each{|k| k.delete(:username)}

  # Sort the keys:
  keys.sort!{|a,b|
    prefixComp = a.to_hash[:nodeUrnPrefix].downcase <=> b.to_hash[:nodeUrnPrefix].downcase
    if prefixComp != 0
      prefixComp
    else
      a.to_hash[:key] <=> b.to_hash[:key]
    end
  }
  return keys
end

.to_uid(object) ⇒ Object



42
43
44
# File 'lib/wise_omf/uid_helper.rb', line 42

def self.to_uid(object)
  return Base64.encode64(JSON.generate(object)).gsub("\n", "-")
end