{-# 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.WAFV2.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)
--
-- Retrieves the WebACL for the specified resource.
module Amazonka.WAFV2.GetWebACLForResource
  ( -- * Creating a Request
    GetWebACLForResource (..),
    newGetWebACLForResource,

    -- * Request Lenses
    getWebACLForResource_resourceArn,

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

    -- * Response Lenses
    getWebACLForResourceResponse_webACL,
    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.WAFV2.Types

-- | /See:/ 'newGetWebACLForResource' smart constructor.
data GetWebACLForResource = GetWebACLForResource'
  { -- | The Amazon Resource Name (ARN) of the resource whose web ACL you want to
    -- retrieve.
    --
    -- The ARN must 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 REST API:
    --     @arn:aws:apigateway:@/@region@/@::\/restapis\/@/@api-id@/@\/stages\/@/@stage-name@/@ @
    --
    -- -   For an AppSync GraphQL API:
    --     @arn:aws:appsync:@/@region@/@:@/@account-id@/@:apis\/@/@GraphQLApiId@/@ @
    --
    -- -   For an Amazon Cognito user pool:
    --     @arn:aws:cognito-idp:@/@region@/@:@/@account-id@/@:userpool\/@/@user-pool-id@/@ @
    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 Amazon Resource Name (ARN) of the resource whose web ACL you want to
-- retrieve.
--
-- The ARN must 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 REST API:
--     @arn:aws:apigateway:@/@region@/@::\/restapis\/@/@api-id@/@\/stages\/@/@stage-name@/@ @
--
-- -   For an AppSync GraphQL API:
--     @arn:aws:appsync:@/@region@/@:@/@account-id@/@:apis\/@/@GraphQLApiId@/@ @
--
-- -   For an Amazon Cognito user pool:
--     @arn:aws:cognito-idp:@/@region@/@:@/@account-id@/@:userpool\/@/@user-pool-id@/@ @
newGetWebACLForResource ::
  -- | 'resourceArn'
  Prelude.Text ->
  GetWebACLForResource
newGetWebACLForResource :: Text -> GetWebACLForResource
newGetWebACLForResource Text
pResourceArn_ =
  GetWebACLForResource' {$sel:resourceArn:GetWebACLForResource' :: Text
resourceArn = Text
pResourceArn_}

-- | The Amazon Resource Name (ARN) of the resource whose web ACL you want to
-- retrieve.
--
-- The ARN must 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 REST API:
--     @arn:aws:apigateway:@/@region@/@::\/restapis\/@/@api-id@/@\/stages\/@/@stage-name@/@ @
--
-- -   For an AppSync GraphQL API:
--     @arn:aws:appsync:@/@region@/@:@/@account-id@/@:apis\/@/@GraphQLApiId@/@ @
--
-- -   For an Amazon Cognito user pool:
--     @arn:aws:cognito-idp:@/@region@/@:@/@account-id@/@:userpool\/@/@user-pool-id@/@ @
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 WebACL -> 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
"WebACL")
            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_20190729.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'
  { -- | The web ACL that is associated with the resource. If there is no
    -- associated resource, WAF returns a null web ACL.
    GetWebACLForResourceResponse -> Maybe WebACL
webACL :: Prelude.Maybe WebACL,
    -- | 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:
--
-- 'webACL', 'getWebACLForResourceResponse_webACL' - The web ACL that is associated with the resource. If there is no
-- associated resource, WAF returns a null web ACL.
--
-- 'httpStatus', 'getWebACLForResourceResponse_httpStatus' - The response's http status code.
newGetWebACLForResourceResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetWebACLForResourceResponse
newGetWebACLForResourceResponse :: Int -> GetWebACLForResourceResponse
newGetWebACLForResourceResponse Int
pHttpStatus_ =
  GetWebACLForResourceResponse'
    { $sel:webACL:GetWebACLForResourceResponse' :: Maybe WebACL
webACL =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetWebACLForResourceResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The web ACL that is associated with the resource. If there is no
-- associated resource, WAF returns a null web ACL.
getWebACLForResourceResponse_webACL :: Lens.Lens' GetWebACLForResourceResponse (Prelude.Maybe WebACL)
getWebACLForResourceResponse_webACL :: Lens' GetWebACLForResourceResponse (Maybe WebACL)
getWebACLForResourceResponse_webACL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetWebACLForResourceResponse' {Maybe WebACL
webACL :: Maybe WebACL
$sel:webACL:GetWebACLForResourceResponse' :: GetWebACLForResourceResponse -> Maybe WebACL
webACL} -> Maybe WebACL
webACL) (\s :: GetWebACLForResourceResponse
s@GetWebACLForResourceResponse' {} Maybe WebACL
a -> GetWebACLForResourceResponse
s {$sel:webACL:GetWebACLForResourceResponse' :: Maybe WebACL
webACL = Maybe WebACL
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 WebACL
httpStatus :: Int
webACL :: Maybe WebACL
$sel:httpStatus:GetWebACLForResourceResponse' :: GetWebACLForResourceResponse -> Int
$sel:webACL:GetWebACLForResourceResponse' :: GetWebACLForResourceResponse -> Maybe WebACL
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe WebACL
webACL
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus