diff options
author | azul <azul@riseup.net> | 2018-01-31 04:44:15 -0800 |
---|---|---|
committer | azul <azul@riseup.net> | 2018-01-31 04:44:15 -0800 |
commit | b58c2d841013ec9fc30c3c8e6dcc3ee73dccfbf4 (patch) | |
tree | 5c8c2caf8a581b215c63c93444c5b72a5175c0f8 /app/models | |
parent | a6e0378669118feeb0c42b6282b0b469fb11ad8f (diff) | |
parent | a55cc3653de22d868ade5303918280a38e8e9fe8 (diff) |
Merge branch 'feature/different-keytypes' into 'master'
couch: add identity view to get all keys
See merge request leap/webapp!61
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/identity.rb | 7 | ||||
-rw-r--r-- | app/models/keyring.rb | 9 |
2 files changed, 10 insertions, 6 deletions
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) diff --git a/app/models/keyring.rb b/app/models/keyring.rb index 66f7bfd..a5320c2 100644 --- a/app/models/keyring.rb +++ b/app/models/keyring.rb @@ -20,13 +20,13 @@ class Keyring def create(type, value) raise Error, "key already exists" if storage.keys[type].present? - storage.set_key type, {type: type, value: value, rev: new_rev}.to_json + storage.set_key type, {type: type, value: value, rev: new_rev} storage.save end def update(type, rev:, value:) check_rev type, rev - storage.set_key type, {type: type, value: value, rev: new_rev}.to_json + storage.set_key type, {type: type, value: value, rev: new_rev} storage.save end @@ -37,7 +37,7 @@ class Keyring end def key_of_type(type) - JSON.parse(storage.keys[type]) if storage.keys[type] + storage.keys[type] end protected @@ -46,6 +46,9 @@ class Keyring def check_rev(type, rev) old = key_of_type(type) raise NotFound, type unless old + # We used to store plain strings. It's deprecated now. + # If we happen to run into them do not check their revision. + return if old.is_a? String raise Error, "wrong revision: #{rev}" unless old['rev'] == rev end |