{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.CodePipeline.Types.WebhookDefinition
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.CodePipeline.Types.WebhookDefinition where

import Amazonka.CodePipeline.Types.WebhookAuthConfiguration
import Amazonka.CodePipeline.Types.WebhookAuthenticationType
import Amazonka.CodePipeline.Types.WebhookFilterRule
import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude

-- | Represents information about a webhook and its definition.
--
-- /See:/ 'newWebhookDefinition' smart constructor.
data WebhookDefinition = WebhookDefinition'
  { -- | The name of the webhook.
    WebhookDefinition -> Text
name :: Prelude.Text,
    -- | The name of the pipeline you want to connect to the webhook.
    WebhookDefinition -> Text
targetPipeline :: Prelude.Text,
    -- | The name of the action in a pipeline you want to connect to the webhook.
    -- The action must be from the source (first) stage of the pipeline.
    WebhookDefinition -> Text
targetAction :: Prelude.Text,
    -- | A list of rules applied to the body\/payload sent in the POST request to
    -- a webhook URL. All defined rules must pass for the request to be
    -- accepted and the pipeline started.
    WebhookDefinition -> [WebhookFilterRule]
filters :: [WebhookFilterRule],
    -- | Supported options are GITHUB_HMAC, IP, and UNAUTHENTICATED.
    --
    -- -   For information about the authentication scheme implemented by
    --     GITHUB_HMAC, see
    --     <https://developer.github.com/webhooks/securing/ Securing your webhooks>
    --     on the GitHub Developer website.
    --
    -- -   IP rejects webhooks trigger requests unless they originate from an
    --     IP address in the IP range whitelisted in the authentication
    --     configuration.
    --
    -- -   UNAUTHENTICATED accepts all webhook trigger requests regardless of
    --     origin.
    WebhookDefinition -> WebhookAuthenticationType
authentication :: WebhookAuthenticationType,
    -- | Properties that configure the authentication applied to incoming webhook
    -- trigger requests. The required properties depend on the authentication
    -- type. For GITHUB_HMAC, only the @SecretToken @property must be set. For
    -- IP, only the @AllowedIPRange @property must be set to a valid CIDR
    -- range. For UNAUTHENTICATED, no properties can be set.
    WebhookDefinition -> WebhookAuthConfiguration
authenticationConfiguration :: WebhookAuthConfiguration
  }
  deriving (WebhookDefinition -> WebhookDefinition -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: WebhookDefinition -> WebhookDefinition -> Bool
$c/= :: WebhookDefinition -> WebhookDefinition -> Bool
== :: WebhookDefinition -> WebhookDefinition -> Bool
$c== :: WebhookDefinition -> WebhookDefinition -> Bool
Prelude.Eq, ReadPrec [WebhookDefinition]
ReadPrec WebhookDefinition
Int -> ReadS WebhookDefinition
ReadS [WebhookDefinition]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [WebhookDefinition]
$creadListPrec :: ReadPrec [WebhookDefinition]
readPrec :: ReadPrec WebhookDefinition
$creadPrec :: ReadPrec WebhookDefinition
readList :: ReadS [WebhookDefinition]
$creadList :: ReadS [WebhookDefinition]
readsPrec :: Int -> ReadS WebhookDefinition
$creadsPrec :: Int -> ReadS WebhookDefinition
Prelude.Read, Int -> WebhookDefinition -> ShowS
[WebhookDefinition] -> ShowS
WebhookDefinition -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [WebhookDefinition] -> ShowS
$cshowList :: [WebhookDefinition] -> ShowS
show :: WebhookDefinition -> String
$cshow :: WebhookDefinition -> String
showsPrec :: Int -> WebhookDefinition -> ShowS
$cshowsPrec :: Int -> WebhookDefinition -> ShowS
Prelude.Show, forall x. Rep WebhookDefinition x -> WebhookDefinition
forall x. WebhookDefinition -> Rep WebhookDefinition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep WebhookDefinition x -> WebhookDefinition
$cfrom :: forall x. WebhookDefinition -> Rep WebhookDefinition x
Prelude.Generic)

-- |
-- Create a value of 'WebhookDefinition' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'name', 'webhookDefinition_name' - The name of the webhook.
--
-- 'targetPipeline', 'webhookDefinition_targetPipeline' - The name of the pipeline you want to connect to the webhook.
--
-- 'targetAction', 'webhookDefinition_targetAction' - The name of the action in a pipeline you want to connect to the webhook.
-- The action must be from the source (first) stage of the pipeline.
--
-- 'filters', 'webhookDefinition_filters' - A list of rules applied to the body\/payload sent in the POST request to
-- a webhook URL. All defined rules must pass for the request to be
-- accepted and the pipeline started.
--
-- 'authentication', 'webhookDefinition_authentication' - Supported options are GITHUB_HMAC, IP, and UNAUTHENTICATED.
--
-- -   For information about the authentication scheme implemented by
--     GITHUB_HMAC, see
--     <https://developer.github.com/webhooks/securing/ Securing your webhooks>
--     on the GitHub Developer website.
--
-- -   IP rejects webhooks trigger requests unless they originate from an
--     IP address in the IP range whitelisted in the authentication
--     configuration.
--
-- -   UNAUTHENTICATED accepts all webhook trigger requests regardless of
--     origin.
--
-- 'authenticationConfiguration', 'webhookDefinition_authenticationConfiguration' - Properties that configure the authentication applied to incoming webhook
-- trigger requests. The required properties depend on the authentication
-- type. For GITHUB_HMAC, only the @SecretToken @property must be set. For
-- IP, only the @AllowedIPRange @property must be set to a valid CIDR
-- range. For UNAUTHENTICATED, no properties can be set.
newWebhookDefinition ::
  -- | 'name'
  Prelude.Text ->
  -- | 'targetPipeline'
  Prelude.Text ->
  -- | 'targetAction'
  Prelude.Text ->
  -- | 'authentication'
  WebhookAuthenticationType ->
  -- | 'authenticationConfiguration'
  WebhookAuthConfiguration ->
  WebhookDefinition
newWebhookDefinition :: Text
-> Text
-> Text
-> WebhookAuthenticationType
-> WebhookAuthConfiguration
-> WebhookDefinition
newWebhookDefinition
  Text
pName_
  Text
pTargetPipeline_
  Text
pTargetAction_
  WebhookAuthenticationType
pAuthentication_
  WebhookAuthConfiguration
pAuthenticationConfiguration_ =
    WebhookDefinition'
      { $sel:name:WebhookDefinition' :: Text
name = Text
pName_,
        $sel:targetPipeline:WebhookDefinition' :: Text
targetPipeline = Text
pTargetPipeline_,
        $sel:targetAction:WebhookDefinition' :: Text
targetAction = Text
pTargetAction_,
        $sel:filters:WebhookDefinition' :: [WebhookFilterRule]
filters = forall a. Monoid a => a
Prelude.mempty,
        $sel:authentication:WebhookDefinition' :: WebhookAuthenticationType
authentication = WebhookAuthenticationType
pAuthentication_,
        $sel:authenticationConfiguration:WebhookDefinition' :: WebhookAuthConfiguration
authenticationConfiguration =
          WebhookAuthConfiguration
pAuthenticationConfiguration_
      }

-- | The name of the webhook.
webhookDefinition_name :: Lens.Lens' WebhookDefinition Prelude.Text
webhookDefinition_name :: Lens' WebhookDefinition Text
webhookDefinition_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\WebhookDefinition' {Text
name :: Text
$sel:name:WebhookDefinition' :: WebhookDefinition -> Text
name} -> Text
name) (\s :: WebhookDefinition
s@WebhookDefinition' {} Text
a -> WebhookDefinition
s {$sel:name:WebhookDefinition' :: Text
name = Text
a} :: WebhookDefinition)

-- | The name of the pipeline you want to connect to the webhook.
webhookDefinition_targetPipeline :: Lens.Lens' WebhookDefinition Prelude.Text
webhookDefinition_targetPipeline :: Lens' WebhookDefinition Text
webhookDefinition_targetPipeline = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\WebhookDefinition' {Text
targetPipeline :: Text
$sel:targetPipeline:WebhookDefinition' :: WebhookDefinition -> Text
targetPipeline} -> Text
targetPipeline) (\s :: WebhookDefinition
s@WebhookDefinition' {} Text
a -> WebhookDefinition
s {$sel:targetPipeline:WebhookDefinition' :: Text
targetPipeline = Text
a} :: WebhookDefinition)

-- | The name of the action in a pipeline you want to connect to the webhook.
-- The action must be from the source (first) stage of the pipeline.
webhookDefinition_targetAction :: Lens.Lens' WebhookDefinition Prelude.Text
webhookDefinition_targetAction :: Lens' WebhookDefinition Text
webhookDefinition_targetAction = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\WebhookDefinition' {Text
targetAction :: Text
$sel:targetAction:WebhookDefinition' :: WebhookDefinition -> Text
targetAction} -> Text
targetAction) (\s :: WebhookDefinition
s@WebhookDefinition' {} Text
a -> WebhookDefinition
s {$sel:targetAction:WebhookDefinition' :: Text
targetAction = Text
a} :: WebhookDefinition)

-- | A list of rules applied to the body\/payload sent in the POST request to
-- a webhook URL. All defined rules must pass for the request to be
-- accepted and the pipeline started.
webhookDefinition_filters :: Lens.Lens' WebhookDefinition [WebhookFilterRule]
webhookDefinition_filters :: Lens' WebhookDefinition [WebhookFilterRule]
webhookDefinition_filters = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\WebhookDefinition' {[WebhookFilterRule]
filters :: [WebhookFilterRule]
$sel:filters:WebhookDefinition' :: WebhookDefinition -> [WebhookFilterRule]
filters} -> [WebhookFilterRule]
filters) (\s :: WebhookDefinition
s@WebhookDefinition' {} [WebhookFilterRule]
a -> WebhookDefinition
s {$sel:filters:WebhookDefinition' :: [WebhookFilterRule]
filters = [WebhookFilterRule]
a} :: WebhookDefinition) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Supported options are GITHUB_HMAC, IP, and UNAUTHENTICATED.
--
-- -   For information about the authentication scheme implemented by
--     GITHUB_HMAC, see
--     <https://developer.github.com/webhooks/securing/ Securing your webhooks>
--     on the GitHub Developer website.
--
-- -   IP rejects webhooks trigger requests unless they originate from an
--     IP address in the IP range whitelisted in the authentication
--     configuration.
--
-- -   UNAUTHENTICATED accepts all webhook trigger requests regardless of
--     origin.
webhookDefinition_authentication :: Lens.Lens' WebhookDefinition WebhookAuthenticationType
webhookDefinition_authentication :: Lens' WebhookDefinition WebhookAuthenticationType
webhookDefinition_authentication = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\WebhookDefinition' {WebhookAuthenticationType
authentication :: WebhookAuthenticationType
$sel:authentication:WebhookDefinition' :: WebhookDefinition -> WebhookAuthenticationType
authentication} -> WebhookAuthenticationType
authentication) (\s :: WebhookDefinition
s@WebhookDefinition' {} WebhookAuthenticationType
a -> WebhookDefinition
s {$sel:authentication:WebhookDefinition' :: WebhookAuthenticationType
authentication = WebhookAuthenticationType
a} :: WebhookDefinition)

-- | Properties that configure the authentication applied to incoming webhook
-- trigger requests. The required properties depend on the authentication
-- type. For GITHUB_HMAC, only the @SecretToken @property must be set. For
-- IP, only the @AllowedIPRange @property must be set to a valid CIDR
-- range. For UNAUTHENTICATED, no properties can be set.
webhookDefinition_authenticationConfiguration :: Lens.Lens' WebhookDefinition WebhookAuthConfiguration
webhookDefinition_authenticationConfiguration :: Lens' WebhookDefinition WebhookAuthConfiguration
webhookDefinition_authenticationConfiguration = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\WebhookDefinition' {WebhookAuthConfiguration
authenticationConfiguration :: WebhookAuthConfiguration
$sel:authenticationConfiguration:WebhookDefinition' :: WebhookDefinition -> WebhookAuthConfiguration
authenticationConfiguration} -> WebhookAuthConfiguration
authenticationConfiguration) (\s :: WebhookDefinition
s@WebhookDefinition' {} WebhookAuthConfiguration
a -> WebhookDefinition
s {$sel:authenticationConfiguration:WebhookDefinition' :: WebhookAuthConfiguration
authenticationConfiguration = WebhookAuthConfiguration
a} :: WebhookDefinition)

instance Data.FromJSON WebhookDefinition where
  parseJSON :: Value -> Parser WebhookDefinition
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"WebhookDefinition"
      ( \Object
x ->
          Text
-> Text
-> Text
-> [WebhookFilterRule]
-> WebhookAuthenticationType
-> WebhookAuthConfiguration
-> WebhookDefinition
WebhookDefinition'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"name")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"targetPipeline")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"targetAction")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"filters" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"authentication")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"authenticationConfiguration")
      )

instance Prelude.Hashable WebhookDefinition where
  hashWithSalt :: Int -> WebhookDefinition -> Int
hashWithSalt Int
_salt WebhookDefinition' {[WebhookFilterRule]
Text
WebhookAuthConfiguration
WebhookAuthenticationType
authenticationConfiguration :: WebhookAuthConfiguration
authentication :: WebhookAuthenticationType
filters :: [WebhookFilterRule]
targetAction :: Text
targetPipeline :: Text
name :: Text
$sel:authenticationConfiguration:WebhookDefinition' :: WebhookDefinition -> WebhookAuthConfiguration
$sel:authentication:WebhookDefinition' :: WebhookDefinition -> WebhookAuthenticationType
$sel:filters:WebhookDefinition' :: WebhookDefinition -> [WebhookFilterRule]
$sel:targetAction:WebhookDefinition' :: WebhookDefinition -> Text
$sel:targetPipeline:WebhookDefinition' :: WebhookDefinition -> Text
$sel:name:WebhookDefinition' :: WebhookDefinition -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
targetPipeline
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
targetAction
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [WebhookFilterRule]
filters
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` WebhookAuthenticationType
authentication
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` WebhookAuthConfiguration
authenticationConfiguration

instance Prelude.NFData WebhookDefinition where
  rnf :: WebhookDefinition -> ()
rnf WebhookDefinition' {[WebhookFilterRule]
Text
WebhookAuthConfiguration
WebhookAuthenticationType
authenticationConfiguration :: WebhookAuthConfiguration
authentication :: WebhookAuthenticationType
filters :: [WebhookFilterRule]
targetAction :: Text
targetPipeline :: Text
name :: Text
$sel:authenticationConfiguration:WebhookDefinition' :: WebhookDefinition -> WebhookAuthConfiguration
$sel:authentication:WebhookDefinition' :: WebhookDefinition -> WebhookAuthenticationType
$sel:filters:WebhookDefinition' :: WebhookDefinition -> [WebhookFilterRule]
$sel:targetAction:WebhookDefinition' :: WebhookDefinition -> Text
$sel:targetPipeline:WebhookDefinition' :: WebhookDefinition -> Text
$sel:name:WebhookDefinition' :: WebhookDefinition -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
targetPipeline
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
targetAction
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [WebhookFilterRule]
filters
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf WebhookAuthenticationType
authentication
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf WebhookAuthConfiguration
authenticationConfiguration

instance Data.ToJSON WebhookDefinition where
  toJSON :: WebhookDefinition -> Value
toJSON WebhookDefinition' {[WebhookFilterRule]
Text
WebhookAuthConfiguration
WebhookAuthenticationType
authenticationConfiguration :: WebhookAuthConfiguration
authentication :: WebhookAuthenticationType
filters :: [WebhookFilterRule]
targetAction :: Text
targetPipeline :: Text
name :: Text
$sel:authenticationConfiguration:WebhookDefinition' :: WebhookDefinition -> WebhookAuthConfiguration
$sel:authentication:WebhookDefinition' :: WebhookDefinition -> WebhookAuthenticationType
$sel:filters:WebhookDefinition' :: WebhookDefinition -> [WebhookFilterRule]
$sel:targetAction:WebhookDefinition' :: WebhookDefinition -> Text
$sel:targetPipeline:WebhookDefinition' :: WebhookDefinition -> Text
$sel:name:WebhookDefinition' :: WebhookDefinition -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"name" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
name),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"targetPipeline" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
targetPipeline),
            forall a. a -> Maybe a
Prelude.Just (Key
"targetAction" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
targetAction),
            forall a. a -> Maybe a
Prelude.Just (Key
"filters" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= [WebhookFilterRule]
filters),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"authentication" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= WebhookAuthenticationType
authentication),
            forall a. a -> Maybe a
Prelude.Just
              ( Key
"authenticationConfiguration"
                  forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= WebhookAuthConfiguration
authenticationConfiguration
              )
          ]
      )