From a55cc3653de22d868ade5303918280a38e8e9fe8 Mon Sep 17 00:00:00 2001 From: Azul Date: Wed, 31 Jan 2018 12:27:55 +0100 Subject: keys: store type and rev in hash rather than serialized Since the old keys used to be strings i started out by json serializing the new keys with type, value, rev. However storing serialized json in couch (json) does not really make sense. So now we do not serialize but instead have one json document. The lookup for a key of type pgp may still return a string but for everything that uses the new api it will return a hash with type and revision. This data structure is way easier to handle also on the nickserver side. --- app/models/identity.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'app/models/identity.rb') diff --git a/app/models/identity.rb b/app/models/identity.rb index b8c2245..13ce124 100644 --- a/app/models/identity.rb +++ b/app/models/identity.rb @@ -131,9 +131,10 @@ class Identity < CouchRest::Model::Base read_attribute('keys') || HashWithIndifferentAccess.new end - def set_key(type, key) - return if keys[type] == key.to_s - write_attribute('keys', keys.merge(type => key.to_s)) + def set_key(type, key_hash) + key_hash.stringify_keys! if key_hash.respond_to? :stringify_keys! + return if keys[type] == key_hash + write_attribute('keys', keys.merge(type => key_hash)) end def delete_key(type) -- cgit v1.2.3