{-# 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.Lightsail.Types.Container
-- 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.Lightsail.Types.Container where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.Lightsail.Types.ContainerServiceProtocol
import qualified Amazonka.Prelude as Prelude

-- | Describes the settings of a container that will be launched, or that is
-- launched, to an Amazon Lightsail container service.
--
-- /See:/ 'newContainer' smart constructor.
data Container = Container'
  { -- | The name of the image used for the container.
    --
    -- Container images sourced from your Lightsail container service, that are
    -- registered and stored on your service, start with a colon (@:@). For
    -- example, @:container-service-1.mystaticwebsite.1@. Container images
    -- sourced from a public registry like Docker Hub don\'t start with a
    -- colon. For example, @nginx:latest@ or @nginx@.
    Container -> Maybe Text
image :: Prelude.Maybe Prelude.Text,
    -- | The launch command for the container.
    Container -> Maybe [Text]
command :: Prelude.Maybe [Prelude.Text],
    -- | The environment variables of the container.
    Container -> Maybe (HashMap Text Text)
environment :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | The open firewall ports of the container.
    Container -> Maybe (HashMap Text ContainerServiceProtocol)
ports :: Prelude.Maybe (Prelude.HashMap Prelude.Text ContainerServiceProtocol)
  }
  deriving (Container -> Container -> Bool
(Container -> Container -> Bool)
-> (Container -> Container -> Bool) -> Eq Container
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Container -> Container -> Bool
$c/= :: Container -> Container -> Bool
== :: Container -> Container -> Bool
$c== :: Container -> Container -> Bool
Prelude.Eq, ReadPrec [Container]
ReadPrec Container
Int -> ReadS Container
ReadS [Container]
(Int -> ReadS Container)
-> ReadS [Container]
-> ReadPrec Container
-> ReadPrec [Container]
-> Read Container
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Container]
$creadListPrec :: ReadPrec [Container]
readPrec :: ReadPrec Container
$creadPrec :: ReadPrec Container
readList :: ReadS [Container]
$creadList :: ReadS [Container]
readsPrec :: Int -> ReadS Container
$creadsPrec :: Int -> ReadS Container
Prelude.Read, Int -> Container -> ShowS
[Container] -> ShowS
Container -> String
(Int -> Container -> ShowS)
-> (Container -> String)
-> ([Container] -> ShowS)
-> Show Container
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Container] -> ShowS
$cshowList :: [Container] -> ShowS
show :: Container -> String
$cshow :: Container -> String
showsPrec :: Int -> Container -> ShowS
$cshowsPrec :: Int -> Container -> ShowS
Prelude.Show, (forall x. Container -> Rep Container x)
-> (forall x. Rep Container x -> Container) -> Generic Container
forall x. Rep Container x -> Container
forall x. Container -> Rep Container x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Container x -> Container
$cfrom :: forall x. Container -> Rep Container x
Prelude.Generic)

-- |
-- Create a value of 'Container' 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:
--
-- 'image', 'container_image' - The name of the image used for the container.
--
-- Container images sourced from your Lightsail container service, that are
-- registered and stored on your service, start with a colon (@:@). For
-- example, @:container-service-1.mystaticwebsite.1@. Container images
-- sourced from a public registry like Docker Hub don\'t start with a
-- colon. For example, @nginx:latest@ or @nginx@.
--
-- 'command', 'container_command' - The launch command for the container.
--
-- 'environment', 'container_environment' - The environment variables of the container.
--
-- 'ports', 'container_ports' - The open firewall ports of the container.
newContainer ::
  Container
newContainer :: Container
newContainer =
  Container' :: Maybe Text
-> Maybe [Text]
-> Maybe (HashMap Text Text)
-> Maybe (HashMap Text ContainerServiceProtocol)
-> Container
Container'
    { $sel:image:Container' :: Maybe Text
image = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:command:Container' :: Maybe [Text]
command = Maybe [Text]
forall a. Maybe a
Prelude.Nothing,
      $sel:environment:Container' :: Maybe (HashMap Text Text)
environment = Maybe (HashMap Text Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:ports:Container' :: Maybe (HashMap Text ContainerServiceProtocol)
ports = Maybe (HashMap Text ContainerServiceProtocol)
forall a. Maybe a
Prelude.Nothing
    }

-- | The name of the image used for the container.
--
-- Container images sourced from your Lightsail container service, that are
-- registered and stored on your service, start with a colon (@:@). For
-- example, @:container-service-1.mystaticwebsite.1@. Container images
-- sourced from a public registry like Docker Hub don\'t start with a
-- colon. For example, @nginx:latest@ or @nginx@.
container_image :: Lens.Lens' Container (Prelude.Maybe Prelude.Text)
container_image :: (Maybe Text -> f (Maybe Text)) -> Container -> f Container
container_image = (Container -> Maybe Text)
-> (Container -> Maybe Text -> Container)
-> Lens Container Container (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Container' {Maybe Text
image :: Maybe Text
$sel:image:Container' :: Container -> Maybe Text
image} -> Maybe Text
image) (\s :: Container
s@Container' {} Maybe Text
a -> Container
s {$sel:image:Container' :: Maybe Text
image = Maybe Text
a} :: Container)

-- | The launch command for the container.
container_command :: Lens.Lens' Container (Prelude.Maybe [Prelude.Text])
container_command :: (Maybe [Text] -> f (Maybe [Text])) -> Container -> f Container
container_command = (Container -> Maybe [Text])
-> (Container -> Maybe [Text] -> Container)
-> Lens Container Container (Maybe [Text]) (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Container' {Maybe [Text]
command :: Maybe [Text]
$sel:command:Container' :: Container -> Maybe [Text]
command} -> Maybe [Text]
command) (\s :: Container
s@Container' {} Maybe [Text]
a -> Container
s {$sel:command:Container' :: Maybe [Text]
command = Maybe [Text]
a} :: Container) ((Maybe [Text] -> f (Maybe [Text])) -> Container -> f Container)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> Container
-> f Container
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

-- | The environment variables of the container.
container_environment :: Lens.Lens' Container (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
container_environment :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> Container -> f Container
container_environment = (Container -> Maybe (HashMap Text Text))
-> (Container -> Maybe (HashMap Text Text) -> Container)
-> Lens
     Container
     Container
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Container' {Maybe (HashMap Text Text)
environment :: Maybe (HashMap Text Text)
$sel:environment:Container' :: Container -> Maybe (HashMap Text Text)
environment} -> Maybe (HashMap Text Text)
environment) (\s :: Container
s@Container' {} Maybe (HashMap Text Text)
a -> Container
s {$sel:environment:Container' :: Maybe (HashMap Text Text)
environment = Maybe (HashMap Text Text)
a} :: Container) ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
 -> Container -> f Container)
-> ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
    -> Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> Container
-> f Container
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
-> Iso
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text 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
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The open firewall ports of the container.
container_ports :: Lens.Lens' Container (Prelude.Maybe (Prelude.HashMap Prelude.Text ContainerServiceProtocol))
container_ports :: (Maybe (HashMap Text ContainerServiceProtocol)
 -> f (Maybe (HashMap Text ContainerServiceProtocol)))
-> Container -> f Container
container_ports = (Container -> Maybe (HashMap Text ContainerServiceProtocol))
-> (Container
    -> Maybe (HashMap Text ContainerServiceProtocol) -> Container)
-> Lens
     Container
     Container
     (Maybe (HashMap Text ContainerServiceProtocol))
     (Maybe (HashMap Text ContainerServiceProtocol))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Container' {Maybe (HashMap Text ContainerServiceProtocol)
ports :: Maybe (HashMap Text ContainerServiceProtocol)
$sel:ports:Container' :: Container -> Maybe (HashMap Text ContainerServiceProtocol)
ports} -> Maybe (HashMap Text ContainerServiceProtocol)
ports) (\s :: Container
s@Container' {} Maybe (HashMap Text ContainerServiceProtocol)
a -> Container
s {$sel:ports:Container' :: Maybe (HashMap Text ContainerServiceProtocol)
ports = Maybe (HashMap Text ContainerServiceProtocol)
a} :: Container) ((Maybe (HashMap Text ContainerServiceProtocol)
  -> f (Maybe (HashMap Text ContainerServiceProtocol)))
 -> Container -> f Container)
-> ((Maybe (HashMap Text ContainerServiceProtocol)
     -> f (Maybe (HashMap Text ContainerServiceProtocol)))
    -> Maybe (HashMap Text ContainerServiceProtocol)
    -> f (Maybe (HashMap Text ContainerServiceProtocol)))
-> (Maybe (HashMap Text ContainerServiceProtocol)
    -> f (Maybe (HashMap Text ContainerServiceProtocol)))
-> Container
-> f Container
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text ContainerServiceProtocol)
  (HashMap Text ContainerServiceProtocol)
  (HashMap Text ContainerServiceProtocol)
  (HashMap Text ContainerServiceProtocol)
-> Iso
     (Maybe (HashMap Text ContainerServiceProtocol))
     (Maybe (HashMap Text ContainerServiceProtocol))
     (Maybe (HashMap Text ContainerServiceProtocol))
     (Maybe (HashMap Text ContainerServiceProtocol))
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
  (HashMap Text ContainerServiceProtocol)
  (HashMap Text ContainerServiceProtocol)
  (HashMap Text ContainerServiceProtocol)
  (HashMap Text ContainerServiceProtocol)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON Container where
  parseJSON :: Value -> Parser Container
parseJSON =
    String -> (Object -> Parser Container) -> Value -> Parser Container
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Container"
      ( \Object
x ->
          Maybe Text
-> Maybe [Text]
-> Maybe (HashMap Text Text)
-> Maybe (HashMap Text ContainerServiceProtocol)
-> Container
Container'
            (Maybe Text
 -> Maybe [Text]
 -> Maybe (HashMap Text Text)
 -> Maybe (HashMap Text ContainerServiceProtocol)
 -> Container)
-> Parser (Maybe Text)
-> Parser
     (Maybe [Text]
      -> Maybe (HashMap Text Text)
      -> Maybe (HashMap Text ContainerServiceProtocol)
      -> Container)
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
"image")
            Parser
  (Maybe [Text]
   -> Maybe (HashMap Text Text)
   -> Maybe (HashMap Text ContainerServiceProtocol)
   -> Container)
-> Parser (Maybe [Text])
-> Parser
     (Maybe (HashMap Text Text)
      -> Maybe (HashMap Text ContainerServiceProtocol) -> Container)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (Maybe [Text]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"command" Parser (Maybe (Maybe [Text]))
-> Maybe [Text] -> Parser (Maybe [Text])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [Text]
forall a. Monoid a => a
Prelude.mempty)
            Parser
  (Maybe (HashMap Text Text)
   -> Maybe (HashMap Text ContainerServiceProtocol) -> Container)
-> Parser (Maybe (HashMap Text Text))
-> Parser
     (Maybe (HashMap Text ContainerServiceProtocol) -> Container)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (Maybe (HashMap Text Text)))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"environment" Parser (Maybe (Maybe (HashMap Text Text)))
-> Maybe (HashMap Text Text) -> Parser (Maybe (HashMap Text Text))
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe (HashMap Text Text)
forall a. Monoid a => a
Prelude.mempty)
            Parser (Maybe (HashMap Text ContainerServiceProtocol) -> Container)
-> Parser (Maybe (HashMap Text ContainerServiceProtocol))
-> Parser Container
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object
-> Text
-> Parser (Maybe (Maybe (HashMap Text ContainerServiceProtocol)))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ports" Parser (Maybe (Maybe (HashMap Text ContainerServiceProtocol)))
-> Maybe (HashMap Text ContainerServiceProtocol)
-> Parser (Maybe (HashMap Text ContainerServiceProtocol))
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe (HashMap Text ContainerServiceProtocol)
forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable Container

instance Prelude.NFData Container

instance Core.ToJSON Container where
  toJSON :: Container -> Value
toJSON Container' {Maybe [Text]
Maybe Text
Maybe (HashMap Text Text)
Maybe (HashMap Text ContainerServiceProtocol)
ports :: Maybe (HashMap Text ContainerServiceProtocol)
environment :: Maybe (HashMap Text Text)
command :: Maybe [Text]
image :: Maybe Text
$sel:ports:Container' :: Container -> Maybe (HashMap Text ContainerServiceProtocol)
$sel:environment:Container' :: Container -> Maybe (HashMap Text Text)
$sel:command:Container' :: Container -> Maybe [Text]
$sel:image:Container' :: Container -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"image" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
image,
            (Text
"command" Text -> [Text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) ([Text] -> Pair) -> Maybe [Text] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Text]
command,
            (Text
"environment" Text -> HashMap Text Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (HashMap Text Text -> Pair)
-> Maybe (HashMap Text Text) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text Text)
environment,
            (Text
"ports" Text -> HashMap Text ContainerServiceProtocol -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (HashMap Text ContainerServiceProtocol -> Pair)
-> Maybe (HashMap Text ContainerServiceProtocol) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text ContainerServiceProtocol)
ports
          ]
      )