{-# 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.GetWebACLForResource
-- 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 Regional__ 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 web ACL for the specified resource, either an application
-- load balancer or Amazon API Gateway stage.
module Amazonka.WAFRegional.GetWebACLForResource
  ( -- * Creating a Request
    GetWebACLForResource (..),
    newGetWebACLForResource,

    -- * Request Lenses
    getWebACLForResource_resourceArn,

    -- * Destructuring the Response
    GetWebACLForResourceResponse (..),
    newGetWebACLForResourceResponse,

    -- * Response Lenses
    getWebACLForResourceResponse_webACLSummary,
    getWebACLForResourceResponse_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:/ 'newGetWebACLForResource' smart constructor.
data GetWebACLForResource = GetWebACLForResource'
  { -- | The ARN (Amazon Resource Name) of the resource for which to get the web
    -- ACL, either an application load balancer or Amazon API Gateway stage.
    --
    -- The ARN should be in one of the following formats:
    --
    -- -   For an Application Load Balancer:
    --     @arn:aws:elasticloadbalancing:@/@region@/@:@/@account-id@/@:loadbalancer\/app\/@/@load-balancer-name@/@\/@/@load-balancer-id@/@ @
    --
    -- -   For an Amazon API Gateway stage:
    --     @arn:aws:apigateway:@/@region@/@::\/restapis\/@/@api-id@/@\/stages\/@/@stage-name@/@ @
    GetWebACLForResource -> Text
resourceArn :: Prelude.Text
  }
  deriving (GetWebACLForResource -> GetWebACLForResource -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetWebACLForResource -> GetWebACLForResource -> Bool
$c/= :: GetWebACLForResource -> GetWebACLForResource -> Bool
== :: GetWebACLForResource -> GetWebACLForResource -> Bool
$c== :: GetWebACLForResource -> GetWebACLForResource -> Bool
Prelude.Eq, ReadPrec [GetWebACLForResource]
ReadPrec GetWebACLForResource
Int -> ReadS GetWebACLForResource
ReadS [GetWebACLForResource]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetWebACLForResource]
$creadListPrec :: ReadPrec [GetWebACLForResource]
readPrec :: ReadPrec GetWebACLForResource
$creadPrec :: ReadPrec GetWebACLForResource
readList :: ReadS [GetWebACLForResource]
$creadList :: ReadS [GetWebACLForResource]
readsPrec :: Int -> ReadS GetWebACLForResource
$creadsPrec :: Int -> ReadS GetWebACLForResource
Prelude.Read, Int -> GetWebACLForResource -> ShowS
[GetWebACLForResource] -> ShowS
GetWebACLForResource -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetWebACLForResource] -> ShowS
$cshowList :: [GetWebACLForResource] -> ShowS
show :: GetWebACLForResource -> String
$cshow :: GetWebACLForResource -> String
showsPrec :: Int -> GetWebACLForResource -> ShowS
$cshowsPrec :: Int -> GetWebACLForResource -> ShowS
Prelude.Show, forall x. Rep GetWebACLForResource x -> GetWebACLForResource
forall x. GetWebACLForResource -> Rep GetWebACLForResource x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetWebACLForResource x -> GetWebACLForResource
$cfrom :: forall x. GetWebACLForResource -> Rep GetWebACLForResource x
Prelude.Generic)

-- |
-- Create a value of 'GetWebACLForResource' 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:
--
-- 'resourceArn', 'getWebACLForResource_resourceArn' - The ARN (Amazon Resource Name) of the resource for which to get the web
-- ACL, either an application load balancer or Amazon API Gateway stage.
--
-- The ARN should be in one of the following formats:
--
-- -   For an Application Load Balancer:
--     @arn:aws:elasticloadbalancing:@/@region@/@:@/@account-id@/@:loadbalancer\/app\/@/@load-balancer-name@/@\/@/@load-balancer-id@/@ @
--
-- -   For an Amazon API Gateway stage:
--     @arn:aws:apigateway:@/@region@/@::\/restapis\/@/@api-id@/@\/stages\/@/@stage-name@/@ @
newGetWebACLForResource ::
  -- | 'resourceArn'
  Prelude.Text ->
  GetWebACLForResource
newGetWebACLForResource :: Text -> GetWebACLForResource
newGetWebACLForResource Text
pResourceArn_ =
  GetWebACLForResource' {$sel:resourceArn:GetWebACLForResource' :: Text
resourceArn = Text
pResourceArn_}

-- | The ARN (Amazon Resource Name) of the resource for which to get the web
-- ACL, either an application load balancer or Amazon API Gateway stage.
--
-- The ARN should be in one of the following formats:
--
-- -   For an Application Load Balancer:
--     @arn:aws:elasticloadbalancing:@/@region@/@:@/@account-id@/@:loadbalancer\/app\/@/@load-balancer-name@/@\/@/@load-balancer-id@/@ @
--
-- -   For an Amazon API Gateway stage:
--     @arn:aws:apigateway:@/@region@/@::\/restapis\/@/@api-id@/@\/stages\/@/@stage-name@/@ @
getWebACLForResource_resourceArn :: Lens.Lens' GetWebACLForResource Prelude.Text
getWebACLForResource_resourceArn :: Lens' GetWebACLForResource Text
getWebACLForResource_resourceArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetWebACLForResource' {Text
resourceArn :: Text
$sel:resourceArn:GetWebACLForResource' :: GetWebACLForResource -> Text
resourceArn} -> Text
resourceArn) (\s :: GetWebACLForResource
s@GetWebACLForResource' {} Text
a -> GetWebACLForResource
s {$sel:resourceArn:GetWebACLForResource' :: Text
resourceArn = Text
a} :: GetWebACLForResource)

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

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

instance Data.ToHeaders GetWebACLForResource where
  toHeaders :: GetWebACLForResource -> 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.GetWebACLForResource" ::
                          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 GetWebACLForResource where
  toJSON :: GetWebACLForResource -> Value
toJSON GetWebACLForResource' {Text
resourceArn :: Text
$sel:resourceArn:GetWebACLForResource' :: GetWebACLForResource -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [forall a. a -> Maybe a
Prelude.Just (Key
"ResourceArn" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
resourceArn)]
      )

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

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

-- | /See:/ 'newGetWebACLForResourceResponse' smart constructor.
data GetWebACLForResourceResponse = GetWebACLForResourceResponse'
  { -- | Information about the web ACL that you specified in the
    -- @GetWebACLForResource@ request. If there is no associated resource, a
    -- null WebACLSummary is returned.
    GetWebACLForResourceResponse -> Maybe WebACLSummary
webACLSummary :: Prelude.Maybe WebACLSummary,
    -- | The response's http status code.
    GetWebACLForResourceResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetWebACLForResourceResponse
-> GetWebACLForResourceResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetWebACLForResourceResponse
-> GetWebACLForResourceResponse -> Bool
$c/= :: GetWebACLForResourceResponse
-> GetWebACLForResourceResponse -> Bool
== :: GetWebACLForResourceResponse
-> GetWebACLForResourceResponse -> Bool
$c== :: GetWebACLForResourceResponse
-> GetWebACLForResourceResponse -> Bool
Prelude.Eq, ReadPrec [GetWebACLForResourceResponse]
ReadPrec GetWebACLForResourceResponse
Int -> ReadS GetWebACLForResourceResponse
ReadS [GetWebACLForResourceResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetWebACLForResourceResponse]
$creadListPrec :: ReadPrec [GetWebACLForResourceResponse]
readPrec :: ReadPrec GetWebACLForResourceResponse
$creadPrec :: ReadPrec GetWebACLForResourceResponse
readList :: ReadS [GetWebACLForResourceResponse]
$creadList :: ReadS [GetWebACLForResourceResponse]
readsPrec :: Int -> ReadS GetWebACLForResourceResponse
$creadsPrec :: Int -> ReadS GetWebACLForResourceResponse
Prelude.Read, Int -> GetWebACLForResourceResponse -> ShowS
[GetWebACLForResourceResponse] -> ShowS
GetWebACLForResourceResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetWebACLForResourceResponse] -> ShowS
$cshowList :: [GetWebACLForResourceResponse] -> ShowS
show :: GetWebACLForResourceResponse -> String
$cshow :: GetWebACLForResourceResponse -> String
showsPrec :: Int -> GetWebACLForResourceResponse -> ShowS
$cshowsPrec :: Int -> GetWebACLForResourceResponse -> ShowS
Prelude.Show, forall x.
Rep GetWebACLForResourceResponse x -> GetWebACLForResourceResponse
forall x.
GetWebACLForResourceResponse -> Rep GetWebACLForResourceResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetWebACLForResourceResponse x -> GetWebACLForResourceResponse
$cfrom :: forall x.
GetWebACLForResourceResponse -> Rep GetWebACLForResourceResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetWebACLForResourceResponse' 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:
--
-- 'webACLSummary', 'getWebACLForResourceResponse_webACLSummary' - Information about the web ACL that you specified in the
-- @GetWebACLForResource@ request. If there is no associated resource, a
-- null WebACLSummary is returned.
--
-- 'httpStatus', 'getWebACLForResourceResponse_httpStatus' - The response's http status code.
newGetWebACLForResourceResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetWebACLForResourceResponse
newGetWebACLForResourceResponse :: Int -> GetWebACLForResourceResponse
newGetWebACLForResourceResponse Int
pHttpStatus_ =
  GetWebACLForResourceResponse'
    { $sel:webACLSummary:GetWebACLForResourceResponse' :: Maybe WebACLSummary
webACLSummary =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetWebACLForResourceResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Information about the web ACL that you specified in the
-- @GetWebACLForResource@ request. If there is no associated resource, a
-- null WebACLSummary is returned.
getWebACLForResourceResponse_webACLSummary :: Lens.Lens' GetWebACLForResourceResponse (Prelude.Maybe WebACLSummary)
getWebACLForResourceResponse_webACLSummary :: Lens' GetWebACLForResourceResponse (Maybe WebACLSummary)
getWebACLForResourceResponse_webACLSummary = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetWebACLForResourceResponse' {Maybe WebACLSummary
webACLSummary :: Maybe WebACLSummary
$sel:webACLSummary:GetWebACLForResourceResponse' :: GetWebACLForResourceResponse -> Maybe WebACLSummary
webACLSummary} -> Maybe WebACLSummary
webACLSummary) (\s :: GetWebACLForResourceResponse
s@GetWebACLForResourceResponse' {} Maybe WebACLSummary
a -> GetWebACLForResourceResponse
s {$sel:webACLSummary:GetWebACLForResourceResponse' :: Maybe WebACLSummary
webACLSummary = Maybe WebACLSummary
a} :: GetWebACLForResourceResponse)

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

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