From 35622c8b94cfc406474933474bbee41eb7715ca5 Mon Sep 17 00:00:00 2001 From: Piotr Kozimor Date: Mon, 7 Jun 2021 11:17:00 +0200 Subject: [PATCH] Define APIs for ThreePid component --- threepid/api.go | 38 ++++++++++++++++++++++++++++++++++++++ threepid/storage.go | 8 ++++++++ 2 files changed, 46 insertions(+) create mode 100644 threepid/api.go create mode 100644 threepid/storage.go diff --git a/threepid/api.go b/threepid/api.go new file mode 100644 index 000000000..6731d7a4d --- /dev/null +++ b/threepid/api.go @@ -0,0 +1,38 @@ +package threepid + +import "context" + +type API interface { + CreateSession(context.Context, *CreateSessionRequest, *Session) error + ValidateSession(context.Context, *ValidateSessionRequest, struct{}) error + GetThreePidForSession(context.Context, *SessionOwnership, *GetThreePidForSessionResponse) error + DeleteSession(context.Context, *SessionOwnership, struct{}) error + IsSessionValidated(context.Context, *SessionOwnership, *IsSessionValidatedResponse) error +} + +type CreateSessionRequest struct { + ClientSecret, NextLink, ThreePid string +} + +type ValidateSessionRequest struct { + SessionOwnership + Token string +} + +type GetThreePidForSessionResponse struct { + ThreePid string +} + +type SessionOwnership struct { + Sid, ClientSecret string +} + +type Session struct { + Sid, ClientSecret, ThreePid, Token, NextLink string + SendAttempt int +} + +type IsSessionValidatedResponse struct { + Validated bool + ValidatedAt int +} diff --git a/threepid/storage.go b/threepid/storage.go new file mode 100644 index 000000000..8da3b2666 --- /dev/null +++ b/threepid/storage.go @@ -0,0 +1,8 @@ +package threepid + +type storage interface { + InsertSession(*Session) error + GetSession(sid string) (*Session, error) + GetSessionByThreePidAndSecret(threePid, ClientSecret string) (*Session, error) + RemoveSession(sid string) error +}