{-# 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.WAF.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.WAF.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.WAF.Types.IPSetDescriptor

-- | 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.
--
-- Contains one or more IP addresses or blocks of IP addresses specified in
-- Classless Inter-Domain Routing (CIDR) notation. AWS WAF supports IPv4
-- address ranges: \/8 and any range between \/16 through \/32. AWS WAF
-- supports IPv6 address ranges: \/24, \/32, \/48, \/56, \/64, and \/128.
--
-- To specify an individual IP address, you specify the four-part IP
-- address followed by a @\/32@, for example, 192.0.2.0\/32. To block a
-- range of IP addresses, you can specify \/8 or any range between \/16
-- through \/32 (for IPv4) or \/24, \/32, \/48, \/56, \/64, or \/128 (for
-- IPv6). For more information about CIDR notation, see the Wikipedia entry
-- <https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing Classless Inter-Domain Routing>.
--
-- /See:/ 'newIPSet' smart constructor.
data IPSet = IPSet'
  { -- | A friendly name or description of the IPSet. You can\'t change the name
    -- of an @IPSet@ after you create it.
    IPSet -> Maybe Text
name :: Prelude.Maybe Prelude.Text,
    -- | The @IPSetId@ for an @IPSet@. You use @IPSetId@ to get information about
    -- an @IPSet@ (see GetIPSet), update an @IPSet@ (see UpdateIPSet), insert
    -- an @IPSet@ into a @Rule@ or delete one from a @Rule@ (see UpdateRule),
    -- and delete an @IPSet@ from AWS WAF (see DeleteIPSet).
    --
    -- @IPSetId@ is returned by CreateIPSet and by ListIPSets.
    IPSet -> Text
iPSetId :: Prelude.Text,
    -- | The IP address type (@IPV4@ or @IPV6@) and the IP address range (in CIDR
    -- notation) that web requests originate from. If the @WebACL@ is
    -- associated with a CloudFront distribution and the viewer did not use an
    -- HTTP proxy or a load balancer to send the request, this is the value of
    -- the c-ip field in the CloudFront access logs.
    IPSet -> [IPSetDescriptor]
iPSetDescriptors :: [IPSetDescriptor]
  }
  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:
--
-- 'name', 'iPSet_name' - A friendly name or description of the IPSet. You can\'t change the name
-- of an @IPSet@ after you create it.
--
-- 'iPSetId', 'iPSet_iPSetId' - The @IPSetId@ for an @IPSet@. You use @IPSetId@ to get information about
-- an @IPSet@ (see GetIPSet), update an @IPSet@ (see UpdateIPSet), insert
-- an @IPSet@ into a @Rule@ or delete one from a @Rule@ (see UpdateRule),
-- and delete an @IPSet@ from AWS WAF (see DeleteIPSet).
--
-- @IPSetId@ is returned by CreateIPSet and by ListIPSets.
--
-- 'iPSetDescriptors', 'iPSet_iPSetDescriptors' - The IP address type (@IPV4@ or @IPV6@) and the IP address range (in CIDR
-- notation) that web requests originate from. If the @WebACL@ is
-- associated with a CloudFront distribution and the viewer did not use an
-- HTTP proxy or a load balancer to send the request, this is the value of
-- the c-ip field in the CloudFront access logs.
newIPSet ::
  -- | 'iPSetId'
  Prelude.Text ->
  IPSet
newIPSet :: Text -> IPSet
newIPSet Text
pIPSetId_ =
  IPSet'
    { $sel:name:IPSet' :: Maybe Text
name = forall a. Maybe a
Prelude.Nothing,
      $sel:iPSetId:IPSet' :: Text
iPSetId = Text
pIPSetId_,
      $sel:iPSetDescriptors:IPSet' :: [IPSetDescriptor]
iPSetDescriptors = forall a. Monoid a => a
Prelude.mempty
    }

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

-- | The @IPSetId@ for an @IPSet@. You use @IPSetId@ to get information about
-- an @IPSet@ (see GetIPSet), update an @IPSet@ (see UpdateIPSet), insert
-- an @IPSet@ into a @Rule@ or delete one from a @Rule@ (see UpdateRule),
-- and delete an @IPSet@ from AWS WAF (see DeleteIPSet).
--
-- @IPSetId@ is returned by CreateIPSet and by ListIPSets.
iPSet_iPSetId :: Lens.Lens' IPSet Prelude.Text
iPSet_iPSetId :: Lens' IPSet Text
iPSet_iPSetId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IPSet' {Text
iPSetId :: Text
$sel:iPSetId:IPSet' :: IPSet -> Text
iPSetId} -> Text
iPSetId) (\s :: IPSet
s@IPSet' {} Text
a -> IPSet
s {$sel:iPSetId:IPSet' :: Text
iPSetId = Text
a} :: IPSet)

-- | The IP address type (@IPV4@ or @IPV6@) and the IP address range (in CIDR
-- notation) that web requests originate from. If the @WebACL@ is
-- associated with a CloudFront distribution and the viewer did not use an
-- HTTP proxy or a load balancer to send the request, this is the value of
-- the c-ip field in the CloudFront access logs.
iPSet_iPSetDescriptors :: Lens.Lens' IPSet [IPSetDescriptor]
iPSet_iPSetDescriptors :: Lens' IPSet [IPSetDescriptor]
iPSet_iPSetDescriptors = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IPSet' {[IPSetDescriptor]
iPSetDescriptors :: [IPSetDescriptor]
$sel:iPSetDescriptors:IPSet' :: IPSet -> [IPSetDescriptor]
iPSetDescriptors} -> [IPSetDescriptor]
iPSetDescriptors) (\s :: IPSet
s@IPSet' {} [IPSetDescriptor]
a -> IPSet
s {$sel:iPSetDescriptors:IPSet' :: [IPSetDescriptor]
iPSetDescriptors = [IPSetDescriptor]
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 -> [IPSetDescriptor] -> 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
"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
"IPSetId")
            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
"IPSetDescriptors"
                            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' {[IPSetDescriptor]
Maybe Text
Text
iPSetDescriptors :: [IPSetDescriptor]
iPSetId :: Text
name :: Maybe Text
$sel:iPSetDescriptors:IPSet' :: IPSet -> [IPSetDescriptor]
$sel:iPSetId:IPSet' :: IPSet -> Text
$sel:name:IPSet' :: IPSet -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
iPSetId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [IPSetDescriptor]
iPSetDescriptors

instance Prelude.NFData IPSet where
  rnf :: IPSet -> ()
rnf IPSet' {[IPSetDescriptor]
Maybe Text
Text
iPSetDescriptors :: [IPSetDescriptor]
iPSetId :: Text
name :: Maybe Text
$sel:iPSetDescriptors:IPSet' :: IPSet -> [IPSetDescriptor]
$sel:iPSetId:IPSet' :: IPSet -> Text
$sel:name:IPSet' :: IPSet -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
iPSetId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [IPSetDescriptor]
iPSetDescriptors