-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add endpoint to Federator API, cleanup (#1189)
* Add endpoint to Federator API, cleanup * rename API to Api * remove search endpoint It being here doesn't give us a lot, still needs some answers and tweaks. We will need a while to get there anyways.
- Loading branch information
Showing
6 changed files
with
116 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,53 +17,42 @@ | |
-- You should have received a copy of the GNU Affero General Public License along | ||
-- with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
module Federator.API where | ||
|
||
import Brig.Types.Client.Prekey | ||
import Brig.Types.Test.Arbitrary () | ||
import Data.Aeson.TH (deriveJSON) | ||
import Data.Handle (Handle (..)) | ||
import Data.Id (UserId) | ||
import Data.Qualified | ||
import Federator.Util | ||
module Federator.API | ||
( Api (..), | ||
module Fed, | ||
) | ||
where | ||
|
||
import Data.Id (ConvId, UserId) | ||
import Data.Qualified (Qualified) | ||
import Imports | ||
import Servant.API | ||
import Servant.API.Generic | ||
import Test.QuickCheck | ||
import Wire.API.Federation.API.Conversation as Fed hiding (Api) | ||
import Wire.API.Federation.Event as Fed | ||
import Wire.API.User.Client.Prekey (PrekeyBundle) | ||
|
||
data API route = API | ||
{ _gapiSearch :: | ||
route | ||
:- "i" | ||
:> "search" | ||
-- QUESTION: what exactly should the query be? text + domain? | ||
:> QueryParam' [Required, Strict] "q" (Qualified Handle) | ||
:> Get '[JSON] FUser, | ||
_gapiPrekeys :: | ||
data Api route = Api | ||
{ _gapiPrekeys :: | ||
route | ||
:- "i" | ||
:> "users" | ||
:> Capture "fqu" (Qualified UserId) | ||
:> Capture "id" (Qualified UserId) | ||
:> "prekeys" | ||
:> Get '[JSON] PrekeyBundle | ||
-- FUTUREWORK(federation): | ||
-- this should return a version of PrekeyBundle with qualified UserId, | ||
-- defined in wire-api-federation | ||
:> Get '[JSON] PrekeyBundle, | ||
_gapiJoinConversationById :: | ||
route | ||
:- "i" | ||
:> "conversations" | ||
:> Capture "cnv" (Qualified ConvId) | ||
:> "join" | ||
:> ReqBody '[JSON] Fed.JoinConversationByIdRequest | ||
:> Post '[JSON] (Fed.ConversationUpdateResult Fed.MemberJoin) | ||
} | ||
deriving (Generic) | ||
|
||
-- curl http://localhost:8097/i/[email protected]; curl http://localhost:8097/i/users/`uuid`@example.com/prekeys | ||
|
||
---------------------------------------------------------------------- | ||
-- TODO: add roundtrip tests for *HttpApiData, *JSON, ... | ||
-- | ||
-- TODO: the client ids in the 'PrekeyBundle' aren't really needed here. do we want to make a | ||
-- new type for that, then? | ||
|
||
data FUser = FUser | ||
{ _fuGlobalHandle :: !(Qualified Handle), | ||
_fuFQU :: !(Qualified UserId) | ||
} | ||
deriving (Eq, Show, Generic) | ||
|
||
deriveJSON (wireJsonOptions "_fu") ''FUser | ||
|
||
instance Arbitrary FUser where | ||
arbitrary = FUser <$> arbitrary <*> arbitrary | ||
-- FUTUREWORK: add roundtrip tests for *HttpApiData, *JSON, ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
{-# LANGUAGE GeneralizedNewtypeDeriving #-} | ||
{-# LANGUAGE RecordWildCards #-} | ||
|
||
-- This file is part of the Wire Server implementation. | ||
-- | ||
-- Copyright (C) 2020 Wire Swiss GmbH <[email protected]> | ||
|
@@ -15,25 +18,20 @@ | |
-- You should have received a copy of the GNU Affero General Public License along | ||
-- with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
module Federator.Util | ||
( wireJsonOptions, | ||
module Federator.Impl | ||
( app, | ||
) | ||
where | ||
|
||
import Data.Aeson as Aeson | ||
import Imports | ||
|
||
dropPrefix :: String -> String -> Maybe String | ||
dropPrefix pfx str = | ||
if length pfx > length str | ||
then Nothing | ||
else case splitAt (length pfx) str of | ||
(pfx', sfx) -> | ||
if pfx' /= pfx | ||
then Nothing | ||
else Just sfx | ||
import Data.Proxy | ||
import qualified Federator.API as API | ||
import Federator.Types | ||
import Network.Wai | ||
import Servant.API.Generic | ||
import Servant.Mock | ||
import Servant.Server | ||
|
||
-- | This is a partial function; totality of all calls must be verified by roundtrip tests on | ||
-- the aeson instances involved. | ||
wireJsonOptions :: String -> Options | ||
wireJsonOptions pfx = defaultOptions {fieldLabelModifier = fromJust . dropPrefix pfx . fmap toLower} | ||
app :: Env -> Application | ||
app _ = serve api (mock api Proxy) | ||
where | ||
api = Proxy @(ToServantApi API.Api) |
Oops, something went wrong.