{-# 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.ELBV2.Types.SourceIpConditionConfig
-- 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.ELBV2.Types.SourceIpConditionConfig 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

-- | Information about a source IP condition.
--
-- You can use this condition to route based on the IP address of the
-- source that connects to the load balancer. If a client is behind a
-- proxy, this is the IP address of the proxy not the IP address of the
-- client.
--
-- /See:/ 'newSourceIpConditionConfig' smart constructor.
data SourceIpConditionConfig = SourceIpConditionConfig'
  { -- | The source IP addresses, in CIDR format. You can use both IPv4 and IPv6
    -- addresses. Wildcards are not supported.
    --
    -- If you specify multiple addresses, the condition is satisfied if the
    -- source IP address of the request matches one of the CIDR blocks. This
    -- condition is not satisfied by the addresses in the X-Forwarded-For
    -- header. To search for addresses in the X-Forwarded-For header, use
    -- HttpHeaderConditionConfig.
    SourceIpConditionConfig -> Maybe [Text]
values :: Prelude.Maybe [Prelude.Text]
  }
  deriving (SourceIpConditionConfig -> SourceIpConditionConfig -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SourceIpConditionConfig -> SourceIpConditionConfig -> Bool
$c/= :: SourceIpConditionConfig -> SourceIpConditionConfig -> Bool
== :: SourceIpConditionConfig -> SourceIpConditionConfig -> Bool
$c== :: SourceIpConditionConfig -> SourceIpConditionConfig -> Bool
Prelude.Eq, ReadPrec [SourceIpConditionConfig]
ReadPrec SourceIpConditionConfig
Int -> ReadS SourceIpConditionConfig
ReadS [SourceIpConditionConfig]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SourceIpConditionConfig]
$creadListPrec :: ReadPrec [SourceIpConditionConfig]
readPrec :: ReadPrec SourceIpConditionConfig
$creadPrec :: ReadPrec SourceIpConditionConfig
readList :: ReadS [SourceIpConditionConfig]
$creadList :: ReadS [SourceIpConditionConfig]
readsPrec :: Int -> ReadS SourceIpConditionConfig
$creadsPrec :: Int -> ReadS SourceIpConditionConfig
Prelude.Read, Int -> SourceIpConditionConfig -> ShowS
[SourceIpConditionConfig] -> ShowS
SourceIpConditionConfig -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SourceIpConditionConfig] -> ShowS
$cshowList :: [SourceIpConditionConfig] -> ShowS
show :: SourceIpConditionConfig -> String
$cshow :: SourceIpConditionConfig -> String
showsPrec :: Int -> SourceIpConditionConfig -> ShowS
$cshowsPrec :: Int -> SourceIpConditionConfig -> ShowS
Prelude.Show, forall x. Rep SourceIpConditionConfig x -> SourceIpConditionConfig
forall x. SourceIpConditionConfig -> Rep SourceIpConditionConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SourceIpConditionConfig x -> SourceIpConditionConfig
$cfrom :: forall x. SourceIpConditionConfig -> Rep SourceIpConditionConfig x
Prelude.Generic)

-- |
-- Create a value of 'SourceIpConditionConfig' 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:
--
-- 'values', 'sourceIpConditionConfig_values' - The source IP addresses, in CIDR format. You can use both IPv4 and IPv6
-- addresses. Wildcards are not supported.
--
-- If you specify multiple addresses, the condition is satisfied if the
-- source IP address of the request matches one of the CIDR blocks. This
-- condition is not satisfied by the addresses in the X-Forwarded-For
-- header. To search for addresses in the X-Forwarded-For header, use
-- HttpHeaderConditionConfig.
newSourceIpConditionConfig ::
  SourceIpConditionConfig
newSourceIpConditionConfig :: SourceIpConditionConfig
newSourceIpConditionConfig =
  SourceIpConditionConfig' {$sel:values:SourceIpConditionConfig' :: Maybe [Text]
values = forall a. Maybe a
Prelude.Nothing}

-- | The source IP addresses, in CIDR format. You can use both IPv4 and IPv6
-- addresses. Wildcards are not supported.
--
-- If you specify multiple addresses, the condition is satisfied if the
-- source IP address of the request matches one of the CIDR blocks. This
-- condition is not satisfied by the addresses in the X-Forwarded-For
-- header. To search for addresses in the X-Forwarded-For header, use
-- HttpHeaderConditionConfig.
sourceIpConditionConfig_values :: Lens.Lens' SourceIpConditionConfig (Prelude.Maybe [Prelude.Text])
sourceIpConditionConfig_values :: Lens' SourceIpConditionConfig (Maybe [Text])
sourceIpConditionConfig_values = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SourceIpConditionConfig' {Maybe [Text]
values :: Maybe [Text]
$sel:values:SourceIpConditionConfig' :: SourceIpConditionConfig -> Maybe [Text]
values} -> Maybe [Text]
values) (\s :: SourceIpConditionConfig
s@SourceIpConditionConfig' {} Maybe [Text]
a -> SourceIpConditionConfig
s {$sel:values:SourceIpConditionConfig' :: Maybe [Text]
values = Maybe [Text]
a} :: SourceIpConditionConfig) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Data.FromXML SourceIpConditionConfig where
  parseXML :: [Node] -> Either String SourceIpConditionConfig
parseXML [Node]
x =
    Maybe [Text] -> SourceIpConditionConfig
SourceIpConditionConfig'
      forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( [Node]
x
                      forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"Values"
                      forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty
                      forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (forall a. FromXML a => Text -> [Node] -> Either String [a]
Data.parseXMLList Text
"member")
                  )

instance Prelude.Hashable SourceIpConditionConfig where
  hashWithSalt :: Int -> SourceIpConditionConfig -> Int
hashWithSalt Int
_salt SourceIpConditionConfig' {Maybe [Text]
values :: Maybe [Text]
$sel:values:SourceIpConditionConfig' :: SourceIpConditionConfig -> Maybe [Text]
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Text]
values

instance Prelude.NFData SourceIpConditionConfig where
  rnf :: SourceIpConditionConfig -> ()
rnf SourceIpConditionConfig' {Maybe [Text]
values :: Maybe [Text]
$sel:values:SourceIpConditionConfig' :: SourceIpConditionConfig -> Maybe [Text]
..} = forall a. NFData a => a -> ()
Prelude.rnf Maybe [Text]
values

instance Data.ToQuery SourceIpConditionConfig where
  toQuery :: SourceIpConditionConfig -> QueryString
toQuery SourceIpConditionConfig' {Maybe [Text]
values :: Maybe [Text]
$sel:values:SourceIpConditionConfig' :: SourceIpConditionConfig -> Maybe [Text]
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Values"
          forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: forall a. ToQuery a => a -> QueryString
Data.toQuery
            (forall a.
(IsList a, ToQuery (Item a)) =>
ByteString -> a -> QueryString
Data.toQueryList ByteString
"member" forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Text]
values)
      ]