@@ -90,6 +90,9 @@ module Docker.Client.Types (
9090 , defaultConnectConfig
9191 , DisconnectConfig(..)
9292 , defaultDisconnectConfig
93+ , PruneFilter(..)
94+ , defaultPruneFilter
95+ , NetworksDeleted(..)
9396 , EndpointSettings(..)
9497 , defaultEndpointSettings
9598 , IPAMSettings(..)
@@ -118,6 +121,7 @@ module Docker.Client.Types (
118121 , MemoryConstraintSize(..)
119122 ) where
120123
124+import Control.Monad (join)
121125import Data.Aeson (FromJSON, ToJSON, genericParseJSON,
122126 genericToJSON, object, parseJSON, toJSON,
123127 (.!=), (.:), (.:?), (.=))
@@ -125,6 +129,7 @@ import qualified Data.Aeson as JSON
125129import Data.Aeson.Types (defaultOptions, fieldLabelModifier)
126130import Data.Char (isAlphaNum, toUpper)
127131import qualified Data.HashMap.Strict as HM
132+import Data.Maybe (maybeToList, catMaybes)
128133import Data.Monoid ((<>))
129134import Data.Scientific (floatingOrInteger)
130135import Data.Text (Text)
@@ -162,6 +167,7 @@ data Endpoint =
162167 | InspectNetworkEndpoint NetworkID
163168 | ConnectNetworkEndpoint NetworkID ConnectConfig
164169 | DisconnectNetworkEndpoint NetworkID DisconnectConfig
170+ | PruneNetworksEndpoint PruneFilter
165171 deriving (Eq, Show)
166172
167173-- | We should newtype this
@@ -1051,6 +1057,39 @@ instance ToJSON DisconnectConfig where
10511057defaultDisconnectConfig :: Text -> DisconnectConfig
10521058defaultDisconnectConfig = flip DisconnectConfig False
10531059
1060+data PruneFilter = PruneFilter
1061+ { pruneFilterUntil :: Maybe Text
1062+ -- ^ Can be a Unix timestamp, a date-formatted timestamp, or a duration,
1063+ -- such as @10m@ or @1h30m@.
1064+ , pruneFilterIncludeLabels :: [(Text, (Maybe Text))]
1065+ , pruneFilterExcludeLabels :: [(Text, (Maybe Text))]
1066+ } deriving (Eq, Show)
1067+
1068+instance ToJSON PruneFilter where
1069+ toJSON pf = object . catMaybes $
1070+ [ "until" .=? maybeToList (pruneFilterUntil pf)
1071+ , "label" .=? (constructLabel <$> pruneFilterIncludeLabels pf)
1072+ , "label!" .=? (constructLabel <$> pruneFilterExcludeLabels pf)
1073+ ]
1074+ where
1075+ _ .=? [] = Nothing
1076+ k .=? l = Just $ k .= l
1077+
1078+constructLabel :: (Text, Maybe Text) -> Text
1079+constructLabel (k, Just v) = T.concat [k, "=", v]
1080+constructLabel (k, Nothing) = k
1081+
1082+defaultPruneFilter :: PruneFilter
1083+defaultPruneFilter = PruneFilter Nothing [] []
1084+
1085+newtype NetworksDeleted = NetworksDeleted [Text]
1086+ deriving (Eq, Show)
1087+
1088+instance FromJSON NetworksDeleted where
1089+ parseJSON (JSON.Object o) =
1090+ NetworksDeleted . join . maybeToList <$> o .: "NetworksDeleted"
1091+ parseJSON _ = fail $ "NetworksDeleted is not an object"
1092+
10541093data EndpointSettings = EndpointSettings
10551094 { endpointIPAMConfig :: IPAMSettings
10561095 , endpointLinks :: [Text]