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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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'
  { -- | One or more 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
(SourceIpConditionConfig -> SourceIpConditionConfig -> Bool)
-> (SourceIpConditionConfig -> SourceIpConditionConfig -> Bool)
-> Eq SourceIpConditionConfig
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]
(Int -> ReadS SourceIpConditionConfig)
-> ReadS [SourceIpConditionConfig]
-> ReadPrec SourceIpConditionConfig
-> ReadPrec [SourceIpConditionConfig]
-> Read 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
(Int -> SourceIpConditionConfig -> ShowS)
-> (SourceIpConditionConfig -> String)
-> ([SourceIpConditionConfig] -> ShowS)
-> Show SourceIpConditionConfig
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.
 SourceIpConditionConfig -> Rep SourceIpConditionConfig x)
-> (forall x.
    Rep SourceIpConditionConfig x -> SourceIpConditionConfig)
-> Generic SourceIpConditionConfig
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' - One or more 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' :: Maybe [Text] -> SourceIpConditionConfig
SourceIpConditionConfig' {$sel:values:SourceIpConditionConfig' :: Maybe [Text]
values = Maybe [Text]
forall a. Maybe a
Prelude.Nothing}

-- | One or more 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 :: (Maybe [Text] -> f (Maybe [Text]))
-> SourceIpConditionConfig -> f SourceIpConditionConfig
sourceIpConditionConfig_values = (SourceIpConditionConfig -> Maybe [Text])
-> (SourceIpConditionConfig
    -> Maybe [Text] -> SourceIpConditionConfig)
-> Lens
     SourceIpConditionConfig
     SourceIpConditionConfig
     (Maybe [Text])
     (Maybe [Text])
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) ((Maybe [Text] -> f (Maybe [Text]))
 -> SourceIpConditionConfig -> f SourceIpConditionConfig)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> SourceIpConditionConfig
-> f SourceIpConditionConfig
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Text] [Text] [Text] [Text]
-> Iso (Maybe [Text]) (Maybe [Text]) (Maybe [Text]) (Maybe [Text])
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 AnIso [Text] [Text] [Text] [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.Hashable SourceIpConditionConfig

instance Prelude.NFData SourceIpConditionConfig

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