mirror of
https://github.com/dhall-lang/dhall-kubernetes.git
synced 2024-09-10 23:15:30 +03:00
Remove dependence on kubernetes-client-core
This commit is contained in:
parent
7d033a8bc6
commit
ac4b0d1aeb
@ -53,7 +53,7 @@ In the following example, we:
|
|||||||
-- examples/deploymentSimple.dhall
|
-- examples/deploymentSimple.dhall
|
||||||
|
|
||||||
let kubernetes =
|
let kubernetes =
|
||||||
../package.dhall sha256:0a6949aabfb5a1250f08c4e3a533024d4705bea98ace08d8d107417e54a9648a
|
../package.dhall sha256:63eb2e2bb9a50632801b673e67e666740c09c89deb0a0d0592d165178b5eba53
|
||||||
|
|
||||||
let deployment =
|
let deployment =
|
||||||
kubernetes.Deployment::{
|
kubernetes.Deployment::{
|
||||||
@ -152,7 +152,7 @@ let map = Prelude.List.map
|
|||||||
let kv = Prelude.JSON.keyText
|
let kv = Prelude.JSON.keyText
|
||||||
|
|
||||||
let kubernetes =
|
let kubernetes =
|
||||||
../package.dhall sha256:0a6949aabfb5a1250f08c4e3a533024d4705bea98ace08d8d107417e54a9648a
|
../package.dhall sha256:63eb2e2bb9a50632801b673e67e666740c09c89deb0a0d0592d165178b5eba53
|
||||||
|
|
||||||
let Service = { name : Text, host : Text, version : Text }
|
let Service = { name : Text, host : Text, version : Text }
|
||||||
|
|
||||||
|
@ -24,7 +24,6 @@ executable dhall-kubernetes-generator
|
|||||||
aeson >= 1.0.0.0 && < 1.5 ,
|
aeson >= 1.0.0.0 && < 1.5 ,
|
||||||
containers >= 0.5.0.0 && < 0.7 ,
|
containers >= 0.5.0.0 && < 0.7 ,
|
||||||
dhall >= 1.22.0 && < 1.29 ,
|
dhall >= 1.22.0 && < 1.29 ,
|
||||||
kubernetes-client-core >= 0.1.0.1 && < 0.2,
|
|
||||||
megaparsec >= 7.0 && < 7.1 ,
|
megaparsec >= 7.0 && < 7.1 ,
|
||||||
optparse-applicative >= 0.14.3.0 && < 0.15 ,
|
optparse-applicative >= 0.14.3.0 && < 0.15 ,
|
||||||
parser-combinators >= 1.0.3 && < 1.3 ,
|
parser-combinators >= 1.0.3 && < 1.3 ,
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
{-# LANGUAGE NamedFieldPuns #-}
|
||||||
|
{-# LANGUAGE FlexibleContexts #-}
|
||||||
|
|
||||||
module Dhall.Kubernetes.Convert
|
module Dhall.Kubernetes.Convert
|
||||||
( toTypes
|
( toTypes
|
||||||
, toDefault
|
, toDefault
|
||||||
@ -6,6 +9,17 @@ module Dhall.Kubernetes.Convert
|
|||||||
, toDefinition
|
, toDefinition
|
||||||
) where
|
) where
|
||||||
|
|
||||||
|
import Control.Applicative ((<|>))
|
||||||
|
import Data.Aeson
|
||||||
|
import Data.Aeson.Types (Parser, parseMaybe)
|
||||||
|
import Data.Bifunctor (first, second)
|
||||||
|
import Data.Maybe (fromMaybe, mapMaybe)
|
||||||
|
import Data.Set (Set)
|
||||||
|
import Data.Text (Text)
|
||||||
|
import Dhall.Kubernetes.Types
|
||||||
|
import GHC.Generics (Generic, Rep)
|
||||||
|
|
||||||
|
import qualified Data.Char as Char
|
||||||
import qualified Data.List as List
|
import qualified Data.List as List
|
||||||
import qualified Data.Map.Strict as Data.Map
|
import qualified Data.Map.Strict as Data.Map
|
||||||
import qualified Data.Set as Set
|
import qualified Data.Set as Set
|
||||||
@ -14,18 +28,6 @@ import qualified Data.Text as Text
|
|||||||
import qualified Dhall.Core as Dhall
|
import qualified Dhall.Core as Dhall
|
||||||
import qualified Dhall.Map
|
import qualified Dhall.Map
|
||||||
|
|
||||||
import Control.Applicative ((<|>))
|
|
||||||
import Data.Aeson
|
|
||||||
import Data.Aeson.Types (parseMaybe)
|
|
||||||
import Data.Bifunctor (first, second)
|
|
||||||
import Data.Maybe (fromMaybe, mapMaybe)
|
|
||||||
import Data.Set (Set)
|
|
||||||
import Data.Text (Text)
|
|
||||||
|
|
||||||
import Dhall.Kubernetes.Types
|
|
||||||
import Kubernetes.OpenAPI.Model
|
|
||||||
|
|
||||||
|
|
||||||
-- | Get all the required fields for a model
|
-- | Get all the required fields for a model
|
||||||
-- See https://kubernetes.io/docs/concepts/overview/working-with-objects/kubernetes-objects/#required-fields
|
-- See https://kubernetes.io/docs/concepts/overview/working-with-objects/kubernetes-objects/#required-fields
|
||||||
-- TLDR: because k8s API allows PUTS etc with partial data,
|
-- TLDR: because k8s API allows PUTS etc with partial data,
|
||||||
@ -296,6 +298,86 @@ getImportsMap prefixMap duplicateNameHandler objectNames folder toInclude
|
|||||||
[name] -> Just name
|
[name] -> Just name
|
||||||
names -> duplicateNameHandler (kind, names)
|
names -> duplicateNameHandler (kind, names)
|
||||||
|
|
||||||
|
stripPrefix :: (Generic a, GFromJSON Zero (Rep a)) => Int -> Value -> Parser a
|
||||||
|
stripPrefix n = genericParseJSON options
|
||||||
|
where
|
||||||
|
options = defaultOptions { fieldLabelModifier }
|
||||||
|
|
||||||
|
fieldLabelModifier string = case drop n string of
|
||||||
|
s : tring -> Char.toLower s : tring
|
||||||
|
[] -> []
|
||||||
|
|
||||||
|
data V1beta1CustomResourceDefinition =
|
||||||
|
V1beta1CustomResourceDefinition
|
||||||
|
{ v1beta1CustomResourceDefinitionSpec :: V1beta1CustomResourceDefinitionSpec
|
||||||
|
}
|
||||||
|
deriving (Generic)
|
||||||
|
|
||||||
|
instance FromJSON V1beta1CustomResourceDefinition where
|
||||||
|
parseJSON = stripPrefix 31
|
||||||
|
|
||||||
|
data V1beta1CustomResourceDefinitionSpec =
|
||||||
|
V1beta1CustomResourceDefinitionSpec
|
||||||
|
{ v1beta1CustomResourceDefinitionSpecGroup :: Text
|
||||||
|
, v1beta1CustomResourceDefinitionSpecNames :: V1beta1CustomResourceDefinitionNames
|
||||||
|
, v1beta1CustomResourceDefinitionSpecValidation :: Maybe V1beta1CustomResourceValidation
|
||||||
|
, v1beta1CustomResourceDefinitionSpecVersion :: Maybe Text
|
||||||
|
, v1beta1CustomResourceDefinitionSpecVersions :: Maybe [V1beta1CustomResourceDefinitionVersion]
|
||||||
|
} deriving (Generic)
|
||||||
|
|
||||||
|
instance FromJSON V1beta1CustomResourceDefinitionSpec where
|
||||||
|
parseJSON = stripPrefix 35
|
||||||
|
|
||||||
|
data V1beta1CustomResourceDefinitionNames =
|
||||||
|
V1beta1CustomResourceDefinitionNames
|
||||||
|
{ v1beta1CustomResourceDefinitionNamesKind :: Text
|
||||||
|
} deriving (Generic)
|
||||||
|
|
||||||
|
instance FromJSON V1beta1CustomResourceDefinitionNames where
|
||||||
|
parseJSON = stripPrefix 36
|
||||||
|
|
||||||
|
data V1beta1CustomResourceValidation =
|
||||||
|
V1beta1CustomResourceValidation
|
||||||
|
{ v1beta1CustomResourceValidationOpenApiv3Schema :: Maybe V1beta1JSONSchemaProps
|
||||||
|
} deriving (Generic)
|
||||||
|
|
||||||
|
instance FromJSON V1beta1CustomResourceValidation where
|
||||||
|
parseJSON = stripPrefix 31
|
||||||
|
|
||||||
|
data V1beta1CustomResourceDefinitionVersion =
|
||||||
|
V1betaV1beta1CustomResourceDefinitionVersion
|
||||||
|
{ v1beta1CustomResourceDefinitionVersionName :: Text
|
||||||
|
} deriving (Generic)
|
||||||
|
|
||||||
|
instance FromJSON V1beta1CustomResourceDefinitionVersion where
|
||||||
|
parseJSON = stripPrefix 38
|
||||||
|
|
||||||
|
data V1beta1JSONSchemaProps =
|
||||||
|
V1beta1JSONSchemaProps
|
||||||
|
{ v1beta1JSONSchemaPropsRef :: Maybe Text
|
||||||
|
, v1beta1JSONSchemaPropsDescription :: Maybe Text
|
||||||
|
, v1beta1JSONSchemaPropsFormat :: Maybe Text
|
||||||
|
, v1beta1JSONSchemaPropsItems :: Maybe Value
|
||||||
|
, v1beta1JSONSchemaPropsProperties :: Maybe (Data.Map.Map String V1beta1JSONSchemaProps)
|
||||||
|
, v1beta1JSONSchemaPropsRequired :: Maybe [Text]
|
||||||
|
, v1beta1JSONSchemaPropsType :: Maybe Text
|
||||||
|
} deriving (Generic)
|
||||||
|
|
||||||
|
instance FromJSON V1beta1JSONSchemaProps where
|
||||||
|
parseJSON = stripPrefix 22
|
||||||
|
|
||||||
|
mkV1beta1JSONSchemaProps :: V1beta1JSONSchemaProps
|
||||||
|
mkV1beta1JSONSchemaProps =
|
||||||
|
V1beta1JSONSchemaProps
|
||||||
|
{ v1beta1JSONSchemaPropsRef = Nothing
|
||||||
|
, v1beta1JSONSchemaPropsDescription = Nothing
|
||||||
|
, v1beta1JSONSchemaPropsFormat = Nothing
|
||||||
|
, v1beta1JSONSchemaPropsItems = Nothing
|
||||||
|
, v1beta1JSONSchemaPropsProperties = Nothing
|
||||||
|
, v1beta1JSONSchemaPropsRequired = Nothing
|
||||||
|
, v1beta1JSONSchemaPropsType = Nothing
|
||||||
|
}
|
||||||
|
|
||||||
toDefinition :: V1beta1CustomResourceDefinition -> Maybe (ModelName, Definition)
|
toDefinition :: V1beta1CustomResourceDefinition -> Maybe (ModelName, Definition)
|
||||||
toDefinition crd =
|
toDefinition crd =
|
||||||
fmap (\d -> (modelName, d)) definition
|
fmap (\d -> (modelName, d)) definition
|
||||||
@ -347,4 +429,4 @@ toDefinition crd =
|
|||||||
}
|
}
|
||||||
toProperties :: Data.Map.Map String V1beta1JSONSchemaProps -> Data.Map.Map ModelName Definition
|
toProperties :: Data.Map.Map String V1beta1JSONSchemaProps -> Data.Map.Map ModelName Definition
|
||||||
toProperties props =
|
toProperties props =
|
||||||
(Data.Map.fromList . fmap (\(k, p) -> ((ModelName . Text.pack) k, propsToDefinition p Nothing)) . Data.Map.toList) props
|
(Data.Map.fromList . fmap (\(k, p) -> ((ModelName . Text.pack) k, propsToDefinition p Nothing)) . Data.Map.toList) props
|
||||||
|
Loading…
Reference in New Issue
Block a user