{-# 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.AppRunner.Types.ImageConfiguration
-- 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.AppRunner.Types.ImageConfiguration where

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

-- | Describes the configuration that App Runner uses to run an App Runner
-- service using an image pulled from a source image repository.
--
-- /See:/ 'newImageConfiguration' smart constructor.
data ImageConfiguration = ImageConfiguration'
  { -- | An optional command that App Runner runs to start the application in the
    -- source image. If specified, this command overrides the Docker image’s
    -- default start command.
    ImageConfiguration -> Maybe Text
startCommand :: Prelude.Maybe Prelude.Text,
    -- | Environment variables that are available to your running App Runner
    -- service. An array of key-value pairs. Keys with a prefix of
    -- @AWSAPPRUNNER@ are reserved for system use and aren\'t valid.
    ImageConfiguration -> Maybe (HashMap Text (Sensitive Text))
runtimeEnvironmentVariables :: Prelude.Maybe (Prelude.HashMap Prelude.Text (Core.Sensitive Prelude.Text)),
    -- | The port that your application listens to in the container.
    --
    -- Default: @8080@
    ImageConfiguration -> Maybe Text
port :: Prelude.Maybe Prelude.Text
  }
  deriving (ImageConfiguration -> ImageConfiguration -> Bool
(ImageConfiguration -> ImageConfiguration -> Bool)
-> (ImageConfiguration -> ImageConfiguration -> Bool)
-> Eq ImageConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ImageConfiguration -> ImageConfiguration -> Bool
$c/= :: ImageConfiguration -> ImageConfiguration -> Bool
== :: ImageConfiguration -> ImageConfiguration -> Bool
$c== :: ImageConfiguration -> ImageConfiguration -> Bool
Prelude.Eq, Int -> ImageConfiguration -> ShowS
[ImageConfiguration] -> ShowS
ImageConfiguration -> String
(Int -> ImageConfiguration -> ShowS)
-> (ImageConfiguration -> String)
-> ([ImageConfiguration] -> ShowS)
-> Show ImageConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ImageConfiguration] -> ShowS
$cshowList :: [ImageConfiguration] -> ShowS
show :: ImageConfiguration -> String
$cshow :: ImageConfiguration -> String
showsPrec :: Int -> ImageConfiguration -> ShowS
$cshowsPrec :: Int -> ImageConfiguration -> ShowS
Prelude.Show, (forall x. ImageConfiguration -> Rep ImageConfiguration x)
-> (forall x. Rep ImageConfiguration x -> ImageConfiguration)
-> Generic ImageConfiguration
forall x. Rep ImageConfiguration x -> ImageConfiguration
forall x. ImageConfiguration -> Rep ImageConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ImageConfiguration x -> ImageConfiguration
$cfrom :: forall x. ImageConfiguration -> Rep ImageConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'ImageConfiguration' 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:
--
-- 'startCommand', 'imageConfiguration_startCommand' - An optional command that App Runner runs to start the application in the
-- source image. If specified, this command overrides the Docker image’s
-- default start command.
--
-- 'runtimeEnvironmentVariables', 'imageConfiguration_runtimeEnvironmentVariables' - Environment variables that are available to your running App Runner
-- service. An array of key-value pairs. Keys with a prefix of
-- @AWSAPPRUNNER@ are reserved for system use and aren\'t valid.
--
-- 'port', 'imageConfiguration_port' - The port that your application listens to in the container.
--
-- Default: @8080@
newImageConfiguration ::
  ImageConfiguration
newImageConfiguration :: ImageConfiguration
newImageConfiguration =
  ImageConfiguration' :: Maybe Text
-> Maybe (HashMap Text (Sensitive Text))
-> Maybe Text
-> ImageConfiguration
ImageConfiguration'
    { $sel:startCommand:ImageConfiguration' :: Maybe Text
startCommand = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:runtimeEnvironmentVariables:ImageConfiguration' :: Maybe (HashMap Text (Sensitive Text))
runtimeEnvironmentVariables = Maybe (HashMap Text (Sensitive Text))
forall a. Maybe a
Prelude.Nothing,
      $sel:port:ImageConfiguration' :: Maybe Text
port = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | An optional command that App Runner runs to start the application in the
-- source image. If specified, this command overrides the Docker image’s
-- default start command.
imageConfiguration_startCommand :: Lens.Lens' ImageConfiguration (Prelude.Maybe Prelude.Text)
imageConfiguration_startCommand :: (Maybe Text -> f (Maybe Text))
-> ImageConfiguration -> f ImageConfiguration
imageConfiguration_startCommand = (ImageConfiguration -> Maybe Text)
-> (ImageConfiguration -> Maybe Text -> ImageConfiguration)
-> Lens
     ImageConfiguration ImageConfiguration (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ImageConfiguration' {Maybe Text
startCommand :: Maybe Text
$sel:startCommand:ImageConfiguration' :: ImageConfiguration -> Maybe Text
startCommand} -> Maybe Text
startCommand) (\s :: ImageConfiguration
s@ImageConfiguration' {} Maybe Text
a -> ImageConfiguration
s {$sel:startCommand:ImageConfiguration' :: Maybe Text
startCommand = Maybe Text
a} :: ImageConfiguration)

-- | Environment variables that are available to your running App Runner
-- service. An array of key-value pairs. Keys with a prefix of
-- @AWSAPPRUNNER@ are reserved for system use and aren\'t valid.
imageConfiguration_runtimeEnvironmentVariables :: Lens.Lens' ImageConfiguration (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
imageConfiguration_runtimeEnvironmentVariables :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> ImageConfiguration -> f ImageConfiguration
imageConfiguration_runtimeEnvironmentVariables = (ImageConfiguration -> Maybe (HashMap Text (Sensitive Text)))
-> (ImageConfiguration
    -> Maybe (HashMap Text (Sensitive Text)) -> ImageConfiguration)
-> Lens
     ImageConfiguration
     ImageConfiguration
     (Maybe (HashMap Text (Sensitive Text)))
     (Maybe (HashMap Text (Sensitive Text)))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ImageConfiguration' {Maybe (HashMap Text (Sensitive Text))
runtimeEnvironmentVariables :: Maybe (HashMap Text (Sensitive Text))
$sel:runtimeEnvironmentVariables:ImageConfiguration' :: ImageConfiguration -> Maybe (HashMap Text (Sensitive Text))
runtimeEnvironmentVariables} -> Maybe (HashMap Text (Sensitive Text))
runtimeEnvironmentVariables) (\s :: ImageConfiguration
s@ImageConfiguration' {} Maybe (HashMap Text (Sensitive Text))
a -> ImageConfiguration
s {$sel:runtimeEnvironmentVariables:ImageConfiguration' :: Maybe (HashMap Text (Sensitive Text))
runtimeEnvironmentVariables = Maybe (HashMap Text (Sensitive Text))
a} :: ImageConfiguration) ((Maybe (HashMap Text (Sensitive Text))
  -> f (Maybe (HashMap Text (Sensitive Text))))
 -> ImageConfiguration -> f ImageConfiguration)
-> ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
    -> Maybe (HashMap Text (Sensitive Text))
    -> f (Maybe (HashMap Text (Sensitive Text))))
-> (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> ImageConfiguration
-> f ImageConfiguration
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text (Sensitive Text))
  (HashMap Text (Sensitive Text))
  (HashMap Text Text)
  (HashMap Text Text)
-> Iso
     (Maybe (HashMap Text (Sensitive Text)))
     (Maybe (HashMap Text (Sensitive 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 (Sensitive Text))
  (HashMap Text (Sensitive 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 port that your application listens to in the container.
--
-- Default: @8080@
imageConfiguration_port :: Lens.Lens' ImageConfiguration (Prelude.Maybe Prelude.Text)
imageConfiguration_port :: (Maybe Text -> f (Maybe Text))
-> ImageConfiguration -> f ImageConfiguration
imageConfiguration_port = (ImageConfiguration -> Maybe Text)
-> (ImageConfiguration -> Maybe Text -> ImageConfiguration)
-> Lens
     ImageConfiguration ImageConfiguration (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ImageConfiguration' {Maybe Text
port :: Maybe Text
$sel:port:ImageConfiguration' :: ImageConfiguration -> Maybe Text
port} -> Maybe Text
port) (\s :: ImageConfiguration
s@ImageConfiguration' {} Maybe Text
a -> ImageConfiguration
s {$sel:port:ImageConfiguration' :: Maybe Text
port = Maybe Text
a} :: ImageConfiguration)

instance Core.FromJSON ImageConfiguration where
  parseJSON :: Value -> Parser ImageConfiguration
parseJSON =
    String
-> (Object -> Parser ImageConfiguration)
-> Value
-> Parser ImageConfiguration
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ImageConfiguration"
      ( \Object
x ->
          Maybe Text
-> Maybe (HashMap Text (Sensitive Text))
-> Maybe Text
-> ImageConfiguration
ImageConfiguration'
            (Maybe Text
 -> Maybe (HashMap Text (Sensitive Text))
 -> Maybe Text
 -> ImageConfiguration)
-> Parser (Maybe Text)
-> Parser
     (Maybe (HashMap Text (Sensitive Text))
      -> Maybe Text -> ImageConfiguration)
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
"StartCommand")
            Parser
  (Maybe (HashMap Text (Sensitive Text))
   -> Maybe Text -> ImageConfiguration)
-> Parser (Maybe (HashMap Text (Sensitive Text)))
-> Parser (Maybe Text -> ImageConfiguration)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( Object
x Object
-> Text -> Parser (Maybe (Maybe (HashMap Text (Sensitive Text))))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"RuntimeEnvironmentVariables"
                            Parser (Maybe (Maybe (HashMap Text (Sensitive Text))))
-> Maybe (HashMap Text (Sensitive Text))
-> Parser (Maybe (HashMap Text (Sensitive Text)))
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe (HashMap Text (Sensitive Text))
forall a. Monoid a => a
Prelude.mempty
                        )
            Parser (Maybe Text -> ImageConfiguration)
-> Parser (Maybe Text) -> Parser ImageConfiguration
forall (f :: * -> *) a b. Applicative f => 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
"Port")
      )

instance Prelude.Hashable ImageConfiguration

instance Prelude.NFData ImageConfiguration

instance Core.ToJSON ImageConfiguration where
  toJSON :: ImageConfiguration -> Value
toJSON ImageConfiguration' {Maybe Text
Maybe (HashMap Text (Sensitive Text))
port :: Maybe Text
runtimeEnvironmentVariables :: Maybe (HashMap Text (Sensitive Text))
startCommand :: Maybe Text
$sel:port:ImageConfiguration' :: ImageConfiguration -> Maybe Text
$sel:runtimeEnvironmentVariables:ImageConfiguration' :: ImageConfiguration -> Maybe (HashMap Text (Sensitive Text))
$sel:startCommand:ImageConfiguration' :: ImageConfiguration -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"StartCommand" 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
startCommand,
            (Text
"RuntimeEnvironmentVariables" Text -> HashMap Text (Sensitive Text) -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (HashMap Text (Sensitive Text) -> Pair)
-> Maybe (HashMap Text (Sensitive Text)) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text (Sensitive Text))
runtimeEnvironmentVariables,
            (Text
"Port" 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
port
          ]
      )