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

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

-- |
-- Module      : Amazonka.WAFRegional.UpdateRule
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- This is __AWS WAF Classic__ documentation. For more information, see
-- <https://docs.aws.amazon.com/waf/latest/developerguide/classic-waf-chapter.html AWS WAF Classic>
-- in the developer guide.
--
-- __For the latest version of AWS WAF__, use the AWS WAFV2 API and see the
-- <https://docs.aws.amazon.com/waf/latest/developerguide/waf-chapter.html AWS WAF Developer Guide>.
-- With the latest version, AWS WAF has a single set of endpoints for
-- regional and global use.
--
-- Inserts or deletes Predicate objects in a @Rule@. Each @Predicate@
-- object identifies a predicate, such as a ByteMatchSet or an IPSet, that
-- specifies the web requests that you want to allow, block, or count. If
-- you add more than one predicate to a @Rule@, a request must match all of
-- the specifications to be allowed, blocked, or counted. For example,
-- suppose that you add the following to a @Rule@:
--
-- -   A @ByteMatchSet@ that matches the value @BadBot@ in the @User-Agent@
--     header
--
-- -   An @IPSet@ that matches the IP address @192.0.2.44@
--
-- You then add the @Rule@ to a @WebACL@ and specify that you want to block
-- requests that satisfy the @Rule@. For a request to be blocked, the
-- @User-Agent@ header in the request must contain the value @BadBot@ /and/
-- the request must originate from the IP address 192.0.2.44.
--
-- To create and configure a @Rule@, perform the following steps:
--
-- 1.  Create and update the predicates that you want to include in the
--     @Rule@.
--
-- 2.  Create the @Rule@. See CreateRule.
--
-- 3.  Use @GetChangeToken@ to get the change token that you provide in the
--     @ChangeToken@ parameter of an UpdateRule request.
--
-- 4.  Submit an @UpdateRule@ request to add predicates to the @Rule@.
--
-- 5.  Create and update a @WebACL@ that contains the @Rule@. See
--     CreateWebACL.
--
-- If you want to replace one @ByteMatchSet@ or @IPSet@ with another, you
-- delete the existing one and add the new one.
--
-- For more information about how to use the AWS WAF API to allow or block
-- HTTP requests, see the
-- <https://docs.aws.amazon.com/waf/latest/developerguide/ AWS WAF Developer Guide>.
module Amazonka.WAFRegional.UpdateRule
  ( -- * Creating a Request
    UpdateRule (..),
    newUpdateRule,

    -- * Request Lenses
    updateRule_ruleId,
    updateRule_changeToken,
    updateRule_updates,

    -- * Destructuring the Response
    UpdateRuleResponse (..),
    newUpdateRuleResponse,

    -- * Response Lenses
    updateRuleResponse_changeToken,
    updateRuleResponse_httpStatus,
  )
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
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response
import Amazonka.WAFRegional.Types

-- | /See:/ 'newUpdateRule' smart constructor.
data UpdateRule = UpdateRule'
  { -- | The @RuleId@ of the @Rule@ that you want to update. @RuleId@ is returned
    -- by @CreateRule@ and by ListRules.
    UpdateRule -> Text
ruleId :: Prelude.Text,
    -- | The value returned by the most recent call to GetChangeToken.
    UpdateRule -> Text
changeToken :: Prelude.Text,
    -- | An array of @RuleUpdate@ objects that you want to insert into or delete
    -- from a Rule. For more information, see the applicable data types:
    --
    -- -   RuleUpdate: Contains @Action@ and @Predicate@
    --
    -- -   Predicate: Contains @DataId@, @Negated@, and @Type@
    --
    -- -   FieldToMatch: Contains @Data@ and @Type@
    UpdateRule -> [RuleUpdate]
updates :: [RuleUpdate]
  }
  deriving (UpdateRule -> UpdateRule -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateRule -> UpdateRule -> Bool
$c/= :: UpdateRule -> UpdateRule -> Bool
== :: UpdateRule -> UpdateRule -> Bool
$c== :: UpdateRule -> UpdateRule -> Bool
Prelude.Eq, ReadPrec [UpdateRule]
ReadPrec UpdateRule
Int -> ReadS UpdateRule
ReadS [UpdateRule]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateRule]
$creadListPrec :: ReadPrec [UpdateRule]
readPrec :: ReadPrec UpdateRule
$creadPrec :: ReadPrec UpdateRule
readList :: ReadS [UpdateRule]
$creadList :: ReadS [UpdateRule]
readsPrec :: Int -> ReadS UpdateRule
$creadsPrec :: Int -> ReadS UpdateRule
Prelude.Read, Int -> UpdateRule -> ShowS
[UpdateRule] -> ShowS
UpdateRule -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateRule] -> ShowS
$cshowList :: [UpdateRule] -> ShowS
show :: UpdateRule -> String
$cshow :: UpdateRule -> String
showsPrec :: Int -> UpdateRule -> ShowS
$cshowsPrec :: Int -> UpdateRule -> ShowS
Prelude.Show, forall x. Rep UpdateRule x -> UpdateRule
forall x. UpdateRule -> Rep UpdateRule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpdateRule x -> UpdateRule
$cfrom :: forall x. UpdateRule -> Rep UpdateRule x
Prelude.Generic)

-- |
-- Create a value of 'UpdateRule' 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:
--
-- 'ruleId', 'updateRule_ruleId' - The @RuleId@ of the @Rule@ that you want to update. @RuleId@ is returned
-- by @CreateRule@ and by ListRules.
--
-- 'changeToken', 'updateRule_changeToken' - The value returned by the most recent call to GetChangeToken.
--
-- 'updates', 'updateRule_updates' - An array of @RuleUpdate@ objects that you want to insert into or delete
-- from a Rule. For more information, see the applicable data types:
--
-- -   RuleUpdate: Contains @Action@ and @Predicate@
--
-- -   Predicate: Contains @DataId@, @Negated@, and @Type@
--
-- -   FieldToMatch: Contains @Data@ and @Type@
newUpdateRule ::
  -- | 'ruleId'
  Prelude.Text ->
  -- | 'changeToken'
  Prelude.Text ->
  UpdateRule
newUpdateRule :: Text -> Text -> UpdateRule
newUpdateRule Text
pRuleId_ Text
pChangeToken_ =
  UpdateRule'
    { $sel:ruleId:UpdateRule' :: Text
ruleId = Text
pRuleId_,
      $sel:changeToken:UpdateRule' :: Text
changeToken = Text
pChangeToken_,
      $sel:updates:UpdateRule' :: [RuleUpdate]
updates = forall a. Monoid a => a
Prelude.mempty
    }

-- | The @RuleId@ of the @Rule@ that you want to update. @RuleId@ is returned
-- by @CreateRule@ and by ListRules.
updateRule_ruleId :: Lens.Lens' UpdateRule Prelude.Text
updateRule_ruleId :: Lens' UpdateRule Text
updateRule_ruleId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateRule' {Text
ruleId :: Text
$sel:ruleId:UpdateRule' :: UpdateRule -> Text
ruleId} -> Text
ruleId) (\s :: UpdateRule
s@UpdateRule' {} Text
a -> UpdateRule
s {$sel:ruleId:UpdateRule' :: Text
ruleId = Text
a} :: UpdateRule)

-- | The value returned by the most recent call to GetChangeToken.
updateRule_changeToken :: Lens.Lens' UpdateRule Prelude.Text
updateRule_changeToken :: Lens' UpdateRule Text
updateRule_changeToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateRule' {Text
changeToken :: Text
$sel:changeToken:UpdateRule' :: UpdateRule -> Text
changeToken} -> Text
changeToken) (\s :: UpdateRule
s@UpdateRule' {} Text
a -> UpdateRule
s {$sel:changeToken:UpdateRule' :: Text
changeToken = Text
a} :: UpdateRule)

-- | An array of @RuleUpdate@ objects that you want to insert into or delete
-- from a Rule. For more information, see the applicable data types:
--
-- -   RuleUpdate: Contains @Action@ and @Predicate@
--
-- -   Predicate: Contains @DataId@, @Negated@, and @Type@
--
-- -   FieldToMatch: Contains @Data@ and @Type@
updateRule_updates :: Lens.Lens' UpdateRule [RuleUpdate]
updateRule_updates :: Lens' UpdateRule [RuleUpdate]
updateRule_updates = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateRule' {[RuleUpdate]
updates :: [RuleUpdate]
$sel:updates:UpdateRule' :: UpdateRule -> [RuleUpdate]
updates} -> [RuleUpdate]
updates) (\s :: UpdateRule
s@UpdateRule' {} [RuleUpdate]
a -> UpdateRule
s {$sel:updates:UpdateRule' :: [RuleUpdate]
updates = [RuleUpdate]
a} :: UpdateRule) 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

instance Core.AWSRequest UpdateRule where
  type AWSResponse UpdateRule = UpdateRuleResponse
  request :: (Service -> Service) -> UpdateRule -> Request UpdateRule
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy UpdateRule
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse UpdateRule)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Text -> Int -> UpdateRuleResponse
UpdateRuleResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"ChangeToken")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable UpdateRule where
  hashWithSalt :: Int -> UpdateRule -> Int
hashWithSalt Int
_salt UpdateRule' {[RuleUpdate]
Text
updates :: [RuleUpdate]
changeToken :: Text
ruleId :: Text
$sel:updates:UpdateRule' :: UpdateRule -> [RuleUpdate]
$sel:changeToken:UpdateRule' :: UpdateRule -> Text
$sel:ruleId:UpdateRule' :: UpdateRule -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
ruleId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
changeToken
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [RuleUpdate]
updates

instance Prelude.NFData UpdateRule where
  rnf :: UpdateRule -> ()
rnf UpdateRule' {[RuleUpdate]
Text
updates :: [RuleUpdate]
changeToken :: Text
ruleId :: Text
$sel:updates:UpdateRule' :: UpdateRule -> [RuleUpdate]
$sel:changeToken:UpdateRule' :: UpdateRule -> Text
$sel:ruleId:UpdateRule' :: UpdateRule -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
ruleId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
changeToken
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [RuleUpdate]
updates

instance Data.ToHeaders UpdateRule where
  toHeaders :: UpdateRule -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"AWSWAF_Regional_20161128.UpdateRule" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON UpdateRule where
  toJSON :: UpdateRule -> Value
toJSON UpdateRule' {[RuleUpdate]
Text
updates :: [RuleUpdate]
changeToken :: Text
ruleId :: Text
$sel:updates:UpdateRule' :: UpdateRule -> [RuleUpdate]
$sel:changeToken:UpdateRule' :: UpdateRule -> Text
$sel:ruleId:UpdateRule' :: UpdateRule -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"RuleId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
ruleId),
            forall a. a -> Maybe a
Prelude.Just (Key
"ChangeToken" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
changeToken),
            forall a. a -> Maybe a
Prelude.Just (Key
"Updates" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= [RuleUpdate]
updates)
          ]
      )

instance Data.ToPath UpdateRule where
  toPath :: UpdateRule -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Data.ToQuery UpdateRule where
  toQuery :: UpdateRule -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newUpdateRuleResponse' smart constructor.
data UpdateRuleResponse = UpdateRuleResponse'
  { -- | The @ChangeToken@ that you used to submit the @UpdateRule@ request. You
    -- can also use this value to query the status of the request. For more
    -- information, see GetChangeTokenStatus.
    UpdateRuleResponse -> Maybe Text
changeToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    UpdateRuleResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (UpdateRuleResponse -> UpdateRuleResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateRuleResponse -> UpdateRuleResponse -> Bool
$c/= :: UpdateRuleResponse -> UpdateRuleResponse -> Bool
== :: UpdateRuleResponse -> UpdateRuleResponse -> Bool
$c== :: UpdateRuleResponse -> UpdateRuleResponse -> Bool
Prelude.Eq, ReadPrec [UpdateRuleResponse]
ReadPrec UpdateRuleResponse
Int -> ReadS UpdateRuleResponse
ReadS [UpdateRuleResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateRuleResponse]
$creadListPrec :: ReadPrec [UpdateRuleResponse]
readPrec :: ReadPrec UpdateRuleResponse
$creadPrec :: ReadPrec UpdateRuleResponse
readList :: ReadS [UpdateRuleResponse]
$creadList :: ReadS [UpdateRuleResponse]
readsPrec :: Int -> ReadS UpdateRuleResponse
$creadsPrec :: Int -> ReadS UpdateRuleResponse
Prelude.Read, Int -> UpdateRuleResponse -> ShowS
[UpdateRuleResponse] -> ShowS
UpdateRuleResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateRuleResponse] -> ShowS
$cshowList :: [UpdateRuleResponse] -> ShowS
show :: UpdateRuleResponse -> String
$cshow :: UpdateRuleResponse -> String
showsPrec :: Int -> UpdateRuleResponse -> ShowS
$cshowsPrec :: Int -> UpdateRuleResponse -> ShowS
Prelude.Show, forall x. Rep UpdateRuleResponse x -> UpdateRuleResponse
forall x. UpdateRuleResponse -> Rep UpdateRuleResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpdateRuleResponse x -> UpdateRuleResponse
$cfrom :: forall x. UpdateRuleResponse -> Rep UpdateRuleResponse x
Prelude.Generic)

-- |
-- Create a value of 'UpdateRuleResponse' 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:
--
-- 'changeToken', 'updateRuleResponse_changeToken' - The @ChangeToken@ that you used to submit the @UpdateRule@ request. You
-- can also use this value to query the status of the request. For more
-- information, see GetChangeTokenStatus.
--
-- 'httpStatus', 'updateRuleResponse_httpStatus' - The response's http status code.
newUpdateRuleResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  UpdateRuleResponse
newUpdateRuleResponse :: Int -> UpdateRuleResponse
newUpdateRuleResponse Int
pHttpStatus_ =
  UpdateRuleResponse'
    { $sel:changeToken:UpdateRuleResponse' :: Maybe Text
changeToken = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:UpdateRuleResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The @ChangeToken@ that you used to submit the @UpdateRule@ request. You
-- can also use this value to query the status of the request. For more
-- information, see GetChangeTokenStatus.
updateRuleResponse_changeToken :: Lens.Lens' UpdateRuleResponse (Prelude.Maybe Prelude.Text)
updateRuleResponse_changeToken :: Lens' UpdateRuleResponse (Maybe Text)
updateRuleResponse_changeToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateRuleResponse' {Maybe Text
changeToken :: Maybe Text
$sel:changeToken:UpdateRuleResponse' :: UpdateRuleResponse -> Maybe Text
changeToken} -> Maybe Text
changeToken) (\s :: UpdateRuleResponse
s@UpdateRuleResponse' {} Maybe Text
a -> UpdateRuleResponse
s {$sel:changeToken:UpdateRuleResponse' :: Maybe Text
changeToken = Maybe Text
a} :: UpdateRuleResponse)

-- | The response's http status code.
updateRuleResponse_httpStatus :: Lens.Lens' UpdateRuleResponse Prelude.Int
updateRuleResponse_httpStatus :: Lens' UpdateRuleResponse Int
updateRuleResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateRuleResponse' {Int
httpStatus :: Int
$sel:httpStatus:UpdateRuleResponse' :: UpdateRuleResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: UpdateRuleResponse
s@UpdateRuleResponse' {} Int
a -> UpdateRuleResponse
s {$sel:httpStatus:UpdateRuleResponse' :: Int
httpStatus = Int
a} :: UpdateRuleResponse)

instance Prelude.NFData UpdateRuleResponse where
  rnf :: UpdateRuleResponse -> ()
rnf UpdateRuleResponse' {Int
Maybe Text
httpStatus :: Int
changeToken :: Maybe Text
$sel:httpStatus:UpdateRuleResponse' :: UpdateRuleResponse -> Int
$sel:changeToken:UpdateRuleResponse' :: UpdateRuleResponse -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
changeToken
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus