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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.WAF.Types.IPSetDescriptorType

-- | 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.
--
-- Specifies the IP address type (@IPV4@ or @IPV6@) and the IP address
-- range (in CIDR format) that web requests originate from.
--
-- /See:/ 'newIPSetDescriptor' smart constructor.
data IPSetDescriptor = IPSetDescriptor'
  { -- | Specify @IPV4@ or @IPV6@.
    IPSetDescriptor -> IPSetDescriptorType
type' :: IPSetDescriptorType,
    -- | Specify an IPv4 address by using CIDR notation. For example:
    --
    -- -   To configure AWS 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 AWS 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@.
    --
    -- For more information about CIDR notation, see the Wikipedia entry
    -- <https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing Classless Inter-Domain Routing>.
    --
    -- Specify an IPv6 address by using CIDR notation. For example:
    --
    -- -   To configure AWS 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 AWS 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@.
    IPSetDescriptor -> Text
value :: Prelude.Text
  }
  deriving (IPSetDescriptor -> IPSetDescriptor -> Bool
(IPSetDescriptor -> IPSetDescriptor -> Bool)
-> (IPSetDescriptor -> IPSetDescriptor -> Bool)
-> Eq IPSetDescriptor
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: IPSetDescriptor -> IPSetDescriptor -> Bool
$c/= :: IPSetDescriptor -> IPSetDescriptor -> Bool
== :: IPSetDescriptor -> IPSetDescriptor -> Bool
$c== :: IPSetDescriptor -> IPSetDescriptor -> Bool
Prelude.Eq, ReadPrec [IPSetDescriptor]
ReadPrec IPSetDescriptor
Int -> ReadS IPSetDescriptor
ReadS [IPSetDescriptor]
(Int -> ReadS IPSetDescriptor)
-> ReadS [IPSetDescriptor]
-> ReadPrec IPSetDescriptor
-> ReadPrec [IPSetDescriptor]
-> Read IPSetDescriptor
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [IPSetDescriptor]
$creadListPrec :: ReadPrec [IPSetDescriptor]
readPrec :: ReadPrec IPSetDescriptor
$creadPrec :: ReadPrec IPSetDescriptor
readList :: ReadS [IPSetDescriptor]
$creadList :: ReadS [IPSetDescriptor]
readsPrec :: Int -> ReadS IPSetDescriptor
$creadsPrec :: Int -> ReadS IPSetDescriptor
Prelude.Read, Int -> IPSetDescriptor -> ShowS
[IPSetDescriptor] -> ShowS
IPSetDescriptor -> String
(Int -> IPSetDescriptor -> ShowS)
-> (IPSetDescriptor -> String)
-> ([IPSetDescriptor] -> ShowS)
-> Show IPSetDescriptor
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IPSetDescriptor] -> ShowS
$cshowList :: [IPSetDescriptor] -> ShowS
show :: IPSetDescriptor -> String
$cshow :: IPSetDescriptor -> String
showsPrec :: Int -> IPSetDescriptor -> ShowS
$cshowsPrec :: Int -> IPSetDescriptor -> ShowS
Prelude.Show, (forall x. IPSetDescriptor -> Rep IPSetDescriptor x)
-> (forall x. Rep IPSetDescriptor x -> IPSetDescriptor)
-> Generic IPSetDescriptor
forall x. Rep IPSetDescriptor x -> IPSetDescriptor
forall x. IPSetDescriptor -> Rep IPSetDescriptor x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep IPSetDescriptor x -> IPSetDescriptor
$cfrom :: forall x. IPSetDescriptor -> Rep IPSetDescriptor x
Prelude.Generic)

-- |
-- Create a value of 'IPSetDescriptor' 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:
--
-- 'type'', 'iPSetDescriptor_type' - Specify @IPV4@ or @IPV6@.
--
-- 'value', 'iPSetDescriptor_value' - Specify an IPv4 address by using CIDR notation. For example:
--
-- -   To configure AWS 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 AWS 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@.
--
-- For more information about CIDR notation, see the Wikipedia entry
-- <https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing Classless Inter-Domain Routing>.
--
-- Specify an IPv6 address by using CIDR notation. For example:
--
-- -   To configure AWS 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 AWS 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@.
newIPSetDescriptor ::
  -- | 'type''
  IPSetDescriptorType ->
  -- | 'value'
  Prelude.Text ->
  IPSetDescriptor
newIPSetDescriptor :: IPSetDescriptorType -> Text -> IPSetDescriptor
newIPSetDescriptor IPSetDescriptorType
pType_ Text
pValue_ =
  IPSetDescriptor' :: IPSetDescriptorType -> Text -> IPSetDescriptor
IPSetDescriptor' {$sel:type':IPSetDescriptor' :: IPSetDescriptorType
type' = IPSetDescriptorType
pType_, $sel:value:IPSetDescriptor' :: Text
value = Text
pValue_}

-- | Specify @IPV4@ or @IPV6@.
iPSetDescriptor_type :: Lens.Lens' IPSetDescriptor IPSetDescriptorType
iPSetDescriptor_type :: (IPSetDescriptorType -> f IPSetDescriptorType)
-> IPSetDescriptor -> f IPSetDescriptor
iPSetDescriptor_type = (IPSetDescriptor -> IPSetDescriptorType)
-> (IPSetDescriptor -> IPSetDescriptorType -> IPSetDescriptor)
-> Lens
     IPSetDescriptor
     IPSetDescriptor
     IPSetDescriptorType
     IPSetDescriptorType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IPSetDescriptor' {IPSetDescriptorType
type' :: IPSetDescriptorType
$sel:type':IPSetDescriptor' :: IPSetDescriptor -> IPSetDescriptorType
type'} -> IPSetDescriptorType
type') (\s :: IPSetDescriptor
s@IPSetDescriptor' {} IPSetDescriptorType
a -> IPSetDescriptor
s {$sel:type':IPSetDescriptor' :: IPSetDescriptorType
type' = IPSetDescriptorType
a} :: IPSetDescriptor)

-- | Specify an IPv4 address by using CIDR notation. For example:
--
-- -   To configure AWS 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 AWS 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@.
--
-- For more information about CIDR notation, see the Wikipedia entry
-- <https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing Classless Inter-Domain Routing>.
--
-- Specify an IPv6 address by using CIDR notation. For example:
--
-- -   To configure AWS 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 AWS 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@.
iPSetDescriptor_value :: Lens.Lens' IPSetDescriptor Prelude.Text
iPSetDescriptor_value :: (Text -> f Text) -> IPSetDescriptor -> f IPSetDescriptor
iPSetDescriptor_value = (IPSetDescriptor -> Text)
-> (IPSetDescriptor -> Text -> IPSetDescriptor)
-> Lens IPSetDescriptor IPSetDescriptor Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IPSetDescriptor' {Text
value :: Text
$sel:value:IPSetDescriptor' :: IPSetDescriptor -> Text
value} -> Text
value) (\s :: IPSetDescriptor
s@IPSetDescriptor' {} Text
a -> IPSetDescriptor
s {$sel:value:IPSetDescriptor' :: Text
value = Text
a} :: IPSetDescriptor)

instance Core.FromJSON IPSetDescriptor where
  parseJSON :: Value -> Parser IPSetDescriptor
parseJSON =
    String
-> (Object -> Parser IPSetDescriptor)
-> Value
-> Parser IPSetDescriptor
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"IPSetDescriptor"
      ( \Object
x ->
          IPSetDescriptorType -> Text -> IPSetDescriptor
IPSetDescriptor'
            (IPSetDescriptorType -> Text -> IPSetDescriptor)
-> Parser IPSetDescriptorType -> Parser (Text -> IPSetDescriptor)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser IPSetDescriptorType
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Type") Parser (Text -> IPSetDescriptor)
-> Parser Text -> Parser IPSetDescriptor
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
"Value")
      )

instance Prelude.Hashable IPSetDescriptor

instance Prelude.NFData IPSetDescriptor

instance Core.ToJSON IPSetDescriptor where
  toJSON :: IPSetDescriptor -> Value
toJSON IPSetDescriptor' {Text
IPSetDescriptorType
value :: Text
type' :: IPSetDescriptorType
$sel:value:IPSetDescriptor' :: IPSetDescriptor -> Text
$sel:type':IPSetDescriptor' :: IPSetDescriptor -> IPSetDescriptorType
..} =
    [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
"Type" Text -> IPSetDescriptorType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= IPSetDescriptorType
type'),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Value" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
value)
          ]
      )