{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# 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.Types.IPSet
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.WAFV2.Types.IPSet 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 Amazonka.WAFV2.Types.IPAddressVersion

-- | Contains zero or more IP addresses or blocks of IP addresses specified
-- in Classless Inter-Domain Routing (CIDR) notation. WAF supports all IPv4
-- and IPv6 CIDR ranges except for \/0. For information about CIDR
-- notation, see the Wikipedia entry
-- <https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing Classless Inter-Domain Routing>.
--
-- WAF assigns an ARN to each @IPSet@ that you create. To use an IP set in
-- a rule, you provide the ARN to the Rule statement
-- IPSetReferenceStatement.
--
-- /See:/ 'newIPSet' smart constructor.
data IPSet = IPSet'
  { -- | A description of the IP set that helps with identification.
    IPSet -> Maybe Text
description :: Prelude.Maybe Prelude.Text,
    -- | The name of the IP set. You cannot change the name of an @IPSet@ after
    -- you create it.
    IPSet -> Text
name :: Prelude.Text,
    -- | 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.
    IPSet -> Text
id :: Prelude.Text,
    -- | The Amazon Resource Name (ARN) of the entity.
    IPSet -> Text
arn :: Prelude.Text,
    -- | The version of the IP addresses, either @IPV4@ or @IPV6@.
    IPSet -> IPAddressVersion
iPAddressVersion :: IPAddressVersion,
    -- | Contains an array of strings that specifies zero or more IP addresses or
    -- blocks of IP addresses. All addresses must be specified using Classless
    -- Inter-Domain Routing (CIDR) notation. WAF supports all IPv4 and IPv6
    -- CIDR ranges except for @\/0@.
    --
    -- Example address strings:
    --
    -- -   To configure WAF to allow, block, or count requests that originated
    --     from the IP address 192.0.2.44, specify @192.0.2.44\/32@.
    --
    -- -   To configure WAF to allow, block, or count requests that originated
    --     from IP addresses from 192.0.2.0 to 192.0.2.255, specify
    --     @192.0.2.0\/24@.
    --
    -- -   To configure WAF to allow, block, or count requests that originated
    --     from the IP address 1111:0000:0000:0000:0000:0000:0000:0111, specify
    --     @1111:0000:0000:0000:0000:0000:0000:0111\/128@.
    --
    -- -   To configure WAF to allow, block, or count requests that originated
    --     from IP addresses 1111:0000:0000:0000:0000:0000:0000:0000 to
    --     1111:0000:0000:0000:ffff:ffff:ffff:ffff, specify
    --     @1111:0000:0000:0000:0000:0000:0000:0000\/64@.
    --
    -- For more information about CIDR notation, see the Wikipedia entry
    -- <https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing Classless Inter-Domain Routing>.
    --
    -- Example JSON @Addresses@ specifications:
    --
    -- -   Empty array: @\"Addresses\": []@
    --
    -- -   Array with one address: @\"Addresses\": [\"192.0.2.44\/32\"]@
    --
    -- -   Array with three addresses:
    --     @\"Addresses\": [\"192.0.2.44\/32\", \"192.0.2.0\/24\", \"192.0.0.0\/16\"]@
    --
    -- -   INVALID specification: @\"Addresses\": [\"\"]@ INVALID
    IPSet -> [Text]
addresses :: [Prelude.Text]
  }
  deriving (IPSet -> IPSet -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: IPSet -> IPSet -> Bool
$c/= :: IPSet -> IPSet -> Bool
== :: IPSet -> IPSet -> Bool
$c== :: IPSet -> IPSet -> Bool
Prelude.Eq, ReadPrec [IPSet]
ReadPrec IPSet
Int -> ReadS IPSet
ReadS [IPSet]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [IPSet]
$creadListPrec :: ReadPrec [IPSet]
readPrec :: ReadPrec IPSet
$creadPrec :: ReadPrec IPSet
readList :: ReadS [IPSet]
$creadList :: ReadS [IPSet]
readsPrec :: Int -> ReadS IPSet
$creadsPrec :: Int -> ReadS IPSet
Prelude.Read, Int -> IPSet -> ShowS
[IPSet] -> ShowS
IPSet -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IPSet] -> ShowS
$cshowList :: [IPSet] -> ShowS
show :: IPSet -> String
$cshow :: IPSet -> String
showsPrec :: Int -> IPSet -> ShowS
$cshowsPrec :: Int -> IPSet -> ShowS
Prelude.Show, forall x. Rep IPSet x -> IPSet
forall x. IPSet -> Rep IPSet x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep IPSet x -> IPSet
$cfrom :: forall x. IPSet -> Rep IPSet x
Prelude.Generic)

-- |
-- Create a value of 'IPSet' 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:
--
-- 'description', 'iPSet_description' - A description of the IP set that helps with identification.
--
-- 'name', 'iPSet_name' - The name of the IP set. You cannot change the name of an @IPSet@ after
-- you create it.
--
-- 'id', 'iPSet_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.
--
-- 'arn', 'iPSet_arn' - The Amazon Resource Name (ARN) of the entity.
--
-- 'iPAddressVersion', 'iPSet_iPAddressVersion' - The version of the IP addresses, either @IPV4@ or @IPV6@.
--
-- 'addresses', 'iPSet_addresses' - Contains an array of strings that specifies zero or more IP addresses or
-- blocks of IP addresses. All addresses must be specified using Classless
-- Inter-Domain Routing (CIDR) notation. WAF supports all IPv4 and IPv6
-- CIDR ranges except for @\/0@.
--
-- Example address strings:
--
-- -   To configure WAF to allow, block, or count requests that originated
--     from the IP address 192.0.2.44, specify @192.0.2.44\/32@.
--
-- -   To configure WAF to allow, block, or count requests that originated
--     from IP addresses from 192.0.2.0 to 192.0.2.255, specify
--     @192.0.2.0\/24@.
--
-- -   To configure WAF to allow, block, or count requests that originated
--     from the IP address 1111:0000:0000:0000:0000:0000:0000:0111, specify
--     @1111:0000:0000:0000:0000:0000:0000:0111\/128@.
--
-- -   To configure WAF to allow, block, or count requests that originated
--     from IP addresses 1111:0000:0000:0000:0000:0000:0000:0000 to
--     1111:0000:0000:0000:ffff:ffff:ffff:ffff, specify
--     @1111:0000:0000:0000:0000:0000:0000:0000\/64@.
--
-- For more information about CIDR notation, see the Wikipedia entry
-- <https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing Classless Inter-Domain Routing>.
--
-- Example JSON @Addresses@ specifications:
--
-- -   Empty array: @\"Addresses\": []@
--
-- -   Array with one address: @\"Addresses\": [\"192.0.2.44\/32\"]@
--
-- -   Array with three addresses:
--     @\"Addresses\": [\"192.0.2.44\/32\", \"192.0.2.0\/24\", \"192.0.0.0\/16\"]@
--
-- -   INVALID specification: @\"Addresses\": [\"\"]@ INVALID
newIPSet ::
  -- | 'name'
  Prelude.Text ->
  -- | 'id'
  Prelude.Text ->
  -- | 'arn'
  Prelude.Text ->
  -- | 'iPAddressVersion'
  IPAddressVersion ->
  IPSet
newIPSet :: Text -> Text -> Text -> IPAddressVersion -> IPSet
newIPSet Text
pName_ Text
pId_ Text
pARN_ IPAddressVersion
pIPAddressVersion_ =
  IPSet'
    { $sel:description:IPSet' :: Maybe Text
description = forall a. Maybe a
Prelude.Nothing,
      $sel:name:IPSet' :: Text
name = Text
pName_,
      $sel:id:IPSet' :: Text
id = Text
pId_,
      $sel:arn:IPSet' :: Text
arn = Text
pARN_,
      $sel:iPAddressVersion:IPSet' :: IPAddressVersion
iPAddressVersion = IPAddressVersion
pIPAddressVersion_,
      $sel:addresses:IPSet' :: [Text]
addresses = forall a. Monoid a => a
Prelude.mempty
    }

-- | A description of the IP set that helps with identification.
iPSet_description :: Lens.Lens' IPSet (Prelude.Maybe Prelude.Text)
iPSet_description :: Lens' IPSet (Maybe Text)
iPSet_description = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IPSet' {Maybe Text
description :: Maybe Text
$sel:description:IPSet' :: IPSet -> Maybe Text
description} -> Maybe Text
description) (\s :: IPSet
s@IPSet' {} Maybe Text
a -> IPSet
s {$sel:description:IPSet' :: Maybe Text
description = Maybe Text
a} :: IPSet)

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

-- | 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.
iPSet_id :: Lens.Lens' IPSet Prelude.Text
iPSet_id :: Lens' IPSet Text
iPSet_id = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IPSet' {Text
id :: Text
$sel:id:IPSet' :: IPSet -> Text
id} -> Text
id) (\s :: IPSet
s@IPSet' {} Text
a -> IPSet
s {$sel:id:IPSet' :: Text
id = Text
a} :: IPSet)

-- | The Amazon Resource Name (ARN) of the entity.
iPSet_arn :: Lens.Lens' IPSet Prelude.Text
iPSet_arn :: Lens' IPSet Text
iPSet_arn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IPSet' {Text
arn :: Text
$sel:arn:IPSet' :: IPSet -> Text
arn} -> Text
arn) (\s :: IPSet
s@IPSet' {} Text
a -> IPSet
s {$sel:arn:IPSet' :: Text
arn = Text
a} :: IPSet)

-- | The version of the IP addresses, either @IPV4@ or @IPV6@.
iPSet_iPAddressVersion :: Lens.Lens' IPSet IPAddressVersion
iPSet_iPAddressVersion :: Lens' IPSet IPAddressVersion
iPSet_iPAddressVersion = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IPSet' {IPAddressVersion
iPAddressVersion :: IPAddressVersion
$sel:iPAddressVersion:IPSet' :: IPSet -> IPAddressVersion
iPAddressVersion} -> IPAddressVersion
iPAddressVersion) (\s :: IPSet
s@IPSet' {} IPAddressVersion
a -> IPSet
s {$sel:iPAddressVersion:IPSet' :: IPAddressVersion
iPAddressVersion = IPAddressVersion
a} :: IPSet)

-- | Contains an array of strings that specifies zero or more IP addresses or
-- blocks of IP addresses. All addresses must be specified using Classless
-- Inter-Domain Routing (CIDR) notation. WAF supports all IPv4 and IPv6
-- CIDR ranges except for @\/0@.
--
-- Example address strings:
--
-- -   To configure WAF to allow, block, or count requests that originated
--     from the IP address 192.0.2.44, specify @192.0.2.44\/32@.
--
-- -   To configure WAF to allow, block, or count requests that originated
--     from IP addresses from 192.0.2.0 to 192.0.2.255, specify
--     @192.0.2.0\/24@.
--
-- -   To configure WAF to allow, block, or count requests that originated
--     from the IP address 1111:0000:0000:0000:0000:0000:0000:0111, specify
--     @1111:0000:0000:0000:0000:0000:0000:0111\/128@.
--
-- -   To configure WAF to allow, block, or count requests that originated
--     from IP addresses 1111:0000:0000:0000:0000:0000:0000:0000 to
--     1111:0000:0000:0000:ffff:ffff:ffff:ffff, specify
--     @1111:0000:0000:0000:0000:0000:0000:0000\/64@.
--
-- For more information about CIDR notation, see the Wikipedia entry
-- <https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing Classless Inter-Domain Routing>.
--
-- Example JSON @Addresses@ specifications:
--
-- -   Empty array: @\"Addresses\": []@
--
-- -   Array with one address: @\"Addresses\": [\"192.0.2.44\/32\"]@
--
-- -   Array with three addresses:
--     @\"Addresses\": [\"192.0.2.44\/32\", \"192.0.2.0\/24\", \"192.0.0.0\/16\"]@
--
-- -   INVALID specification: @\"Addresses\": [\"\"]@ INVALID
iPSet_addresses :: Lens.Lens' IPSet [Prelude.Text]
iPSet_addresses :: Lens' IPSet [Text]
iPSet_addresses = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IPSet' {[Text]
addresses :: [Text]
$sel:addresses:IPSet' :: IPSet -> [Text]
addresses} -> [Text]
addresses) (\s :: IPSet
s@IPSet' {} [Text]
a -> IPSet
s {$sel:addresses:IPSet' :: [Text]
addresses = [Text]
a} :: IPSet) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Data.FromJSON IPSet where
  parseJSON :: Value -> Parser IPSet
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"IPSet"
      ( \Object
x ->
          Maybe Text
-> Text -> Text -> Text -> IPAddressVersion -> [Text] -> IPSet
IPSet'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Description")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Name")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Id")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"ARN")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"IPAddressVersion")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Addresses" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable IPSet where
  hashWithSalt :: Int -> IPSet -> Int
hashWithSalt Int
_salt IPSet' {[Text]
Maybe Text
Text
IPAddressVersion
addresses :: [Text]
iPAddressVersion :: IPAddressVersion
arn :: Text
id :: Text
name :: Text
description :: Maybe Text
$sel:addresses:IPSet' :: IPSet -> [Text]
$sel:iPAddressVersion:IPSet' :: IPSet -> IPAddressVersion
$sel:arn:IPSet' :: IPSet -> Text
$sel:id:IPSet' :: IPSet -> Text
$sel:name:IPSet' :: IPSet -> Text
$sel:description:IPSet' :: IPSet -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
description
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
id
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
arn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` IPAddressVersion
iPAddressVersion
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [Text]
addresses

instance Prelude.NFData IPSet where
  rnf :: IPSet -> ()
rnf IPSet' {[Text]
Maybe Text
Text
IPAddressVersion
addresses :: [Text]
iPAddressVersion :: IPAddressVersion
arn :: Text
id :: Text
name :: Text
description :: Maybe Text
$sel:addresses:IPSet' :: IPSet -> [Text]
$sel:iPAddressVersion:IPSet' :: IPSet -> IPAddressVersion
$sel:arn:IPSet' :: IPSet -> Text
$sel:id:IPSet' :: IPSet -> Text
$sel:name:IPSet' :: IPSet -> Text
$sel:description:IPSet' :: IPSet -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
description
      seq :: forall a b. a -> b -> b
`Prelude.seq` 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 Text
id
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
arn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf IPAddressVersion
iPAddressVersion
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [Text]
addresses