{-# LANGUAGE DuplicateRecordFields #-}
module Kubernetes.Webhook
( mutatingWebhook,
validatingWebhook,
Allowed (..),
module Kubernetes.Webhook.Types,
)
where
import Data.Either
import Kubernetes.Webhook.Types
data Allowed = Allowed
mutatingWebhook ::
AdmissionReviewRequest ->
(AdmissionRequest -> Either Status Patch) ->
AdmissionReviewResponse
mutatingWebhook :: AdmissionReviewRequest
-> (AdmissionRequest -> Either Status Patch)
-> AdmissionReviewResponse
mutatingWebhook AdmissionReviewRequest {$sel:request:AdmissionReviewRequest :: AdmissionReviewRequest -> AdmissionRequest
request = AdmissionRequest
req} mutator :: AdmissionRequest -> Either Status Patch
mutator =
AdmissionResponse -> AdmissionReviewResponse
admissionReviewResponse $WAdmissionResponse :: UID
-> Bool
-> Maybe Status
-> Maybe Patch
-> Maybe PatchType
-> Maybe (HashMap Text [Text])
-> AdmissionResponse
AdmissionResponse
{ $sel:uid:AdmissionResponse :: UID
uid = UID
rid,
$sel:allowed:AdmissionResponse :: Bool
allowed = Either Status Patch -> Bool
forall a b. Either a b -> Bool
isRight Either Status Patch
processedRequest,
$sel:patch:AdmissionResponse :: Maybe Patch
patch = (Status -> Maybe Patch)
-> (Patch -> Maybe Patch) -> Either Status Patch -> Maybe Patch
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (Maybe Patch -> Status -> Maybe Patch
forall a b. a -> b -> a
const Maybe Patch
forall a. Maybe a
Nothing) Patch -> Maybe Patch
forall a. a -> Maybe a
Just Either Status Patch
processedRequest,
$sel:status:AdmissionResponse :: Maybe Status
status = (Status -> Maybe Status)
-> (Patch -> Maybe Status) -> Either Status Patch -> Maybe Status
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either Status -> Maybe Status
forall a. a -> Maybe a
Just (Maybe Status -> Patch -> Maybe Status
forall a b. a -> b -> a
const Maybe Status
forall a. Maybe a
Nothing) Either Status Patch
processedRequest,
$sel:patchType:AdmissionResponse :: Maybe PatchType
patchType = PatchType -> Maybe PatchType
forall a. a -> Maybe a
Just PatchType
JSONPatch,
$sel:auditAnnotations:AdmissionResponse :: Maybe (HashMap Text [Text])
auditAnnotations = Maybe (HashMap Text [Text])
forall a. Maybe a
Nothing
}
where
AdmissionRequest {$sel:uid:AdmissionRequest :: AdmissionRequest -> UID
uid = UID
rid} = AdmissionRequest
req
processedRequest :: Either Status Patch
processedRequest = AdmissionRequest -> Either Status Patch
mutator AdmissionRequest
req
validatingWebhook ::
AdmissionReviewRequest ->
(AdmissionRequest -> Either Status Allowed) ->
AdmissionReviewResponse
validatingWebhook :: AdmissionReviewRequest
-> (AdmissionRequest -> Either Status Allowed)
-> AdmissionReviewResponse
validatingWebhook AdmissionReviewRequest {$sel:request:AdmissionReviewRequest :: AdmissionReviewRequest -> AdmissionRequest
request = AdmissionRequest
req} allow :: AdmissionRequest -> Either Status Allowed
allow =
AdmissionResponse -> AdmissionReviewResponse
admissionReviewResponse $WAdmissionResponse :: UID
-> Bool
-> Maybe Status
-> Maybe Patch
-> Maybe PatchType
-> Maybe (HashMap Text [Text])
-> AdmissionResponse
AdmissionResponse
{ $sel:uid:AdmissionResponse :: UID
uid = UID
rid,
$sel:allowed:AdmissionResponse :: Bool
allowed = Either Status Allowed -> Bool
forall a b. Either a b -> Bool
isRight Either Status Allowed
processedRequest,
$sel:patch:AdmissionResponse :: Maybe Patch
patch = Maybe Patch
forall a. Maybe a
Nothing,
$sel:status:AdmissionResponse :: Maybe Status
status = (Status -> Maybe Status)
-> (Allowed -> Maybe Status)
-> Either Status Allowed
-> Maybe Status
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either Status -> Maybe Status
forall a. a -> Maybe a
Just (Maybe Status -> Allowed -> Maybe Status
forall a b. a -> b -> a
const Maybe Status
forall a. Maybe a
Nothing) Either Status Allowed
processedRequest,
$sel:patchType:AdmissionResponse :: Maybe PatchType
patchType = Maybe PatchType
forall a. Maybe a
Nothing,
$sel:auditAnnotations:AdmissionResponse :: Maybe (HashMap Text [Text])
auditAnnotations = Maybe (HashMap Text [Text])
forall a. Maybe a
Nothing
}
where
AdmissionRequest {$sel:uid:AdmissionRequest :: AdmissionRequest -> UID
uid = UID
rid} = AdmissionRequest
req
processedRequest :: Either Status Allowed
processedRequest = AdmissionRequest -> Either Status Allowed
allow AdmissionRequest
req