feat: add vsm hub metadata
Some checks failed
Build and Deploy / build-push-deploy (push) Has been cancelled

This commit is contained in:
2026-05-19 02:16:39 +02:00
parent 75ad691dd6
commit 5d5e810886
11 changed files with 161 additions and 6 deletions

View File

@@ -45,6 +45,9 @@ createHub = do
name = paramOrNothing @Text "name"
domain = paramOrNothing @Text "domain"
kind = fromMaybe "domain" (nonEmptyText =<< paramOrNothing @Text "hubKind")
hubFamily = nonEmptyText =<< paramOrNothing @Text "hubFamily"
vsmFunction = nonEmptyText =<< paramOrNothing @Text "vsmFunction"
vsmSystem = nonEmptyText =<< paramOrNothing @Text "vsmSystem"
let missing = missingRequiredFields
[ ("slug", slug)
@@ -65,6 +68,14 @@ createHub = do
, "valid" .= validCreateHubKinds
]
unless (validVsmMetadata hubFamily vsmFunction vsmSystem) do
respondWithStatus 422 $ object
[ "error" .= ("Invalid VSM hub metadata" :: Text)
, "code" .= ("invalid_vsm_metadata" :: Text)
, "hint" .= ("Use no VSM fields, or set hubFamily=vsm with vsmFunction and vsmSystem." :: Text)
, "validVsmSystems" .= validVsmSystems
]
let Just slugText = slug
Just nameText = name
Just domainText = domain
@@ -84,6 +95,9 @@ createHub = do
|> set #name nameText
|> set #domain domainText
|> set #hubKind kind
|> set #hubFamily hubFamily
|> set #vsmFunction vsmFunction
|> set #vsmSystem vsmSystem
|> createRecord
respondWithStatus 201 (hubToJson hub)
@@ -94,6 +108,9 @@ hubToJson hub = object
, "name" .= hub.name
, "domain" .= hub.domain
, "hubKind" .= hub.hubKind
, "hubFamily" .= hub.hubFamily
, "vsmFunction" .= hub.vsmFunction
, "vsmSystem" .= hub.vsmSystem
, "createdAt" .= hub.createdAt
]
@@ -103,6 +120,18 @@ validCreateHubKinds = ["domain", "shared"]
validCreateHubKind :: Text -> Bool
validCreateHubKind kind = kind `elem` validCreateHubKinds
validVsmSystems :: [Text]
validVsmSystems = ["1", "2", "3", "3*", "4", "5", "environment"]
validVsmSystem :: Text -> Bool
validVsmSystem systemName = systemName `elem` validVsmSystems
validVsmMetadata :: Maybe Text -> Maybe Text -> Maybe Text -> Bool
validVsmMetadata Nothing Nothing Nothing = True
validVsmMetadata (Just "vsm") (Just functionName) (Just systemName) =
functionName /= "" && validVsmSystem systemName
validVsmMetadata _ _ _ = False
missingRequiredFields :: [(Text, Maybe Text)] -> [Text]
missingRequiredFields fields =
[ name | (name, value) <- fields, maybe True (== "") value ]