{-# 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.ECS.Types.HostEntry
-- 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.ECS.Types.HostEntry where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Hostnames and IP address entries that are added to the @\/etc\/hosts@
-- file of a container via the @extraHosts@ parameter of its
-- ContainerDefinition.
--
-- /See:/ 'newHostEntry' smart constructor.
data HostEntry = HostEntry'
  { -- | The hostname to use in the @\/etc\/hosts@ entry.
    HostEntry -> Text
hostname :: Prelude.Text,
    -- | The IP address to use in the @\/etc\/hosts@ entry.
    HostEntry -> Text
ipAddress :: Prelude.Text
  }
  deriving (HostEntry -> HostEntry -> Bool
(HostEntry -> HostEntry -> Bool)
-> (HostEntry -> HostEntry -> Bool) -> Eq HostEntry
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: HostEntry -> HostEntry -> Bool
$c/= :: HostEntry -> HostEntry -> Bool
== :: HostEntry -> HostEntry -> Bool
$c== :: HostEntry -> HostEntry -> Bool
Prelude.Eq, ReadPrec [HostEntry]
ReadPrec HostEntry
Int -> ReadS HostEntry
ReadS [HostEntry]
(Int -> ReadS HostEntry)
-> ReadS [HostEntry]
-> ReadPrec HostEntry
-> ReadPrec [HostEntry]
-> Read HostEntry
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [HostEntry]
$creadListPrec :: ReadPrec [HostEntry]
readPrec :: ReadPrec HostEntry
$creadPrec :: ReadPrec HostEntry
readList :: ReadS [HostEntry]
$creadList :: ReadS [HostEntry]
readsPrec :: Int -> ReadS HostEntry
$creadsPrec :: Int -> ReadS HostEntry
Prelude.Read, Int -> HostEntry -> ShowS
[HostEntry] -> ShowS
HostEntry -> String
(Int -> HostEntry -> ShowS)
-> (HostEntry -> String)
-> ([HostEntry] -> ShowS)
-> Show HostEntry
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HostEntry] -> ShowS
$cshowList :: [HostEntry] -> ShowS
show :: HostEntry -> String
$cshow :: HostEntry -> String
showsPrec :: Int -> HostEntry -> ShowS
$cshowsPrec :: Int -> HostEntry -> ShowS
Prelude.Show, (forall x. HostEntry -> Rep HostEntry x)
-> (forall x. Rep HostEntry x -> HostEntry) -> Generic HostEntry
forall x. Rep HostEntry x -> HostEntry
forall x. HostEntry -> Rep HostEntry x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep HostEntry x -> HostEntry
$cfrom :: forall x. HostEntry -> Rep HostEntry x
Prelude.Generic)

-- |
-- Create a value of 'HostEntry' 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:
--
-- 'hostname', 'hostEntry_hostname' - The hostname to use in the @\/etc\/hosts@ entry.
--
-- 'ipAddress', 'hostEntry_ipAddress' - The IP address to use in the @\/etc\/hosts@ entry.
newHostEntry ::
  -- | 'hostname'
  Prelude.Text ->
  -- | 'ipAddress'
  Prelude.Text ->
  HostEntry
newHostEntry :: Text -> Text -> HostEntry
newHostEntry Text
pHostname_ Text
pIpAddress_ =
  HostEntry' :: Text -> Text -> HostEntry
HostEntry'
    { $sel:hostname:HostEntry' :: Text
hostname = Text
pHostname_,
      $sel:ipAddress:HostEntry' :: Text
ipAddress = Text
pIpAddress_
    }

-- | The hostname to use in the @\/etc\/hosts@ entry.
hostEntry_hostname :: Lens.Lens' HostEntry Prelude.Text
hostEntry_hostname :: (Text -> f Text) -> HostEntry -> f HostEntry
hostEntry_hostname = (HostEntry -> Text)
-> (HostEntry -> Text -> HostEntry)
-> Lens HostEntry HostEntry Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HostEntry' {Text
hostname :: Text
$sel:hostname:HostEntry' :: HostEntry -> Text
hostname} -> Text
hostname) (\s :: HostEntry
s@HostEntry' {} Text
a -> HostEntry
s {$sel:hostname:HostEntry' :: Text
hostname = Text
a} :: HostEntry)

-- | The IP address to use in the @\/etc\/hosts@ entry.
hostEntry_ipAddress :: Lens.Lens' HostEntry Prelude.Text
hostEntry_ipAddress :: (Text -> f Text) -> HostEntry -> f HostEntry
hostEntry_ipAddress = (HostEntry -> Text)
-> (HostEntry -> Text -> HostEntry)
-> Lens HostEntry HostEntry Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HostEntry' {Text
ipAddress :: Text
$sel:ipAddress:HostEntry' :: HostEntry -> Text
ipAddress} -> Text
ipAddress) (\s :: HostEntry
s@HostEntry' {} Text
a -> HostEntry
s {$sel:ipAddress:HostEntry' :: Text
ipAddress = Text
a} :: HostEntry)

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

instance Prelude.Hashable HostEntry

instance Prelude.NFData HostEntry

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