-
Notifications
You must be signed in to change notification settings - Fork 332
hscim client #1699
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
hscim client #1699
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4a6517c
Improve roundtrip generator.
fisx 1a3f194
Extend module exports.
fisx 6f6429e
Missing FromJSON instances.
fisx 77d6538
Client routes.
fisx 7f4cf25
CHANGELOG
fisx 892efab
golden tests.
fisx 5da66dc
use generic where appropriate.
fisx 14a064f
Merge branch 'develop' into hscim-client
fisx e0b3c96
applicative hedgehog generators.
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
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,217 @@ | ||
| {-# LANGUAGE AllowAmbiguousTypes #-} | ||
fisx marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| -- This file is part of the Wire Server implementation. | ||
| -- | ||
| -- Copyright (C) 2020 Wire Swiss GmbH <opensource@wire.com> | ||
fisx marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| -- | ||
| -- 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 Web.Scim.Client | ||
| ( HasScimClient, | ||
|
|
||
| -- * config | ||
| spConfig, | ||
| getSchemas, | ||
| schema, | ||
| resourceTypes, | ||
|
|
||
| -- * user | ||
| scimClients, | ||
| getUsers, | ||
| getUser, | ||
| postUser, | ||
| putUser, | ||
| patchUserr, | ||
| deleteUser, | ||
|
|
||
| -- * group | ||
| getGroups, | ||
| getGroup, | ||
| postGroup, | ||
| putGroup, | ||
| patchGroup, | ||
| deleteGroup, | ||
| ) | ||
| where | ||
|
|
||
| import Control.Exception | ||
| import Data.Aeson (FromJSON, ToJSON, Value) | ||
| import Data.Text | ||
| import Servant.API | ||
| import Servant.Client | ||
| import Servant.Client.Generic | ||
| import qualified Web.Scim.Capabilities.MetaSchema as MetaSchema | ||
| import Web.Scim.Class.Auth | ||
| import Web.Scim.Class.Group (Group, GroupId, StoredGroup) | ||
| import Web.Scim.Class.User (StoredUser) | ||
| import Web.Scim.Filter (Filter) | ||
| import Web.Scim.Schema.ListResponse (ListResponse) | ||
| import Web.Scim.Schema.PatchOp (PatchOp) | ||
| import qualified Web.Scim.Schema.ResourceType as ResourceType | ||
| import Web.Scim.Schema.User (User) | ||
| import Web.Scim.Schema.UserTypes (UserExtra, UserId) | ||
| import Web.Scim.Server | ||
|
|
||
| type HasScimClient tag = | ||
| ( AuthTypes tag, | ||
| ToJSON (UserExtra tag), | ||
| FromJSON (UserExtra tag), | ||
| FromJSON (UserId tag), | ||
| FromJSON (GroupId tag), | ||
| ToHttpApiData (AuthData tag), | ||
| ToHttpApiData (UserId tag), | ||
| ToHttpApiData (GroupId tag) | ||
| ) | ||
|
|
||
| scimClients :: HasScimClient tag => ClientEnv -> Site tag (AsClientT IO) | ||
| scimClients env = genericClientHoist $ \x -> runClientM x env >>= either throwIO return | ||
|
|
||
| -- config | ||
|
|
||
| spConfig :: | ||
| forall tag. | ||
| HasScimClient tag => | ||
| ClientEnv -> | ||
| IO MetaSchema.Configuration | ||
| spConfig env = case config @tag (scimClients env) of ((r :<|> _) :<|> (_ :<|> _)) -> r | ||
|
|
||
| getSchemas :: | ||
| forall tag. | ||
| HasScimClient tag => | ||
| ClientEnv -> | ||
| IO (ListResponse Value) | ||
| getSchemas env = case config @tag (scimClients env) of ((_ :<|> r) :<|> (_ :<|> _)) -> r | ||
|
|
||
| schema :: | ||
| forall tag. | ||
| HasScimClient tag => | ||
| ClientEnv -> | ||
| Text -> | ||
| IO Value | ||
| schema env = case config @tag (scimClients env) of ((_ :<|> _) :<|> (r :<|> _)) -> r | ||
|
|
||
| resourceTypes :: | ||
| forall tag. | ||
| HasScimClient tag => | ||
| ClientEnv -> | ||
| IO (ListResponse ResourceType.Resource) | ||
| resourceTypes env = case config @tag (scimClients env) of ((_ :<|> _) :<|> (_ :<|> r)) -> r | ||
|
|
||
| -- users | ||
|
|
||
| getUsers :: | ||
| HasScimClient tag => | ||
| ClientEnv -> | ||
| Maybe (AuthData tag) -> | ||
| Maybe Filter -> | ||
| IO (ListResponse (StoredUser tag)) | ||
| getUsers env tok = case users (scimClients env) tok of ((r :<|> (_ :<|> _)) :<|> (_ :<|> (_ :<|> _))) -> r | ||
|
|
||
| getUser :: | ||
| HasScimClient tag => | ||
| ClientEnv -> | ||
| Maybe (AuthData tag) -> | ||
| UserId tag -> | ||
| IO (StoredUser tag) | ||
| getUser env tok = case users (scimClients env) tok of ((_ :<|> (r :<|> _)) :<|> (_ :<|> (_ :<|> _))) -> r | ||
|
|
||
| postUser :: | ||
| HasScimClient tag => | ||
| ClientEnv -> | ||
| Maybe (AuthData tag) -> | ||
| (User tag) -> | ||
| IO (StoredUser tag) | ||
| postUser env tok = case users (scimClients env) tok of ((_ :<|> (_ :<|> r)) :<|> (_ :<|> (_ :<|> _))) -> r | ||
|
|
||
| putUser :: | ||
| HasScimClient tag => | ||
| ClientEnv -> | ||
| Maybe (AuthData tag) -> | ||
| UserId tag -> | ||
| (User tag) -> | ||
| IO (StoredUser tag) | ||
| putUser env tok = case users (scimClients env) tok of ((_ :<|> (_ :<|> _)) :<|> (r :<|> (_ :<|> _))) -> r | ||
|
|
||
| patchUserr :: | ||
| HasScimClient tag => | ||
| ClientEnv -> | ||
| Maybe (AuthData tag) -> | ||
| UserId tag -> | ||
| PatchOp tag -> | ||
| IO (StoredUser tag) | ||
| patchUserr env tok = case users (scimClients env) tok of ((_ :<|> (_ :<|> _)) :<|> (_ :<|> (r :<|> _))) -> r | ||
|
|
||
| deleteUser :: | ||
| forall tag. | ||
| HasScimClient tag => | ||
| ClientEnv -> | ||
| Maybe (AuthData tag) -> | ||
| UserId tag -> | ||
| IO NoContent | ||
| deleteUser env tok = case users @tag (scimClients env) tok of ((_ :<|> (_ :<|> _)) :<|> (_ :<|> (_ :<|> r))) -> r | ||
|
|
||
| -- groups | ||
|
|
||
| getGroups :: | ||
| forall tag. | ||
| HasScimClient tag => | ||
| ClientEnv -> | ||
| Maybe (AuthData tag) -> | ||
| IO (ListResponse (StoredGroup tag)) | ||
| getGroups = error "groups are not authenticated at the moment; implement that first!" | ||
fisx marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| getGroup :: | ||
| forall tag. | ||
| HasScimClient tag => | ||
| ClientEnv -> | ||
| Maybe (AuthData tag) -> | ||
| GroupId tag -> | ||
| IO (StoredGroup tag) | ||
| getGroup = error "groups are not authenticated at the moment; implement that first!" | ||
|
|
||
| postGroup :: | ||
| forall tag. | ||
| HasScimClient tag => | ||
| ClientEnv -> | ||
| Maybe (AuthData tag) -> | ||
| Group -> | ||
| IO (StoredGroup tag) | ||
| postGroup = error "groups are not authenticated at the moment; implement that first!" | ||
|
|
||
| putGroup :: | ||
| forall tag. | ||
| HasScimClient tag => | ||
| ClientEnv -> | ||
| Maybe (AuthData tag) -> | ||
| GroupId tag -> | ||
| IO (StoredGroup tag) | ||
| putGroup = error "groups are not authenticated at the moment; implement that first!" | ||
|
|
||
| patchGroup :: | ||
| forall tag. | ||
| HasScimClient tag => | ||
| ClientEnv -> | ||
| Maybe (AuthData tag) -> | ||
| GroupId tag -> | ||
| IO (StoredGroup tag) | ||
| patchGroup = error "groups are not authenticated at the moment; implement that first!" | ||
|
|
||
| deleteGroup :: | ||
| forall tag. | ||
| HasScimClient tag => | ||
| ClientEnv -> | ||
| Maybe (AuthData tag) -> | ||
| GroupId tag -> | ||
| IO DeleteNoContent | ||
| deleteGroup = error "groups are not authenticated at the moment; implement that first!" | ||
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
Oops, something went wrong.
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.