{-# 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.GetRule
-- 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)
--
-- 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.WAFRegional.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.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response
import Amazonka.WAFRegional.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
(GetRule -> GetRule -> Bool)
-> (GetRule -> GetRule -> Bool) -> Eq GetRule
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]
(Int -> ReadS GetRule)
-> ReadS [GetRule]
-> ReadPrec GetRule
-> ReadPrec [GetRule]
-> Read 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
(Int -> GetRule -> ShowS)
-> (GetRule -> String) -> ([GetRule] -> ShowS) -> Show GetRule
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. GetRule -> Rep GetRule x)
-> (forall x. Rep GetRule x -> GetRule) -> Generic GetRule
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' :: Text -> GetRule
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 :: (Text -> f Text) -> GetRule -> f GetRule
getRule_ruleId = (GetRule -> Text)
-> (GetRule -> Text -> GetRule) -> Lens GetRule GetRule Text Text
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 :: GetRule -> Request GetRule
request = Service -> GetRule -> Request GetRule
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy GetRule
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetRule)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetRule))
-> Logger
-> Service
-> Proxy GetRule
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetRule)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Rule -> Int -> GetRuleResponse
GetRuleResponse'
            (Maybe Rule -> Int -> GetRuleResponse)
-> Either String (Maybe Rule)
-> Either String (Int -> GetRuleResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Rule)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"Rule")
            Either String (Int -> GetRuleResponse)
-> Either String Int -> Either String GetRuleResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable GetRule

instance Prelude.NFData GetRule

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

instance Core.ToJSON GetRule where
  toJSON :: GetRule -> Value
toJSON GetRule' {Text
ruleId :: Text
$sel:ruleId:GetRule' :: GetRule -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"RuleId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
ruleId)]
      )

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

instance Core.ToQuery GetRule where
  toQuery :: GetRule -> QueryString
toQuery = QueryString -> GetRule -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
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
(GetRuleResponse -> GetRuleResponse -> Bool)
-> (GetRuleResponse -> GetRuleResponse -> Bool)
-> Eq GetRuleResponse
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]
(Int -> ReadS GetRuleResponse)
-> ReadS [GetRuleResponse]
-> ReadPrec GetRuleResponse
-> ReadPrec [GetRuleResponse]
-> Read 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
(Int -> GetRuleResponse -> ShowS)
-> (GetRuleResponse -> String)
-> ([GetRuleResponse] -> ShowS)
-> Show GetRuleResponse
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. GetRuleResponse -> Rep GetRuleResponse x)
-> (forall x. Rep GetRuleResponse x -> GetRuleResponse)
-> Generic GetRuleResponse
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' :: Maybe Rule -> Int -> GetRuleResponse
GetRuleResponse'
    { $sel:rule:GetRuleResponse' :: Maybe Rule
rule = Maybe 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 :: (Maybe Rule -> f (Maybe Rule))
-> GetRuleResponse -> f GetRuleResponse
getRuleResponse_rule = (GetRuleResponse -> Maybe Rule)
-> (GetRuleResponse -> Maybe Rule -> GetRuleResponse)
-> Lens GetRuleResponse GetRuleResponse (Maybe Rule) (Maybe 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 :: (Int -> f Int) -> GetRuleResponse -> f GetRuleResponse
getRuleResponse_httpStatus = (GetRuleResponse -> Int)
-> (GetRuleResponse -> Int -> GetRuleResponse)
-> Lens GetRuleResponse GetRuleResponse Int Int
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