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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The event criteria that specify when a webhook notification is sent to
-- your URL.
--
-- /See:/ 'newWebhookFilterRule' smart constructor.
data WebhookFilterRule = WebhookFilterRule'
  { -- | The value selected by the @JsonPath@ expression must match what is
    -- supplied in the @MatchEquals@ field. Otherwise, the request is ignored.
    -- Properties from the target action configuration can be included as
    -- placeholders in this value by surrounding the action configuration key
    -- with curly brackets. For example, if the value supplied here is
    -- \"refs\/heads\/{Branch}\" and the target action has an action
    -- configuration property called \"Branch\" with a value of \"master\", the
    -- @MatchEquals@ value is evaluated as \"refs\/heads\/master\". For a list
    -- of action configuration properties for built-in action types, see
    -- <https://docs.aws.amazon.com/codepipeline/latest/userguide/reference-pipeline-structure.html#action-requirements Pipeline Structure Reference Action Requirements>.
    WebhookFilterRule -> Maybe Text
matchEquals :: Prelude.Maybe Prelude.Text,
    -- | A JsonPath expression that is applied to the body\/payload of the
    -- webhook. The value selected by the JsonPath expression must match the
    -- value specified in the @MatchEquals@ field. Otherwise, the request is
    -- ignored. For more information, see
    -- <https://github.com/json-path/JsonPath Java JsonPath implementation> in
    -- GitHub.
    WebhookFilterRule -> Text
jsonPath :: Prelude.Text
  }
  deriving (WebhookFilterRule -> WebhookFilterRule -> Bool
(WebhookFilterRule -> WebhookFilterRule -> Bool)
-> (WebhookFilterRule -> WebhookFilterRule -> Bool)
-> Eq WebhookFilterRule
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: WebhookFilterRule -> WebhookFilterRule -> Bool
$c/= :: WebhookFilterRule -> WebhookFilterRule -> Bool
== :: WebhookFilterRule -> WebhookFilterRule -> Bool
$c== :: WebhookFilterRule -> WebhookFilterRule -> Bool
Prelude.Eq, ReadPrec [WebhookFilterRule]
ReadPrec WebhookFilterRule
Int -> ReadS WebhookFilterRule
ReadS [WebhookFilterRule]
(Int -> ReadS WebhookFilterRule)
-> ReadS [WebhookFilterRule]
-> ReadPrec WebhookFilterRule
-> ReadPrec [WebhookFilterRule]
-> Read WebhookFilterRule
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [WebhookFilterRule]
$creadListPrec :: ReadPrec [WebhookFilterRule]
readPrec :: ReadPrec WebhookFilterRule
$creadPrec :: ReadPrec WebhookFilterRule
readList :: ReadS [WebhookFilterRule]
$creadList :: ReadS [WebhookFilterRule]
readsPrec :: Int -> ReadS WebhookFilterRule
$creadsPrec :: Int -> ReadS WebhookFilterRule
Prelude.Read, Int -> WebhookFilterRule -> ShowS
[WebhookFilterRule] -> ShowS
WebhookFilterRule -> String
(Int -> WebhookFilterRule -> ShowS)
-> (WebhookFilterRule -> String)
-> ([WebhookFilterRule] -> ShowS)
-> Show WebhookFilterRule
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [WebhookFilterRule] -> ShowS
$cshowList :: [WebhookFilterRule] -> ShowS
show :: WebhookFilterRule -> String
$cshow :: WebhookFilterRule -> String
showsPrec :: Int -> WebhookFilterRule -> ShowS
$cshowsPrec :: Int -> WebhookFilterRule -> ShowS
Prelude.Show, (forall x. WebhookFilterRule -> Rep WebhookFilterRule x)
-> (forall x. Rep WebhookFilterRule x -> WebhookFilterRule)
-> Generic WebhookFilterRule
forall x. Rep WebhookFilterRule x -> WebhookFilterRule
forall x. WebhookFilterRule -> Rep WebhookFilterRule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep WebhookFilterRule x -> WebhookFilterRule
$cfrom :: forall x. WebhookFilterRule -> Rep WebhookFilterRule x
Prelude.Generic)

-- |
-- Create a value of 'WebhookFilterRule' 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:
--
-- 'matchEquals', 'webhookFilterRule_matchEquals' - The value selected by the @JsonPath@ expression must match what is
-- supplied in the @MatchEquals@ field. Otherwise, the request is ignored.
-- Properties from the target action configuration can be included as
-- placeholders in this value by surrounding the action configuration key
-- with curly brackets. For example, if the value supplied here is
-- \"refs\/heads\/{Branch}\" and the target action has an action
-- configuration property called \"Branch\" with a value of \"master\", the
-- @MatchEquals@ value is evaluated as \"refs\/heads\/master\". For a list
-- of action configuration properties for built-in action types, see
-- <https://docs.aws.amazon.com/codepipeline/latest/userguide/reference-pipeline-structure.html#action-requirements Pipeline Structure Reference Action Requirements>.
--
-- 'jsonPath', 'webhookFilterRule_jsonPath' - A JsonPath expression that is applied to the body\/payload of the
-- webhook. The value selected by the JsonPath expression must match the
-- value specified in the @MatchEquals@ field. Otherwise, the request is
-- ignored. For more information, see
-- <https://github.com/json-path/JsonPath Java JsonPath implementation> in
-- GitHub.
newWebhookFilterRule ::
  -- | 'jsonPath'
  Prelude.Text ->
  WebhookFilterRule
newWebhookFilterRule :: Text -> WebhookFilterRule
newWebhookFilterRule Text
pJsonPath_ =
  WebhookFilterRule' :: Maybe Text -> Text -> WebhookFilterRule
WebhookFilterRule'
    { $sel:matchEquals:WebhookFilterRule' :: Maybe Text
matchEquals = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:jsonPath:WebhookFilterRule' :: Text
jsonPath = Text
pJsonPath_
    }

-- | The value selected by the @JsonPath@ expression must match what is
-- supplied in the @MatchEquals@ field. Otherwise, the request is ignored.
-- Properties from the target action configuration can be included as
-- placeholders in this value by surrounding the action configuration key
-- with curly brackets. For example, if the value supplied here is
-- \"refs\/heads\/{Branch}\" and the target action has an action
-- configuration property called \"Branch\" with a value of \"master\", the
-- @MatchEquals@ value is evaluated as \"refs\/heads\/master\". For a list
-- of action configuration properties for built-in action types, see
-- <https://docs.aws.amazon.com/codepipeline/latest/userguide/reference-pipeline-structure.html#action-requirements Pipeline Structure Reference Action Requirements>.
webhookFilterRule_matchEquals :: Lens.Lens' WebhookFilterRule (Prelude.Maybe Prelude.Text)
webhookFilterRule_matchEquals :: (Maybe Text -> f (Maybe Text))
-> WebhookFilterRule -> f WebhookFilterRule
webhookFilterRule_matchEquals = (WebhookFilterRule -> Maybe Text)
-> (WebhookFilterRule -> Maybe Text -> WebhookFilterRule)
-> Lens
     WebhookFilterRule WebhookFilterRule (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\WebhookFilterRule' {Maybe Text
matchEquals :: Maybe Text
$sel:matchEquals:WebhookFilterRule' :: WebhookFilterRule -> Maybe Text
matchEquals} -> Maybe Text
matchEquals) (\s :: WebhookFilterRule
s@WebhookFilterRule' {} Maybe Text
a -> WebhookFilterRule
s {$sel:matchEquals:WebhookFilterRule' :: Maybe Text
matchEquals = Maybe Text
a} :: WebhookFilterRule)

-- | A JsonPath expression that is applied to the body\/payload of the
-- webhook. The value selected by the JsonPath expression must match the
-- value specified in the @MatchEquals@ field. Otherwise, the request is
-- ignored. For more information, see
-- <https://github.com/json-path/JsonPath Java JsonPath implementation> in
-- GitHub.
webhookFilterRule_jsonPath :: Lens.Lens' WebhookFilterRule Prelude.Text
webhookFilterRule_jsonPath :: (Text -> f Text) -> WebhookFilterRule -> f WebhookFilterRule
webhookFilterRule_jsonPath = (WebhookFilterRule -> Text)
-> (WebhookFilterRule -> Text -> WebhookFilterRule)
-> Lens WebhookFilterRule WebhookFilterRule Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\WebhookFilterRule' {Text
jsonPath :: Text
$sel:jsonPath:WebhookFilterRule' :: WebhookFilterRule -> Text
jsonPath} -> Text
jsonPath) (\s :: WebhookFilterRule
s@WebhookFilterRule' {} Text
a -> WebhookFilterRule
s {$sel:jsonPath:WebhookFilterRule' :: Text
jsonPath = Text
a} :: WebhookFilterRule)

instance Core.FromJSON WebhookFilterRule where
  parseJSON :: Value -> Parser WebhookFilterRule
parseJSON =
    String
-> (Object -> Parser WebhookFilterRule)
-> Value
-> Parser WebhookFilterRule
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"WebhookFilterRule"
      ( \Object
x ->
          Maybe Text -> Text -> WebhookFilterRule
WebhookFilterRule'
            (Maybe Text -> Text -> WebhookFilterRule)
-> Parser (Maybe Text) -> Parser (Text -> WebhookFilterRule)
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
"matchEquals")
            Parser (Text -> WebhookFilterRule)
-> Parser Text -> Parser WebhookFilterRule
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"jsonPath")
      )

instance Prelude.Hashable WebhookFilterRule

instance Prelude.NFData WebhookFilterRule

instance Core.ToJSON WebhookFilterRule where
  toJSON :: WebhookFilterRule -> Value
toJSON WebhookFilterRule' {Maybe Text
Text
jsonPath :: Text
matchEquals :: Maybe Text
$sel:jsonPath:WebhookFilterRule' :: WebhookFilterRule -> Text
$sel:matchEquals:WebhookFilterRule' :: WebhookFilterRule -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"matchEquals" 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
matchEquals,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"jsonPath" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
jsonPath)
          ]
      )