Implement key uploads (#1202)

* Add storage layer for postgres/sqlite

* Return OTK counts when inserting new keys

* Hook up the key DB and make a test pass

* Convert postgres queries to be sqlite queries

* Blacklist test due to requiring rejected events

* Unbreak tests

* Update blacklist
This commit is contained in:
Kegsay 2020-07-15 12:02:34 +01:00 committed by GitHub
parent b4c07995d6
commit 9dd2ed7f65
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 868 additions and 27 deletions

View file

@ -17,6 +17,7 @@ package api
import (
"context"
"encoding/json"
"strings"
)
type KeyInternalAPI interface {
@ -27,7 +28,11 @@ type KeyInternalAPI interface {
// KeyError is returned if there was a problem performing/querying the server
type KeyError struct {
Error string
Err string
}
func (k *KeyError) Error() string {
return k.Err
}
// DeviceKeys represents a set of device keys for a single device
@ -52,6 +57,12 @@ type OneTimeKeys struct {
KeyJSON map[string]json.RawMessage
}
// Split a key in KeyJSON into algorithm and key ID
func (k *OneTimeKeys) Split(keyIDWithAlgo string) (algo string, keyID string) {
segments := strings.Split(keyIDWithAlgo, ":")
return segments[0], segments[1]
}
// OneTimeKeysCount represents the counts of one-time keys for a single device
type OneTimeKeysCount struct {
// The user who owns this device
@ -74,6 +85,7 @@ type PerformUploadKeysRequest struct {
// PerformUploadKeysResponse is the response to PerformUploadKeys
type PerformUploadKeysResponse struct {
// A fatal error when processing e.g database failures
Error *KeyError
// A map of user_id -> device_id -> Error for tracking failures.
KeyErrors map[string]map[string]*KeyError