{-# 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.WAF.GetRule
-- 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.
--
-- Returns the Rule that is specified by the @RuleId@ that you included in
-- the @GetRule@ request.
module Amazonka.WAF.GetRule
  ( -- * Creating a Request
    GetRule (..),
    newGetRule,

    -- * Request Lenses
    getRule_ruleId,

    -- * Destructuring the Response
    GetRuleResponse (..),
    newGetRuleResponse,

    -- * Response Lenses
    getRuleResponse_rule,
    getRuleResponse_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.WAF.Types

-- | /See:/ 'newGetRule' smart constructor.
data GetRule = GetRule'
  { -- | The @RuleId@ of the Rule that you want to get. @RuleId@ is returned by
    -- CreateRule and by ListRules.
    GetRule -> Text
ruleId :: Prelude.Text
  }
  deriving (GetRule -> GetRule -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetRule -> GetRule -> Bool
$c/= :: GetRule -> GetRule -> Bool
== :: GetRule -> GetRule -> Bool
$c== :: GetRule -> GetRule -> Bool
Prelude.Eq, ReadPrec [GetRule]
ReadPrec GetRule
Int -> ReadS GetRule
ReadS [GetRule]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetRule]
$creadListPrec :: ReadPrec [GetRule]
readPrec :: ReadPrec GetRule
$creadPrec :: ReadPrec GetRule
readList :: ReadS [GetRule]
$creadList :: ReadS [GetRule]
readsPrec :: Int -> ReadS GetRule
$creadsPrec :: Int -> ReadS GetRule
Prelude.Read, Int -> GetRule -> ShowS
[GetRule] -> ShowS
GetRule -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetRule] -> ShowS
$cshowList :: [GetRule] -> ShowS
show :: GetRule -> String
$cshow :: GetRule -> String
showsPrec :: Int -> GetRule -> ShowS
$cshowsPrec :: Int -> GetRule -> ShowS
Prelude.Show, forall x. Rep GetRule x -> GetRule
forall x. GetRule -> Rep GetRule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetRule x -> GetRule
$cfrom :: forall x. GetRule -> Rep GetRule x
Prelude.Generic)

-- |
-- Create a value of 'GetRule' 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', 'getRule_ruleId' - The @RuleId@ of the Rule that you want to get. @RuleId@ is returned by
-- CreateRule and by ListRules.
newGetRule ::
  -- | 'ruleId'
  Prelude.Text ->
  GetRule
newGetRule :: Text -> GetRule
newGetRule Text
pRuleId_ = GetRule' {$sel:ruleId:GetRule' :: Text
ruleId = Text
pRuleId_}

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

instance Core.AWSRequest GetRule where
  type AWSResponse GetRule = GetRuleResponse
  request :: (Service -> Service) -> GetRule -> Request GetRule
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 GetRule
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetRule)))
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 Rule -> Int -> GetRuleResponse
GetRuleResponse'
            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
"Rule")
            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 GetRule where
  hashWithSalt :: Int -> GetRule -> Int
hashWithSalt Int
_salt GetRule' {Text
ruleId :: Text
$sel:ruleId:GetRule' :: GetRule -> Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
ruleId

instance Prelude.NFData GetRule where
  rnf :: GetRule -> ()
rnf GetRule' {Text
ruleId :: Text
$sel:ruleId:GetRule' :: GetRule -> Text
..} = forall a. NFData a => a -> ()
Prelude.rnf Text
ruleId

instance Data.ToHeaders GetRule where
  toHeaders :: GetRule -> 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_20150824.GetRule" :: 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 GetRule where
  toJSON :: GetRule -> Value
toJSON GetRule' {Text
ruleId :: Text
$sel:ruleId:GetRule' :: GetRule -> 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)]
      )

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

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

-- | /See:/ 'newGetRuleResponse' smart constructor.
data GetRuleResponse = GetRuleResponse'
  { -- | Information about the Rule that you specified in the @GetRule@ request.
    -- For more information, see the following topics:
    --
    -- -   Rule: Contains @MetricName@, @Name@, an array of @Predicate@
    --     objects, and @RuleId@
    --
    -- -   Predicate: Each @Predicate@ object contains @DataId@, @Negated@, and
    --     @Type@
    GetRuleResponse -> Maybe Rule
rule :: Prelude.Maybe Rule,
    -- | The response's http status code.
    GetRuleResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetRuleResponse -> GetRuleResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetRuleResponse -> GetRuleResponse -> Bool
$c/= :: GetRuleResponse -> GetRuleResponse -> Bool
== :: GetRuleResponse -> GetRuleResponse -> Bool
$c== :: GetRuleResponse -> GetRuleResponse -> Bool
Prelude.Eq, ReadPrec [GetRuleResponse]
ReadPrec GetRuleResponse
Int -> ReadS GetRuleResponse
ReadS [GetRuleResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetRuleResponse]
$creadListPrec :: ReadPrec [GetRuleResponse]
readPrec :: ReadPrec GetRuleResponse
$creadPrec :: ReadPrec GetRuleResponse
readList :: ReadS [GetRuleResponse]
$creadList :: ReadS [GetRuleResponse]
readsPrec :: Int -> ReadS GetRuleResponse
$creadsPrec :: Int -> ReadS GetRuleResponse
Prelude.Read, Int -> GetRuleResponse -> ShowS
[GetRuleResponse] -> ShowS
GetRuleResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetRuleResponse] -> ShowS
$cshowList :: [GetRuleResponse] -> ShowS
show :: GetRuleResponse -> String
$cshow :: GetRuleResponse -> String
showsPrec :: Int -> GetRuleResponse -> ShowS
$cshowsPrec :: Int -> GetRuleResponse -> ShowS
Prelude.Show, forall x. Rep GetRuleResponse x -> GetRuleResponse
forall x. GetRuleResponse -> Rep GetRuleResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetRuleResponse x -> GetRuleResponse
$cfrom :: forall x. GetRuleResponse -> Rep GetRuleResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetRuleResponse' 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:
--
-- 'rule', 'getRuleResponse_rule' - Information about the Rule that you specified in the @GetRule@ request.
-- For more information, see the following topics:
--
-- -   Rule: Contains @MetricName@, @Name@, an array of @Predicate@
--     objects, and @RuleId@
--
-- -   Predicate: Each @Predicate@ object contains @DataId@, @Negated@, and
--     @Type@
--
-- 'httpStatus', 'getRuleResponse_httpStatus' - The response's http status code.
newGetRuleResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetRuleResponse
newGetRuleResponse :: Int -> GetRuleResponse
newGetRuleResponse Int
pHttpStatus_ =
  GetRuleResponse'
    { $sel:rule:GetRuleResponse' :: Maybe Rule
rule = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetRuleResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Information about the Rule that you specified in the @GetRule@ request.
-- For more information, see the following topics:
--
-- -   Rule: Contains @MetricName@, @Name@, an array of @Predicate@
--     objects, and @RuleId@
--
-- -   Predicate: Each @Predicate@ object contains @DataId@, @Negated@, and
--     @Type@
getRuleResponse_rule :: Lens.Lens' GetRuleResponse (Prelude.Maybe Rule)
getRuleResponse_rule :: Lens' GetRuleResponse (Maybe Rule)
getRuleResponse_rule = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetRuleResponse' {Maybe Rule
rule :: Maybe Rule
$sel:rule:GetRuleResponse' :: GetRuleResponse -> Maybe Rule
rule} -> Maybe Rule
rule) (\s :: GetRuleResponse
s@GetRuleResponse' {} Maybe Rule
a -> GetRuleResponse
s {$sel:rule:GetRuleResponse' :: Maybe Rule
rule = Maybe Rule
a} :: GetRuleResponse)

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

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