generated from coulomb/repo-seed
feat: add vsm hub metadata
Some checks failed
Build and Deploy / build-push-deploy (push) Has been cancelled
Some checks failed
Build and Deploy / build-push-deploy (push) Has been cancelled
This commit is contained in:
@@ -61,6 +61,9 @@ hubDetailJson hub mManifest mSnapshot =
|
||||
, "slug" .= hub.slug
|
||||
, "domain" .= hub.domain
|
||||
, "hubKind" .= hub.hubKind
|
||||
, "hubFamily" .= hub.hubFamily
|
||||
, "vsmFunction" .= hub.vsmFunction
|
||||
, "vsmSystem" .= hub.vsmSystem
|
||||
, "gaafStatus" .= gaafIndicator
|
||||
, "manifest" .= fmap manifestSummary mManifest
|
||||
, "healthScore" .= fmap (.healthScore) mSnapshot
|
||||
|
||||
@@ -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 ]
|
||||
|
||||
@@ -92,6 +92,7 @@ buildOpenApiSpec = do
|
||||
]
|
||||
]
|
||||
, "Hub" .= hubSchema
|
||||
, "CreateHubRequest" .= createHubRequestSchema
|
||||
, "HubCapabilityManifest" .= manifestSchema
|
||||
, "ApiConsumer" .= apiConsumerSchema
|
||||
, "ApiKey" .= apiKeySchema
|
||||
@@ -320,10 +321,28 @@ hubSchema = object
|
||||
, "name" .= strProp
|
||||
, "domain" .= strProp
|
||||
, "hubKind" .= object ["type" .= ("string" :: Text), "enum" .= ["domain" :: Text, "shared"]]
|
||||
, "hubFamily" .= object ["type" .= ("string" :: Text), "enum" .= ["vsm" :: Text]]
|
||||
, "vsmFunction" .= strProp
|
||||
, "vsmSystem" .= object ["type" .= ("string" :: Text), "enum" .= ["1" :: Text, "2", "3", "3*", "4", "5", "environment"]]
|
||||
, "createdAt" .= object ["type" .= ("string" :: Text), "format" .= ("date-time" :: Text)]
|
||||
]
|
||||
]
|
||||
|
||||
createHubRequestSchema :: Value
|
||||
createHubRequestSchema = object
|
||||
[ "type" .= ("object" :: Text)
|
||||
, "required" .= (["slug", "name", "domain"] :: [Text])
|
||||
, "properties" .= object
|
||||
[ "slug" .= strProp
|
||||
, "name" .= strProp
|
||||
, "domain" .= strProp
|
||||
, "hubKind" .= object ["type" .= ("string" :: Text), "enum" .= ["domain" :: Text, "shared"]]
|
||||
, "hubFamily" .= object ["type" .= ("string" :: Text), "enum" .= ["vsm" :: Text]]
|
||||
, "vsmFunction" .= strProp
|
||||
, "vsmSystem" .= object ["type" .= ("string" :: Text), "enum" .= ["1" :: Text, "2", "3", "3*", "4", "5", "environment"]]
|
||||
]
|
||||
]
|
||||
|
||||
widgetSchema :: Value
|
||||
widgetSchema = object
|
||||
[ "type" .= ("object" :: Text)
|
||||
|
||||
@@ -94,7 +94,7 @@ tsSdkClientClass = T.unlines
|
||||
, " });"
|
||||
, " }"
|
||||
, ""
|
||||
, " async createHub(body: { slug: string; name: string; domain: string; hubKind?: 'domain' | 'shared' }) {"
|
||||
, " async createHub(body: { slug: string; name: string; domain: string; hubKind?: 'domain' | 'shared'; hubFamily?: 'vsm'; vsmFunction?: string; vsmSystem?: '1' | '2' | '3' | '3*' | '4' | '5' | 'environment' }) {"
|
||||
, " return this.fetch('/hubs', 'POST', body).then(r => r.json());"
|
||||
, " }"
|
||||
, ""
|
||||
@@ -177,8 +177,12 @@ pyClientClass = T.unlines
|
||||
, " with urllib.request.urlopen(req) as resp:"
|
||||
, " return json.loads(resp.read())"
|
||||
, ""
|
||||
, " def create_hub(self, slug: str, name: str, domain: str, hub_kind: str = 'domain') -> dict:"
|
||||
, " return self._request('/hubs', 'POST', {'slug': slug, 'name': name, 'domain': domain, 'hubKind': hub_kind})"
|
||||
, " def create_hub(self, slug: str, name: str, domain: str, hub_kind: str = 'domain', hub_family: Optional[str] = None, vsm_function: Optional[str] = None, vsm_system: Optional[str] = None) -> dict:"
|
||||
, " body: dict = {'slug': slug, 'name': name, 'domain': domain, 'hubKind': hub_kind}"
|
||||
, " if hub_family: body['hubFamily'] = hub_family"
|
||||
, " if vsm_function: body['vsmFunction'] = vsm_function"
|
||||
, " if vsm_system: body['vsmSystem'] = vsm_system"
|
||||
, " return self._request('/hubs', 'POST', body)"
|
||||
, ""
|
||||
, " def create_hub_capability_manifest(self, body: dict) -> dict:"
|
||||
, " return self._request('/hub-capability-manifests', 'POST', body)"
|
||||
|
||||
Reference in New Issue
Block a user