{-# 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.WebhookAuthConfiguration
-- 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.WebhookAuthConfiguration where

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

-- | The authentication applied to incoming webhook trigger requests.
--
-- /See:/ 'newWebhookAuthConfiguration' smart constructor.
data WebhookAuthConfiguration = WebhookAuthConfiguration'
  { -- | The property used to configure acceptance of webhooks in an IP address
    -- range. For IP, only the @AllowedIPRange@ property must be set. This
    -- property must be set to a valid CIDR range.
    WebhookAuthConfiguration -> Maybe Text
allowedIPRange :: Prelude.Maybe Prelude.Text,
    -- | The property used to configure GitHub authentication. For GITHUB_HMAC,
    -- only the @SecretToken@ property must be set.
    WebhookAuthConfiguration -> Maybe Text
secretToken :: Prelude.Maybe Prelude.Text
  }
  deriving (WebhookAuthConfiguration -> WebhookAuthConfiguration -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: WebhookAuthConfiguration -> WebhookAuthConfiguration -> Bool
$c/= :: WebhookAuthConfiguration -> WebhookAuthConfiguration -> Bool
== :: WebhookAuthConfiguration -> WebhookAuthConfiguration -> Bool
$c== :: WebhookAuthConfiguration -> WebhookAuthConfiguration -> Bool
Prelude.Eq, ReadPrec [WebhookAuthConfiguration]
ReadPrec WebhookAuthConfiguration
Int -> ReadS WebhookAuthConfiguration
ReadS [WebhookAuthConfiguration]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [WebhookAuthConfiguration]
$creadListPrec :: ReadPrec [WebhookAuthConfiguration]
readPrec :: ReadPrec WebhookAuthConfiguration
$creadPrec :: ReadPrec WebhookAuthConfiguration
readList :: ReadS [WebhookAuthConfiguration]
$creadList :: ReadS [WebhookAuthConfiguration]
readsPrec :: Int -> ReadS WebhookAuthConfiguration
$creadsPrec :: Int -> ReadS WebhookAuthConfiguration
Prelude.Read, Int -> WebhookAuthConfiguration -> ShowS
[WebhookAuthConfiguration] -> ShowS
WebhookAuthConfiguration -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [WebhookAuthConfiguration] -> ShowS
$cshowList :: [WebhookAuthConfiguration] -> ShowS
show :: WebhookAuthConfiguration -> String
$cshow :: WebhookAuthConfiguration -> String
showsPrec :: Int -> WebhookAuthConfiguration -> ShowS
$cshowsPrec :: Int -> WebhookAuthConfiguration -> ShowS
Prelude.Show, forall x.
Rep WebhookAuthConfiguration x -> WebhookAuthConfiguration
forall x.
WebhookAuthConfiguration -> Rep WebhookAuthConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep WebhookAuthConfiguration x -> WebhookAuthConfiguration
$cfrom :: forall x.
WebhookAuthConfiguration -> Rep WebhookAuthConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'WebhookAuthConfiguration' 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:
--
-- 'allowedIPRange', 'webhookAuthConfiguration_allowedIPRange' - The property used to configure acceptance of webhooks in an IP address
-- range. For IP, only the @AllowedIPRange@ property must be set. This
-- property must be set to a valid CIDR range.
--
-- 'secretToken', 'webhookAuthConfiguration_secretToken' - The property used to configure GitHub authentication. For GITHUB_HMAC,
-- only the @SecretToken@ property must be set.
newWebhookAuthConfiguration ::
  WebhookAuthConfiguration
newWebhookAuthConfiguration :: WebhookAuthConfiguration
newWebhookAuthConfiguration =
  WebhookAuthConfiguration'
    { $sel:allowedIPRange:WebhookAuthConfiguration' :: Maybe Text
allowedIPRange =
        forall a. Maybe a
Prelude.Nothing,
      $sel:secretToken:WebhookAuthConfiguration' :: Maybe Text
secretToken = forall a. Maybe a
Prelude.Nothing
    }

-- | The property used to configure acceptance of webhooks in an IP address
-- range. For IP, only the @AllowedIPRange@ property must be set. This
-- property must be set to a valid CIDR range.
webhookAuthConfiguration_allowedIPRange :: Lens.Lens' WebhookAuthConfiguration (Prelude.Maybe Prelude.Text)
webhookAuthConfiguration_allowedIPRange :: Lens' WebhookAuthConfiguration (Maybe Text)
webhookAuthConfiguration_allowedIPRange = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\WebhookAuthConfiguration' {Maybe Text
allowedIPRange :: Maybe Text
$sel:allowedIPRange:WebhookAuthConfiguration' :: WebhookAuthConfiguration -> Maybe Text
allowedIPRange} -> Maybe Text
allowedIPRange) (\s :: WebhookAuthConfiguration
s@WebhookAuthConfiguration' {} Maybe Text
a -> WebhookAuthConfiguration
s {$sel:allowedIPRange:WebhookAuthConfiguration' :: Maybe Text
allowedIPRange = Maybe Text
a} :: WebhookAuthConfiguration)

-- | The property used to configure GitHub authentication. For GITHUB_HMAC,
-- only the @SecretToken@ property must be set.
webhookAuthConfiguration_secretToken :: Lens.Lens' WebhookAuthConfiguration (Prelude.Maybe Prelude.Text)
webhookAuthConfiguration_secretToken :: Lens' WebhookAuthConfiguration (Maybe Text)
webhookAuthConfiguration_secretToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\WebhookAuthConfiguration' {Maybe Text
secretToken :: Maybe Text
$sel:secretToken:WebhookAuthConfiguration' :: WebhookAuthConfiguration -> Maybe Text
secretToken} -> Maybe Text
secretToken) (\s :: WebhookAuthConfiguration
s@WebhookAuthConfiguration' {} Maybe Text
a -> WebhookAuthConfiguration
s {$sel:secretToken:WebhookAuthConfiguration' :: Maybe Text
secretToken = Maybe Text
a} :: WebhookAuthConfiguration)

instance Data.FromJSON WebhookAuthConfiguration where
  parseJSON :: Value -> Parser WebhookAuthConfiguration
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"WebhookAuthConfiguration"
      ( \Object
x ->
          Maybe Text -> Maybe Text -> WebhookAuthConfiguration
WebhookAuthConfiguration'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"AllowedIPRange")
            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
"SecretToken")
      )

instance Prelude.Hashable WebhookAuthConfiguration where
  hashWithSalt :: Int -> WebhookAuthConfiguration -> Int
hashWithSalt Int
_salt WebhookAuthConfiguration' {Maybe Text
secretToken :: Maybe Text
allowedIPRange :: Maybe Text
$sel:secretToken:WebhookAuthConfiguration' :: WebhookAuthConfiguration -> Maybe Text
$sel:allowedIPRange:WebhookAuthConfiguration' :: WebhookAuthConfiguration -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
allowedIPRange
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
secretToken

instance Prelude.NFData WebhookAuthConfiguration where
  rnf :: WebhookAuthConfiguration -> ()
rnf WebhookAuthConfiguration' {Maybe Text
secretToken :: Maybe Text
allowedIPRange :: Maybe Text
$sel:secretToken:WebhookAuthConfiguration' :: WebhookAuthConfiguration -> Maybe Text
$sel:allowedIPRange:WebhookAuthConfiguration' :: WebhookAuthConfiguration -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
allowedIPRange
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
secretToken

instance Data.ToJSON WebhookAuthConfiguration where
  toJSON :: WebhookAuthConfiguration -> Value
toJSON WebhookAuthConfiguration' {Maybe Text
secretToken :: Maybe Text
allowedIPRange :: Maybe Text
$sel:secretToken:WebhookAuthConfiguration' :: WebhookAuthConfiguration -> Maybe Text
$sel:allowedIPRange:WebhookAuthConfiguration' :: WebhookAuthConfiguration -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"AllowedIPRange" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
allowedIPRange,
            (Key
"SecretToken" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
secretToken
          ]
      )