From a55cc3653de22d868ade5303918280a38e8e9fe8 Mon Sep 17 00:00:00 2001
From: Azul <azul@riseup.net>
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/controllers/api/keys_controller.rb  | 7 ++-----
 app/controllers/api/users_controller.rb | 2 +-
 2 files changed, 3 insertions(+), 6 deletions(-)

(limited to 'app/controllers/api')

diff --git a/app/controllers/api/keys_controller.rb b/app/controllers/api/keys_controller.rb
index 7eb76ee..32ccc19 100644
--- a/app/controllers/api/keys_controller.rb
+++ b/app/controllers/api/keys_controller.rb
@@ -5,14 +5,11 @@ class Api::KeysController < ApiController
 
   # get /keys
   def index
-    keys = identity.keys.map do |k,v|
-      [k, JSON.parse(v)]
-    end
-    render json: keys.to_h
+    render json: identity.keys
   end
 
   def show
-    render json: JSON.parse(identity.keys[params[:id]])
+    render json: identity.keys[params[:id]]
   end
 
   def create
diff --git a/app/controllers/api/users_controller.rb b/app/controllers/api/users_controller.rb
index 65b80c7..eda37e8 100644
--- a/app/controllers/api/users_controller.rb
+++ b/app/controllers/api/users_controller.rb
@@ -112,7 +112,7 @@ module Api
       PgpKey.new(key).tap do |key|
         if key.valid?
           identity = Identity.for(@user)
-          identity.set_key(:pgp, key)
+          identity.set_key(:pgp, key.to_s)
           identity.save
         end
       end
-- 
cgit v1.2.3