{-# 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-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)
module Amazonka.WAF.Types.IPSet where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(IPSet -> IPSet -> Bool) -> (IPSet -> IPSet -> Bool) -> Eq IPSet
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]
(Int -> ReadS IPSet)
-> ReadS [IPSet]
-> ReadPrec IPSet
-> ReadPrec [IPSet]
-> Read 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
(Int -> IPSet -> ShowS)
-> (IPSet -> String) -> ([IPSet] -> ShowS) -> Show IPSet
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. IPSet -> Rep IPSet x)
-> (forall x. Rep IPSet x -> IPSet) -> Generic IPSet
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' :: Maybe Text -> Text -> [IPSetDescriptor] -> IPSet
IPSet'
    { $sel:name:IPSet' :: Maybe Text
name = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:iPSetId:IPSet' :: Text
iPSetId = Text
pIPSetId_,
      $sel:iPSetDescriptors:IPSet' :: [IPSetDescriptor]
iPSetDescriptors = [IPSetDescriptor]
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 :: (Maybe Text -> f (Maybe Text)) -> IPSet -> f IPSet
iPSet_name = (IPSet -> Maybe Text)
-> (IPSet -> Maybe Text -> IPSet)
-> Lens IPSet IPSet (Maybe Text) (Maybe Text)
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 :: (Text -> f Text) -> IPSet -> f IPSet
iPSet_iPSetId = (IPSet -> Text)
-> (IPSet -> Text -> IPSet) -> Lens IPSet IPSet Text Text
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 :: ([IPSetDescriptor] -> f [IPSetDescriptor]) -> IPSet -> f IPSet
iPSet_iPSetDescriptors = (IPSet -> [IPSetDescriptor])
-> (IPSet -> [IPSetDescriptor] -> IPSet)
-> Lens IPSet IPSet [IPSetDescriptor] [IPSetDescriptor]
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) (([IPSetDescriptor] -> f [IPSetDescriptor]) -> IPSet -> f IPSet)
-> (([IPSetDescriptor] -> f [IPSetDescriptor])
    -> [IPSetDescriptor] -> f [IPSetDescriptor])
-> ([IPSetDescriptor] -> f [IPSetDescriptor])
-> IPSet
-> f IPSet
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([IPSetDescriptor] -> f [IPSetDescriptor])
-> [IPSetDescriptor] -> f [IPSetDescriptor]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON IPSet where
  parseJSON :: Value -> Parser IPSet
parseJSON =
    String -> (Object -> Parser IPSet) -> Value -> Parser IPSet
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"IPSet"
      ( \Object
x ->
          Maybe Text -> Text -> [IPSetDescriptor] -> IPSet
IPSet'
            (Maybe Text -> Text -> [IPSetDescriptor] -> IPSet)
-> Parser (Maybe Text)
-> Parser (Text -> [IPSetDescriptor] -> IPSet)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Name")
            Parser (Text -> [IPSetDescriptor] -> IPSet)
-> Parser Text -> Parser ([IPSetDescriptor] -> IPSet)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"IPSetId")
            Parser ([IPSetDescriptor] -> IPSet)
-> Parser [IPSetDescriptor] -> Parser IPSet
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( Object
x Object -> Text -> Parser (Maybe [IPSetDescriptor])
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"IPSetDescriptors"
                            Parser (Maybe [IPSetDescriptor])
-> [IPSetDescriptor] -> Parser [IPSetDescriptor]
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= [IPSetDescriptor]
forall a. Monoid a => a
Prelude.mempty
                        )
      )

instance Prelude.Hashable IPSet

instance Prelude.NFData IPSet