{-# 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.CreateIPSet
-- 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.
--
-- Creates an IPSet, which you use to specify which web requests that you
-- want to allow or block based on the IP addresses that the requests
-- originate from. For example, if you\'re receiving a lot of requests from
-- one or more individual IP addresses or one or more ranges of IP
-- addresses and you want to block the requests, you can create an @IPSet@
-- that contains those IP addresses and then configure AWS WAF to block the
-- requests.
--
-- To create and configure an @IPSet@, perform the following steps:
--
-- 1.  Use GetChangeToken to get the change token that you provide in the
--     @ChangeToken@ parameter of a @CreateIPSet@ request.
--
-- 2.  Submit a @CreateIPSet@ request.
--
-- 3.  Use @GetChangeToken@ to get the change token that you provide in the
--     @ChangeToken@ parameter of an UpdateIPSet request.
--
-- 4.  Submit an @UpdateIPSet@ request to specify the IP addresses that you
--     want AWS WAF to watch for.
--
-- For more information about how to use the AWS WAF API to allow or block
-- HTTP requests, see the
-- <https://docs.aws.amazon.com/waf/latest/developerguide/ AWS WAF Developer Guide>.
module Amazonka.WAFRegional.CreateIPSet
  ( -- * Creating a Request
    CreateIPSet (..),
    newCreateIPSet,

    -- * Request Lenses
    createIPSet_name,
    createIPSet_changeToken,

    -- * Destructuring the Response
    CreateIPSetResponse (..),
    newCreateIPSetResponse,

    -- * Response Lenses
    createIPSetResponse_changeToken,
    createIPSetResponse_iPSet,
    createIPSetResponse_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:/ 'newCreateIPSet' smart constructor.
data CreateIPSet = CreateIPSet'
  { -- | A friendly name or description of the IPSet. You can\'t change @Name@
    -- after you create the @IPSet@.
    CreateIPSet -> Text
name :: Prelude.Text,
    -- | The value returned by the most recent call to GetChangeToken.
    CreateIPSet -> Text
changeToken :: Prelude.Text
  }
  deriving (CreateIPSet -> CreateIPSet -> Bool
(CreateIPSet -> CreateIPSet -> Bool)
-> (CreateIPSet -> CreateIPSet -> Bool) -> Eq CreateIPSet
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateIPSet -> CreateIPSet -> Bool
$c/= :: CreateIPSet -> CreateIPSet -> Bool
== :: CreateIPSet -> CreateIPSet -> Bool
$c== :: CreateIPSet -> CreateIPSet -> Bool
Prelude.Eq, ReadPrec [CreateIPSet]
ReadPrec CreateIPSet
Int -> ReadS CreateIPSet
ReadS [CreateIPSet]
(Int -> ReadS CreateIPSet)
-> ReadS [CreateIPSet]
-> ReadPrec CreateIPSet
-> ReadPrec [CreateIPSet]
-> Read CreateIPSet
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateIPSet]
$creadListPrec :: ReadPrec [CreateIPSet]
readPrec :: ReadPrec CreateIPSet
$creadPrec :: ReadPrec CreateIPSet
readList :: ReadS [CreateIPSet]
$creadList :: ReadS [CreateIPSet]
readsPrec :: Int -> ReadS CreateIPSet
$creadsPrec :: Int -> ReadS CreateIPSet
Prelude.Read, Int -> CreateIPSet -> ShowS
[CreateIPSet] -> ShowS
CreateIPSet -> String
(Int -> CreateIPSet -> ShowS)
-> (CreateIPSet -> String)
-> ([CreateIPSet] -> ShowS)
-> Show CreateIPSet
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateIPSet] -> ShowS
$cshowList :: [CreateIPSet] -> ShowS
show :: CreateIPSet -> String
$cshow :: CreateIPSet -> String
showsPrec :: Int -> CreateIPSet -> ShowS
$cshowsPrec :: Int -> CreateIPSet -> ShowS
Prelude.Show, (forall x. CreateIPSet -> Rep CreateIPSet x)
-> (forall x. Rep CreateIPSet x -> CreateIPSet)
-> Generic CreateIPSet
forall x. Rep CreateIPSet x -> CreateIPSet
forall x. CreateIPSet -> Rep CreateIPSet x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateIPSet x -> CreateIPSet
$cfrom :: forall x. CreateIPSet -> Rep CreateIPSet x
Prelude.Generic)

-- |
-- Create a value of 'CreateIPSet' 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', 'createIPSet_name' - A friendly name or description of the IPSet. You can\'t change @Name@
-- after you create the @IPSet@.
--
-- 'changeToken', 'createIPSet_changeToken' - The value returned by the most recent call to GetChangeToken.
newCreateIPSet ::
  -- | 'name'
  Prelude.Text ->
  -- | 'changeToken'
  Prelude.Text ->
  CreateIPSet
newCreateIPSet :: Text -> Text -> CreateIPSet
newCreateIPSet Text
pName_ Text
pChangeToken_ =
  CreateIPSet' :: Text -> Text -> CreateIPSet
CreateIPSet'
    { $sel:name:CreateIPSet' :: Text
name = Text
pName_,
      $sel:changeToken:CreateIPSet' :: Text
changeToken = Text
pChangeToken_
    }

-- | A friendly name or description of the IPSet. You can\'t change @Name@
-- after you create the @IPSet@.
createIPSet_name :: Lens.Lens' CreateIPSet Prelude.Text
createIPSet_name :: (Text -> f Text) -> CreateIPSet -> f CreateIPSet
createIPSet_name = (CreateIPSet -> Text)
-> (CreateIPSet -> Text -> CreateIPSet)
-> Lens CreateIPSet CreateIPSet Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateIPSet' {Text
name :: Text
$sel:name:CreateIPSet' :: CreateIPSet -> Text
name} -> Text
name) (\s :: CreateIPSet
s@CreateIPSet' {} Text
a -> CreateIPSet
s {$sel:name:CreateIPSet' :: Text
name = Text
a} :: CreateIPSet)

-- | The value returned by the most recent call to GetChangeToken.
createIPSet_changeToken :: Lens.Lens' CreateIPSet Prelude.Text
createIPSet_changeToken :: (Text -> f Text) -> CreateIPSet -> f CreateIPSet
createIPSet_changeToken = (CreateIPSet -> Text)
-> (CreateIPSet -> Text -> CreateIPSet)
-> Lens CreateIPSet CreateIPSet Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateIPSet' {Text
changeToken :: Text
$sel:changeToken:CreateIPSet' :: CreateIPSet -> Text
changeToken} -> Text
changeToken) (\s :: CreateIPSet
s@CreateIPSet' {} Text
a -> CreateIPSet
s {$sel:changeToken:CreateIPSet' :: Text
changeToken = Text
a} :: CreateIPSet)

instance Core.AWSRequest CreateIPSet where
  type AWSResponse CreateIPSet = CreateIPSetResponse
  request :: CreateIPSet -> Request CreateIPSet
request = Service -> CreateIPSet -> Request CreateIPSet
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateIPSet
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateIPSet)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse CreateIPSet))
-> Logger
-> Service
-> Proxy CreateIPSet
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateIPSet)))
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 Text -> Maybe IPSet -> Int -> CreateIPSetResponse
CreateIPSetResponse'
            (Maybe Text -> Maybe IPSet -> Int -> CreateIPSetResponse)
-> Either String (Maybe Text)
-> Either String (Maybe IPSet -> Int -> CreateIPSetResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"ChangeToken")
            Either String (Maybe IPSet -> Int -> CreateIPSetResponse)
-> Either String (Maybe IPSet)
-> Either String (Int -> CreateIPSetResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Maybe IPSet)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"IPSet")
            Either String (Int -> CreateIPSetResponse)
-> Either String Int -> Either String CreateIPSetResponse
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 CreateIPSet

instance Prelude.NFData CreateIPSet

instance Core.ToHeaders CreateIPSet where
  toHeaders :: CreateIPSet -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreateIPSet -> 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.CreateIPSet" ::
                          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 CreateIPSet where
  toJSON :: CreateIPSet -> Value
toJSON CreateIPSet' {Text
changeToken :: Text
name :: Text
$sel:changeToken:CreateIPSet' :: CreateIPSet -> Text
$sel:name:CreateIPSet' :: CreateIPSet -> 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
"Name" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
name),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"ChangeToken" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
changeToken)
          ]
      )

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

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

-- | /See:/ 'newCreateIPSetResponse' smart constructor.
data CreateIPSetResponse = CreateIPSetResponse'
  { -- | The @ChangeToken@ that you used to submit the @CreateIPSet@ request. You
    -- can also use this value to query the status of the request. For more
    -- information, see GetChangeTokenStatus.
    CreateIPSetResponse -> Maybe Text
changeToken :: Prelude.Maybe Prelude.Text,
    -- | The IPSet returned in the @CreateIPSet@ response.
    CreateIPSetResponse -> Maybe IPSet
iPSet :: Prelude.Maybe IPSet,
    -- | The response's http status code.
    CreateIPSetResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CreateIPSetResponse -> CreateIPSetResponse -> Bool
(CreateIPSetResponse -> CreateIPSetResponse -> Bool)
-> (CreateIPSetResponse -> CreateIPSetResponse -> Bool)
-> Eq CreateIPSetResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateIPSetResponse -> CreateIPSetResponse -> Bool
$c/= :: CreateIPSetResponse -> CreateIPSetResponse -> Bool
== :: CreateIPSetResponse -> CreateIPSetResponse -> Bool
$c== :: CreateIPSetResponse -> CreateIPSetResponse -> Bool
Prelude.Eq, ReadPrec [CreateIPSetResponse]
ReadPrec CreateIPSetResponse
Int -> ReadS CreateIPSetResponse
ReadS [CreateIPSetResponse]
(Int -> ReadS CreateIPSetResponse)
-> ReadS [CreateIPSetResponse]
-> ReadPrec CreateIPSetResponse
-> ReadPrec [CreateIPSetResponse]
-> Read CreateIPSetResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateIPSetResponse]
$creadListPrec :: ReadPrec [CreateIPSetResponse]
readPrec :: ReadPrec CreateIPSetResponse
$creadPrec :: ReadPrec CreateIPSetResponse
readList :: ReadS [CreateIPSetResponse]
$creadList :: ReadS [CreateIPSetResponse]
readsPrec :: Int -> ReadS CreateIPSetResponse
$creadsPrec :: Int -> ReadS CreateIPSetResponse
Prelude.Read, Int -> CreateIPSetResponse -> ShowS
[CreateIPSetResponse] -> ShowS
CreateIPSetResponse -> String
(Int -> CreateIPSetResponse -> ShowS)
-> (CreateIPSetResponse -> String)
-> ([CreateIPSetResponse] -> ShowS)
-> Show CreateIPSetResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateIPSetResponse] -> ShowS
$cshowList :: [CreateIPSetResponse] -> ShowS
show :: CreateIPSetResponse -> String
$cshow :: CreateIPSetResponse -> String
showsPrec :: Int -> CreateIPSetResponse -> ShowS
$cshowsPrec :: Int -> CreateIPSetResponse -> ShowS
Prelude.Show, (forall x. CreateIPSetResponse -> Rep CreateIPSetResponse x)
-> (forall x. Rep CreateIPSetResponse x -> CreateIPSetResponse)
-> Generic CreateIPSetResponse
forall x. Rep CreateIPSetResponse x -> CreateIPSetResponse
forall x. CreateIPSetResponse -> Rep CreateIPSetResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateIPSetResponse x -> CreateIPSetResponse
$cfrom :: forall x. CreateIPSetResponse -> Rep CreateIPSetResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreateIPSetResponse' 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:
--
-- 'changeToken', 'createIPSetResponse_changeToken' - The @ChangeToken@ that you used to submit the @CreateIPSet@ request. You
-- can also use this value to query the status of the request. For more
-- information, see GetChangeTokenStatus.
--
-- 'iPSet', 'createIPSetResponse_iPSet' - The IPSet returned in the @CreateIPSet@ response.
--
-- 'httpStatus', 'createIPSetResponse_httpStatus' - The response's http status code.
newCreateIPSetResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateIPSetResponse
newCreateIPSetResponse :: Int -> CreateIPSetResponse
newCreateIPSetResponse Int
pHttpStatus_ =
  CreateIPSetResponse' :: Maybe Text -> Maybe IPSet -> Int -> CreateIPSetResponse
CreateIPSetResponse'
    { $sel:changeToken:CreateIPSetResponse' :: Maybe Text
changeToken = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:iPSet:CreateIPSetResponse' :: Maybe IPSet
iPSet = Maybe IPSet
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreateIPSetResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The @ChangeToken@ that you used to submit the @CreateIPSet@ request. You
-- can also use this value to query the status of the request. For more
-- information, see GetChangeTokenStatus.
createIPSetResponse_changeToken :: Lens.Lens' CreateIPSetResponse (Prelude.Maybe Prelude.Text)
createIPSetResponse_changeToken :: (Maybe Text -> f (Maybe Text))
-> CreateIPSetResponse -> f CreateIPSetResponse
createIPSetResponse_changeToken = (CreateIPSetResponse -> Maybe Text)
-> (CreateIPSetResponse -> Maybe Text -> CreateIPSetResponse)
-> Lens
     CreateIPSetResponse CreateIPSetResponse (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateIPSetResponse' {Maybe Text
changeToken :: Maybe Text
$sel:changeToken:CreateIPSetResponse' :: CreateIPSetResponse -> Maybe Text
changeToken} -> Maybe Text
changeToken) (\s :: CreateIPSetResponse
s@CreateIPSetResponse' {} Maybe Text
a -> CreateIPSetResponse
s {$sel:changeToken:CreateIPSetResponse' :: Maybe Text
changeToken = Maybe Text
a} :: CreateIPSetResponse)

-- | The IPSet returned in the @CreateIPSet@ response.
createIPSetResponse_iPSet :: Lens.Lens' CreateIPSetResponse (Prelude.Maybe IPSet)
createIPSetResponse_iPSet :: (Maybe IPSet -> f (Maybe IPSet))
-> CreateIPSetResponse -> f CreateIPSetResponse
createIPSetResponse_iPSet = (CreateIPSetResponse -> Maybe IPSet)
-> (CreateIPSetResponse -> Maybe IPSet -> CreateIPSetResponse)
-> Lens
     CreateIPSetResponse CreateIPSetResponse (Maybe IPSet) (Maybe IPSet)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateIPSetResponse' {Maybe IPSet
iPSet :: Maybe IPSet
$sel:iPSet:CreateIPSetResponse' :: CreateIPSetResponse -> Maybe IPSet
iPSet} -> Maybe IPSet
iPSet) (\s :: CreateIPSetResponse
s@CreateIPSetResponse' {} Maybe IPSet
a -> CreateIPSetResponse
s {$sel:iPSet:CreateIPSetResponse' :: Maybe IPSet
iPSet = Maybe IPSet
a} :: CreateIPSetResponse)

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

instance Prelude.NFData CreateIPSetResponse