{-# 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.GetIPSet
-- 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 specified IPSet.
module Amazonka.WAFV2.GetIPSet
  ( -- * Creating a Request
    GetIPSet (..),
    newGetIPSet,

    -- * Request Lenses
    getIPSet_name,
    getIPSet_scope,
    getIPSet_id,

    -- * Destructuring the Response
    GetIPSetResponse (..),
    newGetIPSetResponse,

    -- * Response Lenses
    getIPSetResponse_iPSet,
    getIPSetResponse_lockToken,
    getIPSetResponse_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:/ 'newGetIPSet' smart constructor.
data GetIPSet = GetIPSet'
  { -- | The name of the IP set. You cannot change the name of an @IPSet@ after
    -- you create it.
    GetIPSet -> Text
name :: Prelude.Text,
    -- | Specifies whether this is for an Amazon CloudFront distribution or for a
    -- regional application. A regional application can be an Application Load
    -- Balancer (ALB), an Amazon API Gateway REST API, an AppSync GraphQL API,
    -- or an Amazon Cognito user pool.
    --
    -- To work with CloudFront, you must also specify the Region US East (N.
    -- Virginia) as follows:
    --
    -- -   CLI - Specify the Region when you use the CloudFront scope:
    --     @--scope=CLOUDFRONT --region=us-east-1@.
    --
    -- -   API and SDKs - For all calls, use the Region endpoint us-east-1.
    GetIPSet -> Scope
scope :: Scope,
    -- | A unique identifier for the set. This ID is returned in the responses to
    -- create and list commands. You provide it to operations like update and
    -- delete.
    GetIPSet -> Text
id :: Prelude.Text
  }
  deriving (GetIPSet -> GetIPSet -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetIPSet -> GetIPSet -> Bool
$c/= :: GetIPSet -> GetIPSet -> Bool
== :: GetIPSet -> GetIPSet -> Bool
$c== :: GetIPSet -> GetIPSet -> Bool
Prelude.Eq, ReadPrec [GetIPSet]
ReadPrec GetIPSet
Int -> ReadS GetIPSet
ReadS [GetIPSet]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetIPSet]
$creadListPrec :: ReadPrec [GetIPSet]
readPrec :: ReadPrec GetIPSet
$creadPrec :: ReadPrec GetIPSet
readList :: ReadS [GetIPSet]
$creadList :: ReadS [GetIPSet]
readsPrec :: Int -> ReadS GetIPSet
$creadsPrec :: Int -> ReadS GetIPSet
Prelude.Read, Int -> GetIPSet -> ShowS
[GetIPSet] -> ShowS
GetIPSet -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetIPSet] -> ShowS
$cshowList :: [GetIPSet] -> ShowS
show :: GetIPSet -> String
$cshow :: GetIPSet -> String
showsPrec :: Int -> GetIPSet -> ShowS
$cshowsPrec :: Int -> GetIPSet -> ShowS
Prelude.Show, forall x. Rep GetIPSet x -> GetIPSet
forall x. GetIPSet -> Rep GetIPSet x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetIPSet x -> GetIPSet
$cfrom :: forall x. GetIPSet -> Rep GetIPSet x
Prelude.Generic)

-- |
-- Create a value of 'GetIPSet' 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:
--
-- 'name', 'getIPSet_name' - The name of the IP set. You cannot change the name of an @IPSet@ after
-- you create it.
--
-- 'scope', 'getIPSet_scope' - Specifies whether this is for an Amazon CloudFront distribution or for a
-- regional application. A regional application can be an Application Load
-- Balancer (ALB), an Amazon API Gateway REST API, an AppSync GraphQL API,
-- or an Amazon Cognito user pool.
--
-- To work with CloudFront, you must also specify the Region US East (N.
-- Virginia) as follows:
--
-- -   CLI - Specify the Region when you use the CloudFront scope:
--     @--scope=CLOUDFRONT --region=us-east-1@.
--
-- -   API and SDKs - For all calls, use the Region endpoint us-east-1.
--
-- 'id', 'getIPSet_id' - A unique identifier for the set. This ID is returned in the responses to
-- create and list commands. You provide it to operations like update and
-- delete.
newGetIPSet ::
  -- | 'name'
  Prelude.Text ->
  -- | 'scope'
  Scope ->
  -- | 'id'
  Prelude.Text ->
  GetIPSet
newGetIPSet :: Text -> Scope -> Text -> GetIPSet
newGetIPSet Text
pName_ Scope
pScope_ Text
pId_ =
  GetIPSet'
    { $sel:name:GetIPSet' :: Text
name = Text
pName_,
      $sel:scope:GetIPSet' :: Scope
scope = Scope
pScope_,
      $sel:id:GetIPSet' :: Text
id = Text
pId_
    }

-- | The name of the IP set. You cannot change the name of an @IPSet@ after
-- you create it.
getIPSet_name :: Lens.Lens' GetIPSet Prelude.Text
getIPSet_name :: Lens' GetIPSet Text
getIPSet_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetIPSet' {Text
name :: Text
$sel:name:GetIPSet' :: GetIPSet -> Text
name} -> Text
name) (\s :: GetIPSet
s@GetIPSet' {} Text
a -> GetIPSet
s {$sel:name:GetIPSet' :: Text
name = Text
a} :: GetIPSet)

-- | Specifies whether this is for an Amazon CloudFront distribution or for a
-- regional application. A regional application can be an Application Load
-- Balancer (ALB), an Amazon API Gateway REST API, an AppSync GraphQL API,
-- or an Amazon Cognito user pool.
--
-- To work with CloudFront, you must also specify the Region US East (N.
-- Virginia) as follows:
--
-- -   CLI - Specify the Region when you use the CloudFront scope:
--     @--scope=CLOUDFRONT --region=us-east-1@.
--
-- -   API and SDKs - For all calls, use the Region endpoint us-east-1.
getIPSet_scope :: Lens.Lens' GetIPSet Scope
getIPSet_scope :: Lens' GetIPSet Scope
getIPSet_scope = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetIPSet' {Scope
scope :: Scope
$sel:scope:GetIPSet' :: GetIPSet -> Scope
scope} -> Scope
scope) (\s :: GetIPSet
s@GetIPSet' {} Scope
a -> GetIPSet
s {$sel:scope:GetIPSet' :: Scope
scope = Scope
a} :: GetIPSet)

-- | A unique identifier for the set. This ID is returned in the responses to
-- create and list commands. You provide it to operations like update and
-- delete.
getIPSet_id :: Lens.Lens' GetIPSet Prelude.Text
getIPSet_id :: Lens' GetIPSet Text
getIPSet_id = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetIPSet' {Text
id :: Text
$sel:id:GetIPSet' :: GetIPSet -> Text
id} -> Text
id) (\s :: GetIPSet
s@GetIPSet' {} Text
a -> GetIPSet
s {$sel:id:GetIPSet' :: Text
id = Text
a} :: GetIPSet)

instance Core.AWSRequest GetIPSet where
  type AWSResponse GetIPSet = GetIPSetResponse
  request :: (Service -> Service) -> GetIPSet -> Request GetIPSet
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 GetIPSet
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetIPSet)))
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 IPSet -> Maybe Text -> Int -> GetIPSetResponse
GetIPSetResponse'
            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
"IPSet")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"LockToken")
            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 GetIPSet where
  hashWithSalt :: Int -> GetIPSet -> Int
hashWithSalt Int
_salt GetIPSet' {Text
Scope
id :: Text
scope :: Scope
name :: Text
$sel:id:GetIPSet' :: GetIPSet -> Text
$sel:scope:GetIPSet' :: GetIPSet -> Scope
$sel:name:GetIPSet' :: GetIPSet -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Scope
scope
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
id

instance Prelude.NFData GetIPSet where
  rnf :: GetIPSet -> ()
rnf GetIPSet' {Text
Scope
id :: Text
scope :: Scope
name :: Text
$sel:id:GetIPSet' :: GetIPSet -> Text
$sel:scope:GetIPSet' :: GetIPSet -> Scope
$sel:name:GetIPSet' :: GetIPSet -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Scope
scope
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
id

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

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

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

-- | /See:/ 'newGetIPSetResponse' smart constructor.
data GetIPSetResponse = GetIPSetResponse'
  { GetIPSetResponse -> Maybe IPSet
iPSet :: Prelude.Maybe IPSet,
    -- | A token used for optimistic locking. WAF returns a token to your @get@
    -- and @list@ requests, to mark the state of the entity at the time of the
    -- request. To make changes to the entity associated with the token, you
    -- provide the token to operations like @update@ and @delete@. WAF uses the
    -- token to ensure that no changes have been made to the entity since you
    -- last retrieved it. If a change has been made, the update fails with a
    -- @WAFOptimisticLockException@. If this happens, perform another @get@,
    -- and use the new token returned by that operation.
    GetIPSetResponse -> Maybe Text
lockToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    GetIPSetResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetIPSetResponse -> GetIPSetResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetIPSetResponse -> GetIPSetResponse -> Bool
$c/= :: GetIPSetResponse -> GetIPSetResponse -> Bool
== :: GetIPSetResponse -> GetIPSetResponse -> Bool
$c== :: GetIPSetResponse -> GetIPSetResponse -> Bool
Prelude.Eq, ReadPrec [GetIPSetResponse]
ReadPrec GetIPSetResponse
Int -> ReadS GetIPSetResponse
ReadS [GetIPSetResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetIPSetResponse]
$creadListPrec :: ReadPrec [GetIPSetResponse]
readPrec :: ReadPrec GetIPSetResponse
$creadPrec :: ReadPrec GetIPSetResponse
readList :: ReadS [GetIPSetResponse]
$creadList :: ReadS [GetIPSetResponse]
readsPrec :: Int -> ReadS GetIPSetResponse
$creadsPrec :: Int -> ReadS GetIPSetResponse
Prelude.Read, Int -> GetIPSetResponse -> ShowS
[GetIPSetResponse] -> ShowS
GetIPSetResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetIPSetResponse] -> ShowS
$cshowList :: [GetIPSetResponse] -> ShowS
show :: GetIPSetResponse -> String
$cshow :: GetIPSetResponse -> String
showsPrec :: Int -> GetIPSetResponse -> ShowS
$cshowsPrec :: Int -> GetIPSetResponse -> ShowS
Prelude.Show, forall x. Rep GetIPSetResponse x -> GetIPSetResponse
forall x. GetIPSetResponse -> Rep GetIPSetResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetIPSetResponse x -> GetIPSetResponse
$cfrom :: forall x. GetIPSetResponse -> Rep GetIPSetResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetIPSetResponse' 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:
--
-- 'iPSet', 'getIPSetResponse_iPSet' -
--
-- 'lockToken', 'getIPSetResponse_lockToken' - A token used for optimistic locking. WAF returns a token to your @get@
-- and @list@ requests, to mark the state of the entity at the time of the
-- request. To make changes to the entity associated with the token, you
-- provide the token to operations like @update@ and @delete@. WAF uses the
-- token to ensure that no changes have been made to the entity since you
-- last retrieved it. If a change has been made, the update fails with a
-- @WAFOptimisticLockException@. If this happens, perform another @get@,
-- and use the new token returned by that operation.
--
-- 'httpStatus', 'getIPSetResponse_httpStatus' - The response's http status code.
newGetIPSetResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetIPSetResponse
newGetIPSetResponse :: Int -> GetIPSetResponse
newGetIPSetResponse Int
pHttpStatus_ =
  GetIPSetResponse'
    { $sel:iPSet:GetIPSetResponse' :: Maybe IPSet
iPSet = forall a. Maybe a
Prelude.Nothing,
      $sel:lockToken:GetIPSetResponse' :: Maybe Text
lockToken = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetIPSetResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

getIPSetResponse_iPSet :: Lens.Lens' GetIPSetResponse (Prelude.Maybe IPSet)
getIPSetResponse_iPSet :: Lens' GetIPSetResponse (Maybe IPSet)
getIPSetResponse_iPSet = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetIPSetResponse' {Maybe IPSet
iPSet :: Maybe IPSet
$sel:iPSet:GetIPSetResponse' :: GetIPSetResponse -> Maybe IPSet
iPSet} -> Maybe IPSet
iPSet) (\s :: GetIPSetResponse
s@GetIPSetResponse' {} Maybe IPSet
a -> GetIPSetResponse
s {$sel:iPSet:GetIPSetResponse' :: Maybe IPSet
iPSet = Maybe IPSet
a} :: GetIPSetResponse)

-- | A token used for optimistic locking. WAF returns a token to your @get@
-- and @list@ requests, to mark the state of the entity at the time of the
-- request. To make changes to the entity associated with the token, you
-- provide the token to operations like @update@ and @delete@. WAF uses the
-- token to ensure that no changes have been made to the entity since you
-- last retrieved it. If a change has been made, the update fails with a
-- @WAFOptimisticLockException@. If this happens, perform another @get@,
-- and use the new token returned by that operation.
getIPSetResponse_lockToken :: Lens.Lens' GetIPSetResponse (Prelude.Maybe Prelude.Text)
getIPSetResponse_lockToken :: Lens' GetIPSetResponse (Maybe Text)
getIPSetResponse_lockToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetIPSetResponse' {Maybe Text
lockToken :: Maybe Text
$sel:lockToken:GetIPSetResponse' :: GetIPSetResponse -> Maybe Text
lockToken} -> Maybe Text
lockToken) (\s :: GetIPSetResponse
s@GetIPSetResponse' {} Maybe Text
a -> GetIPSetResponse
s {$sel:lockToken:GetIPSetResponse' :: Maybe Text
lockToken = Maybe Text
a} :: GetIPSetResponse)

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

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