module Hercules.Formats.NixCache where
import Data.Aeson
import Data.Text (Text)
import Hercules.Formats.Common
( noVersion,
withKind,
withVersions,
)
import Prelude
data NixCache = NixCache
{ NixCache -> Text
storeURI :: Text,
NixCache -> [Text]
signingKeys :: [Text],
NixCache -> [Text]
publicKeys :: [Text]
}
instance ToJSON NixCache where
toJSON :: NixCache -> Value
toJSON NixCache
a =
[Pair] -> Value
object
[ Text
"kind" Text -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= Text -> Value
String Text
"NixCache",
Text
"storeURI" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= NixCache -> Text
storeURI NixCache
a,
Text
"signingKeys" Text -> [Text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= NixCache -> [Text]
signingKeys NixCache
a,
Text
"publicKeys" Text -> [Text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= NixCache -> [Text]
publicKeys NixCache
a
]
toEncoding :: NixCache -> Encoding
toEncoding NixCache
a =
Series -> Encoding
pairs
( Text
"kind"
Text -> Value -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= Text -> Value
String Text
"NixCache"
Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
<> Text
"storeURI"
Text -> Text -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= NixCache -> Text
storeURI NixCache
a
Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
<> Text
"signingKeys"
Text -> [Text] -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= NixCache -> [Text]
signingKeys NixCache
a
Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
<> Text
"publicKeys"
Text -> [Text] -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= NixCache -> [Text]
publicKeys NixCache
a
)
instance FromJSON NixCache where
parseJSON :: Value -> Parser NixCache
parseJSON =
Text -> (Object -> Parser NixCache) -> Value -> Parser NixCache
forall a. Text -> (Object -> Parser a) -> Value -> Parser a
withKind Text
"NixCache" ((Object -> Parser NixCache) -> Value -> Parser NixCache)
-> (Object -> Parser NixCache) -> Value -> Parser NixCache
forall a b. (a -> b) -> a -> b
$
[VersionParser NixCache] -> Object -> Parser NixCache
forall a. [VersionParser a] -> Object -> Parser a
withVersions
[ (Object -> Parser NixCache) -> VersionParser NixCache
forall a. (Object -> Parser a) -> VersionParser a
noVersion ((Object -> Parser NixCache) -> VersionParser NixCache)
-> (Object -> Parser NixCache) -> VersionParser NixCache
forall a b. (a -> b) -> a -> b
$ \Object
o ->
Text -> [Text] -> [Text] -> NixCache
NixCache
(Text -> [Text] -> [Text] -> NixCache)
-> Parser Text -> Parser ([Text] -> [Text] -> NixCache)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"storeURI"
Parser ([Text] -> [Text] -> NixCache)
-> Parser [Text] -> Parser ([Text] -> NixCache)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Text -> Parser [Text]
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"signingKeys"
Parser ([Text] -> NixCache) -> Parser [Text] -> Parser NixCache
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Text -> Parser [Text]
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"publicKeys"
]