-
Notifications
You must be signed in to change notification settings - Fork 333
Servantify stern #2742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Servantify stern #2742
Changes from 4 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
4408bc2
servantify stern wip, get users by email
battermann 7978112
better ToSchema instance for UserAccount
battermann fb9bbb4
renaming
battermann 4dbc6c7
roundtrip test with swagger
battermann fa6243b
Factor out duplicate code into wire-api.
fisx 0f694fd
Move types from brig-types to wire-api for adding golden tests.
fisx b9309cb
Revert "Move types from brig-types to wire-api for adding golden tests."
fisx d700355
Add cheap golden test.
fisx 34d411b
Merge branch 'develop' into battermann/servantify-stern
fisx 185a472
Fixup
fisx 8bbb9ec
Clarify
fisx 55b2017
Fixup
fisx 7389ce2
Cleanup
fisx d712aab
Simplify
fisx 08c7455
Changelog
fisx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,5 +1,3 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
-- This file is part of the Wire Server implementation. | ||
-- | ||
-- Copyright (C) 2022 Wire Swiss GmbH <[email protected]> | ||
|
@@ -30,14 +28,16 @@ module Brig.Types.Intra | |
) | ||
where | ||
|
||
import Data.Aeson | ||
import qualified Data.Aeson.KeyMap as KeyMap | ||
import Data.Aeson as A | ||
import Data.Code as Code | ||
import Data.Id (TeamId) | ||
import Data.Misc (PlainTextPassword (..)) | ||
import qualified Data.Text as Text | ||
import qualified Data.Schema as Schema | ||
import qualified Data.Swagger as S | ||
import Imports | ||
import Test.QuickCheck (Arbitrary) | ||
import Wire.API.User | ||
import Wire.Arbitrary (GenericUniform (..)) | ||
|
||
------------------------------------------------------------------------------- | ||
-- AccountStatus | ||
|
@@ -52,22 +52,19 @@ data AccountStatus | |
-- creating via scim. | ||
PendingInvitation | ||
deriving (Eq, Show, Generic) | ||
|
||
instance FromJSON AccountStatus where | ||
parseJSON = withText "account-status" $ \s -> case Text.toLower s of | ||
"active" -> pure Active | ||
"suspended" -> pure Suspended | ||
"deleted" -> pure Deleted | ||
"ephemeral" -> pure Ephemeral | ||
"pending-invitation" -> pure PendingInvitation | ||
_ -> fail $ "Invalid account status: " ++ Text.unpack s | ||
|
||
instance ToJSON AccountStatus where | ||
toJSON Active = String "active" | ||
toJSON Suspended = String "suspended" | ||
toJSON Deleted = String "deleted" | ||
toJSON Ephemeral = String "ephemeral" | ||
toJSON PendingInvitation = String "pending-invitation" | ||
deriving (Arbitrary) via (GenericUniform AccountStatus) | ||
deriving (ToJSON, FromJSON, S.ToSchema) via Schema.Schema AccountStatus | ||
|
||
instance Schema.ToSchema AccountStatus where | ||
schema = | ||
Schema.enum @Text "AccountStatus" $ | ||
mconcat | ||
[ Schema.element "active" Active, | ||
Schema.element "suspended" Suspended, | ||
Schema.element "deleted" Deleted, | ||
Schema.element "ephemeral" Ephemeral, | ||
Schema.element "pending-invitation" PendingInvitation | ||
] | ||
|
||
data AccountStatusResp = AccountStatusResp {fromAccountStatusResp :: AccountStatus} | ||
|
||
|
@@ -100,21 +97,15 @@ data UserAccount = UserAccount | |
accountStatus :: !AccountStatus | ||
} | ||
deriving (Eq, Show, Generic) | ||
|
||
instance FromJSON UserAccount where | ||
parseJSON j@(Object o) = do | ||
u <- parseJSON j | ||
s <- o .: "status" | ||
pure $ UserAccount u s | ||
parseJSON _ = mzero | ||
|
||
instance ToJSON UserAccount where | ||
toJSON (UserAccount u s) = | ||
case toJSON u of | ||
Object o -> | ||
Object $ KeyMap.insert "status" (toJSON s) o | ||
other -> | ||
error $ "toJSON UserAccount: not an object: " <> show (encode other) | ||
deriving (Arbitrary) via (GenericUniform UserAccount) | ||
deriving (ToJSON, FromJSON, S.ToSchema) via Schema.Schema UserAccount | ||
|
||
instance Schema.ToSchema UserAccount where | ||
schema = | ||
Schema.object "UserAccount" $ | ||
UserAccount | ||
<$> accountUser Schema..= userObjectSchema | ||
<*> accountStatus Schema..= Schema.field "status" Schema.schema | ||
|
||
------------------------------------------------------------------------------- | ||
-- NewUserScimInvitation | ||
|
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
-- This file is part of the Wire Server implementation. | ||
-- | ||
-- Copyright (C) 2022 Wire Swiss GmbH <[email protected]> | ||
-- | ||
-- This program is free software: you can redistribute it and/or modify it under | ||
-- the terms of the GNU Affero General Public License as published by the Free | ||
-- Software Foundation, either version 3 of the License, or (at your option) any | ||
-- later version. | ||
-- | ||
-- This program is distributed in the hope that it will be useful, but WITHOUT | ||
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
-- FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more | ||
-- details. | ||
-- | ||
-- 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 Stern.API.Routes where | ||
|
||
import Brig.Types.Intra (UserAccount) | ||
import Control.Lens | ||
import Data.Containers.ListUtils (nubOrd) | ||
import Data.Swagger hiding (Contact, Header, Schema, ToSchema) | ||
import qualified Data.Swagger as S | ||
import Imports hiding (head) | ||
import Servant (JSON) | ||
import Servant hiding (Handler, JSON, addHeader, respond) | ||
import Servant.Swagger (HasSwagger (toSwagger)) | ||
import Servant.Swagger.Internal.Orphans () | ||
import Servant.Swagger.UI | ||
import Wire.API.Routes.Named | ||
import Wire.API.User (Email) | ||
|
||
type SternAPI = | ||
Named | ||
"get-users-by-email" | ||
( Summary "Displays user's info given an email address" | ||
:> "users" | ||
:> QueryParam' [Required, Strict, Description "Email address"] "email" Email | ||
:> Get '[JSON] [UserAccount] | ||
) | ||
|
||
------------------------------------------------------------------------------- | ||
-- Swagger | ||
|
||
sternSwagger :: Swagger | ||
sternSwagger = toSwagger (Proxy @SternAPI) | ||
|
||
type SwaggerDocsAPI = "backoffice" :> "api" :> SwaggerSchemaUI "swagger-ui" "swagger.json" | ||
|
||
swaggerDocsAPI :: Servant.Server SwaggerDocsAPI | ||
swaggerDocsAPI = | ||
swaggerSchemaUIServer $ | ||
sternSwagger | ||
& S.info . S.title .~ "Stern API" | ||
& S.security %~ nub | ||
-- sanitise definitions | ||
& S.definitions . traverse %~ sanitise | ||
-- sanitise general responses | ||
& S.responses . traverse . S.schema . _Just . S._Inline %~ sanitise | ||
-- sanitise all responses of all paths | ||
& S.allOperations . S.responses . S.responses | ||
. traverse | ||
. S._Inline | ||
. S.schema | ||
. _Just | ||
. S._Inline | ||
%~ sanitise | ||
where | ||
sanitise :: S.Schema -> S.Schema | ||
sanitise = | ||
(S.properties . traverse . S._Inline %~ sanitise) | ||
. (S.required %~ nubOrd) | ||
. (S.enum_ . _Just %~ nub) |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.