Documentation ¶
Index ¶
- Variables
- func AddKey(userID int64, key string)
- func Authenticate(r *http.Request, body data.SyncRequest) bool
- func AuthenticateWithKeySet(r *http.Request, userID int64, keySet jwk.Set) bool
- func GetFreeUserID() int64
- func GetKeySet(userId int64) (jwk.Set, error)
- func GetUsedUserIDs() map[int64]bool
- func HandleSyncRequest(w http.ResponseWriter, req *http.Request, noAuth bool)
- func ReadKey(path string) string
- func SolveConflict(userId int64, store storage.Storage) (bool, error)
- func Sync(syncRequest data.SyncRequest, store storage.Storage) ([]data.Interval, bool, error)
- func UniteTagsAndAnnotation(a data.Interval, b data.Interval) ([]string, string)
- type ErrorResponseBody
Constants ¶
This section is empty.
Variables ¶
var PublicKeyLocation string
Functions ¶
func Authenticate ¶
func Authenticate(r *http.Request, body data.SyncRequest) bool
Authenticate returns true iff the JWT specified in the HTTP requests' Bearer token was signed by the correct user. If any step of the authentication process fails or there is no matching public key, Authenticate returns false
func AuthenticateWithKeySet ¶
AuthenticateWithKeySet returns true iff the JWT in the Bearer token can be validated in verified with a key in the given key set
func GetFreeUserID ¶
func GetFreeUserID() int64
GetFreeUserID returns the smallest valid unused user id
func GetKeySet ¶
GetKeySet returns the key set of user with a given userId. Returns an error if the keys file of that user was not found or could not be parsed.
func GetUsedUserIDs ¶
GetUsedUserIDs returns a map containing every user id with an existing file [user id]_keys in PublicKeyLocation directory
func HandleSyncRequest ¶
func HandleSyncRequest(w http.ResponseWriter, req *http.Request, noAuth bool)
HandleSyncRequest receives sync requests and starts the sync process with the received data.
func SolveConflict ¶
SolveConflict merges overlapping intervals of given user. It then updates userId's state in store accordingly SolveConflict returns true iff a conflict was detected
func Sync ¶
Sync updates the stored state in passed storage.Storage for the user issuing the sync request. If something fails it tries to restore the state prior to the syncRequest. This is not always possible though. The error message denotes whether restoring state was successful. Later atomicity should be guaranteed by storage. Iff no errors occur Sync returns the synced interval data of the user issuing the sync request.
func UniteTagsAndAnnotation ¶
UniteTagsAndAnnotation computes the new tags and annotation for overlapping intervals and returns tags, annotation. Case 1: Iff only one interval has an Annotation, we use this annotation. Case 2: Iff no interval has an annotation, we use "" as annotation. Case 3: Iff both intervals have different annotation, we use "" as annotation, and add both annotation to tags. Case 4: Iff both intervals have the same annotation, we just use that annotation As tags we return the alphabetically sorted union of both intervals' tags (and both annotations in Case 3) without duplicates.
Types ¶
type ErrorResponseBody ¶
An ErrorResponseBody represents a JSON message that is sent to the client when an error occurs
func (ErrorResponseBody) ToString ¶
func (e ErrorResponseBody) ToString() string
Returns a string representation of this error reponse which will be sent to the client