Skip to content

Commit

Permalink
spar: Move changes for named scim auth-tokens to V8 (#4370)
Browse files Browse the repository at this point in the history
* spar: Move changes for named scim auth-tokens to V8

* Regen swagger-v7.json

Also includes changes from #4368

* Remove redundant wrapper function in spar.

* Clarify internal comment.

* Bring back the old constraints on number of idps in create-idp V7.

---------

Co-authored-by: Marko Dimjašević <[email protected]>
Co-authored-by: Matthias Fischmann <[email protected]>
  • Loading branch information
3 people authored Dec 11, 2024
1 parent 8af8925 commit 97b59ab
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 243 deletions.
21 changes: 11 additions & 10 deletions libs/wire-api/src/Wire/API/Routes/Public/Spar.hs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ type APIIDP =
Named "idp-get" (ZOptUser :> IdpGet)
:<|> Named "idp-get-raw" (ZOptUser :> IdpGetRaw)
:<|> Named "idp-get-all" (ZOptUser :> IdpGetAll)
:<|> Named "idp-create@v7" (Until 'V8 :> ZOptUser :> IdpCreate) -- (change is semantic, see handler)
:<|> Named "idp-create" (ZOptUser :> IdpCreate)
:<|> Named "idp-update" (ZOptUser :> IdpUpdate)
:<|> Named "idp-delete" (ZOptUser :> IdpDelete)
Expand Down Expand Up @@ -189,21 +190,21 @@ data ScimSite tag route = ScimSite
deriving (Generic)

type APIScimToken =
Named "auth-tokens-create@v6" (Until 'V7 :> ZOptUser :> APIScimTokenCreateV6)
:<|> Named "auth-tokens-create" (From 'V7 :> ZOptUser :> APIScimTokenCreate)
:<|> Named "auth-tokens-put-name" (From 'V7 :> ZUser :> APIScimTokenPutName)
Named "auth-tokens-create@v7" (Until 'V8 :> ZOptUser :> APIScimTokenCreateV7)
:<|> Named "auth-tokens-create" (From 'V8 :> ZOptUser :> APIScimTokenCreate)
:<|> Named "auth-tokens-put-name" (From 'V8 :> ZUser :> APIScimTokenPutName)
:<|> Named "auth-tokens-delete" (ZOptUser :> APIScimTokenDelete)
:<|> Named "auth-tokens-list@v6" (Until 'V7 :> ZOptUser :> APIScimTokenListV6)
:<|> Named "auth-tokens-list" (From 'V7 :> ZOptUser :> APIScimTokenList)
:<|> Named "auth-tokens-list@v7" (Until 'V8 :> ZOptUser :> APIScimTokenListV7)
:<|> Named "auth-tokens-list" (From 'V8 :> ZOptUser :> APIScimTokenList)

type APIScimTokenPutName =
Capture "id" ScimTokenId
:> ReqBody '[JSON] ScimTokenName
:> Put '[JSON] ()

type APIScimTokenCreateV6 =
VersionedReqBody 'V6 '[JSON] CreateScimToken
:> Post '[JSON] CreateScimTokenResponseV6
type APIScimTokenCreateV7 =
VersionedReqBody 'V7 '[JSON] CreateScimToken
:> Post '[JSON] CreateScimTokenResponseV7

type APIScimTokenCreate =
ReqBody '[JSON] CreateScimToken
Expand All @@ -216,8 +217,8 @@ type APIScimTokenDelete =
type APIScimTokenList =
Get '[JSON] ScimTokenList

type APIScimTokenListV6 =
Get '[JSON] ScimTokenListV6
type APIScimTokenListV7 =
Get '[JSON] ScimTokenListV7

data SparAPITag

Expand Down
57 changes: 33 additions & 24 deletions libs/wire-api/src/Wire/API/User/Scim.hs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ instance ToSchema ScimTokenInfo where
<*> (.stiName) .= field "name" schema

-- | Metadata that we store about each token.
data ScimTokenInfoV6 = ScimTokenInfoV6
data ScimTokenInfoV7 = ScimTokenInfoV7
{ -- | Which team can be managed with the token
stiTeam :: !TeamId,
-- | Token ID, can be used to eg. delete the token
Expand All @@ -196,13 +196,13 @@ data ScimTokenInfoV6 = ScimTokenInfoV6
stiDescr :: !Text
}
deriving (Eq, Show, Generic)
deriving (Arbitrary) via (GenericUniform ScimTokenInfoV6)
deriving (A.ToJSON, A.FromJSON, S.ToSchema) via (Schema.Schema ScimTokenInfoV6)
deriving (Arbitrary) via (GenericUniform ScimTokenInfoV7)
deriving (A.ToJSON, A.FromJSON, S.ToSchema) via (Schema.Schema ScimTokenInfoV7)

instance ToSchema ScimTokenInfoV6 where
instance ToSchema ScimTokenInfoV7 where
schema =
object "ScimTokenInfoV6" $
ScimTokenInfoV6
object "ScimTokenInfoV7" $
ScimTokenInfoV7
<$> (.stiTeam) .= field "team" schema
<*> (.stiId) .= field "id" schema
<*> (.stiCreatedAt) .= field "created_at" utcTimeSchema
Expand Down Expand Up @@ -433,20 +433,29 @@ data CreateScimToken = CreateScimToken
deriving (A.ToJSON, A.FromJSON, S.ToSchema) via (Schema.Schema CreateScimToken)

createScimTokenSchema :: Maybe Version -> ValueSchema NamedSwaggerDoc CreateScimToken
createScimTokenSchema v =
object ("CreateScimToken" <> foldMap (Text.toUpper . versionText) v) $
createScimTokenSchema mVersion =
object ("CreateScimToken" <> foldMap (Text.toUpper . versionText) mVersion) $
CreateScimToken
<$> (.description) .= field "description" schema
<*> password .= optField "password" (maybeWithDefault A.Null schema)
<*> verificationCode .= optField "verification_code" (maybeWithDefault A.Null schema)
<*> (if isJust v then const Nothing else (.name)) .= maybe_ (optField "name" schema)
<*> (if isJust v then const Nothing else (fmap SAML.fromIdPId . idp)) .= maybe_ (optField "idp" (SAML.IdPId <$> uuidSchema))
<*> nameSchema
<*> idpSchema
where
nameSchema =
case mVersion of
Just v | v <= V7 -> const Nothing .= pure Nothing
_ -> (.name) .= maybe_ (optField "name" schema)
idpSchema =
case mVersion of
Just v | v <= V7 -> const Nothing .= pure Nothing
_ -> (fmap SAML.fromIdPId . idp) .= maybe_ (optField "idp" (SAML.IdPId <$> uuidSchema))

instance ToSchema CreateScimToken where
schema = createScimTokenSchema Nothing

instance ToSchema (Versioned 'V6 CreateScimToken) where
schema = Versioned <$> unVersioned .= createScimTokenSchema (Just V6)
instance ToSchema (Versioned 'V7 CreateScimToken) where
schema = Versioned <$> unVersioned .= createScimTokenSchema (Just V7)

-- | Type used for the response of 'APIScimTokenCreate'.
data CreateScimTokenResponse = CreateScimTokenResponse
Expand All @@ -464,18 +473,18 @@ instance ToSchema CreateScimTokenResponse where
<$> (.token) .= field "token" schema
<*> (.info) .= field "info" schema

data CreateScimTokenResponseV6 = CreateScimTokenResponseV6
data CreateScimTokenResponseV7 = CreateScimTokenResponseV7
{ token :: ScimToken,
info :: ScimTokenInfoV6
info :: ScimTokenInfoV7
}
deriving (Eq, Show, Generic)
deriving (Arbitrary) via (GenericUniform CreateScimTokenResponseV6)
deriving (A.ToJSON, A.FromJSON, S.ToSchema) via (Schema.Schema CreateScimTokenResponseV6)
deriving (Arbitrary) via (GenericUniform CreateScimTokenResponseV7)
deriving (A.ToJSON, A.FromJSON, S.ToSchema) via (Schema.Schema CreateScimTokenResponseV7)

instance ToSchema CreateScimTokenResponseV6 where
instance ToSchema CreateScimTokenResponseV7 where
schema =
object "CreateScimTokenResponseV6" $
CreateScimTokenResponseV6
object "CreateScimTokenResponseV7" $
CreateScimTokenResponseV7
<$> (.token) .= field "token" schema
<*> (.info) .= field "info" schema

Expand All @@ -492,14 +501,14 @@ data ScimTokenList = ScimTokenList
instance ToSchema ScimTokenList where
schema = object "ScimTokenList" $ ScimTokenList <$> (.scimTokenListTokens) .= field "tokens" (array schema)

data ScimTokenListV6 = ScimTokenListV6
{ scimTokenListTokens :: [ScimTokenInfoV6]
data ScimTokenListV7 = ScimTokenListV7
{ scimTokenListTokens :: [ScimTokenInfoV7]
}
deriving (Eq, Show)
deriving (A.ToJSON, A.FromJSON, S.ToSchema) via (Schema.Schema ScimTokenListV6)
deriving (A.ToJSON, A.FromJSON, S.ToSchema) via (Schema.Schema ScimTokenListV7)

instance ToSchema ScimTokenListV6 where
schema = object "ScimTokenListV6" $ ScimTokenListV6 <$> (.scimTokenListTokens) .= field "tokens" (array schema)
instance ToSchema ScimTokenListV7 where
schema = object "ScimTokenListV7" $ ScimTokenListV7 <$> (.scimTokenListTokens) .= field "tokens" (array schema)

newtype ScimTokenName = ScimTokenName {fromScimTokenName :: Text}
deriving (Eq, Show)
Expand Down
Loading

0 comments on commit 97b59ab

Please sign in to comment.