{-# 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-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.CodePipeline.Types.WebhookAuthConfiguration where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(WebhookAuthConfiguration -> WebhookAuthConfiguration -> Bool)
-> (WebhookAuthConfiguration -> WebhookAuthConfiguration -> Bool)
-> Eq WebhookAuthConfiguration
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]
(Int -> ReadS WebhookAuthConfiguration)
-> ReadS [WebhookAuthConfiguration]
-> ReadPrec WebhookAuthConfiguration
-> ReadPrec [WebhookAuthConfiguration]
-> Read 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
(Int -> WebhookAuthConfiguration -> ShowS)
-> (WebhookAuthConfiguration -> String)
-> ([WebhookAuthConfiguration] -> ShowS)
-> Show WebhookAuthConfiguration
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.
 WebhookAuthConfiguration -> Rep WebhookAuthConfiguration x)
-> (forall x.
    Rep WebhookAuthConfiguration x -> WebhookAuthConfiguration)
-> Generic WebhookAuthConfiguration
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' :: Maybe Text -> Maybe Text -> WebhookAuthConfiguration
WebhookAuthConfiguration'
    { $sel:allowedIPRange:WebhookAuthConfiguration' :: Maybe Text
allowedIPRange =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:secretToken:WebhookAuthConfiguration' :: Maybe Text
secretToken = Maybe Text
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 :: (Maybe Text -> f (Maybe Text))
-> WebhookAuthConfiguration -> f WebhookAuthConfiguration
webhookAuthConfiguration_allowedIPRange = (WebhookAuthConfiguration -> Maybe Text)
-> (WebhookAuthConfiguration
    -> Maybe Text -> WebhookAuthConfiguration)
-> Lens
     WebhookAuthConfiguration
     WebhookAuthConfiguration
     (Maybe Text)
     (Maybe Text)
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 :: (Maybe Text -> f (Maybe Text))
-> WebhookAuthConfiguration -> f WebhookAuthConfiguration
webhookAuthConfiguration_secretToken = (WebhookAuthConfiguration -> Maybe Text)
-> (WebhookAuthConfiguration
    -> Maybe Text -> WebhookAuthConfiguration)
-> Lens
     WebhookAuthConfiguration
     WebhookAuthConfiguration
     (Maybe Text)
     (Maybe Text)
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 Core.FromJSON WebhookAuthConfiguration where
  parseJSON :: Value -> Parser WebhookAuthConfiguration
parseJSON =
    String
-> (Object -> Parser WebhookAuthConfiguration)
-> Value
-> Parser WebhookAuthConfiguration
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"WebhookAuthConfiguration"
      ( \Object
x ->
          Maybe Text -> Maybe Text -> WebhookAuthConfiguration
WebhookAuthConfiguration'
            (Maybe Text -> Maybe Text -> WebhookAuthConfiguration)
-> Parser (Maybe Text)
-> Parser (Maybe Text -> WebhookAuthConfiguration)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"AllowedIPRange")
            Parser (Maybe Text -> WebhookAuthConfiguration)
-> Parser (Maybe Text) -> Parser WebhookAuthConfiguration
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"SecretToken")
      )

instance Prelude.Hashable WebhookAuthConfiguration

instance Prelude.NFData WebhookAuthConfiguration

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"AllowedIPRange" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
allowedIPRange,
            (Text
"SecretToken" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
secretToken
          ]
      )