{-# 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.CodeDeploy.Types.AppSpecContent
-- 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.CodeDeploy.Types.AppSpecContent where

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

-- | A revision for an AWS Lambda or Amazon ECS deployment that is a
-- YAML-formatted or JSON-formatted string. For AWS Lambda and Amazon ECS
-- deployments, the revision is the same as the AppSpec file. This method
-- replaces the deprecated @RawString@ data type.
--
-- /See:/ 'newAppSpecContent' smart constructor.
data AppSpecContent = AppSpecContent'
  { -- | The YAML-formatted or JSON-formatted revision string.
    --
    -- For an AWS Lambda deployment, the content includes a Lambda function
    -- name, the alias for its original version, and the alias for its
    -- replacement version. The deployment shifts traffic from the original
    -- version of the Lambda function to the replacement version.
    --
    -- For an Amazon ECS deployment, the content includes the task name,
    -- information about the load balancer that serves traffic to the
    -- container, and more.
    --
    -- For both types of deployments, the content can specify Lambda functions
    -- that run at specified hooks, such as @BeforeInstall@, during a
    -- deployment.
    AppSpecContent -> Maybe Text
content :: Prelude.Maybe Prelude.Text,
    -- | The SHA256 hash value of the revision content.
    AppSpecContent -> Maybe Text
sha256 :: Prelude.Maybe Prelude.Text
  }
  deriving (AppSpecContent -> AppSpecContent -> Bool
(AppSpecContent -> AppSpecContent -> Bool)
-> (AppSpecContent -> AppSpecContent -> Bool) -> Eq AppSpecContent
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AppSpecContent -> AppSpecContent -> Bool
$c/= :: AppSpecContent -> AppSpecContent -> Bool
== :: AppSpecContent -> AppSpecContent -> Bool
$c== :: AppSpecContent -> AppSpecContent -> Bool
Prelude.Eq, ReadPrec [AppSpecContent]
ReadPrec AppSpecContent
Int -> ReadS AppSpecContent
ReadS [AppSpecContent]
(Int -> ReadS AppSpecContent)
-> ReadS [AppSpecContent]
-> ReadPrec AppSpecContent
-> ReadPrec [AppSpecContent]
-> Read AppSpecContent
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AppSpecContent]
$creadListPrec :: ReadPrec [AppSpecContent]
readPrec :: ReadPrec AppSpecContent
$creadPrec :: ReadPrec AppSpecContent
readList :: ReadS [AppSpecContent]
$creadList :: ReadS [AppSpecContent]
readsPrec :: Int -> ReadS AppSpecContent
$creadsPrec :: Int -> ReadS AppSpecContent
Prelude.Read, Int -> AppSpecContent -> ShowS
[AppSpecContent] -> ShowS
AppSpecContent -> String
(Int -> AppSpecContent -> ShowS)
-> (AppSpecContent -> String)
-> ([AppSpecContent] -> ShowS)
-> Show AppSpecContent
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AppSpecContent] -> ShowS
$cshowList :: [AppSpecContent] -> ShowS
show :: AppSpecContent -> String
$cshow :: AppSpecContent -> String
showsPrec :: Int -> AppSpecContent -> ShowS
$cshowsPrec :: Int -> AppSpecContent -> ShowS
Prelude.Show, (forall x. AppSpecContent -> Rep AppSpecContent x)
-> (forall x. Rep AppSpecContent x -> AppSpecContent)
-> Generic AppSpecContent
forall x. Rep AppSpecContent x -> AppSpecContent
forall x. AppSpecContent -> Rep AppSpecContent x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AppSpecContent x -> AppSpecContent
$cfrom :: forall x. AppSpecContent -> Rep AppSpecContent x
Prelude.Generic)

-- |
-- Create a value of 'AppSpecContent' 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:
--
-- 'content', 'appSpecContent_content' - The YAML-formatted or JSON-formatted revision string.
--
-- For an AWS Lambda deployment, the content includes a Lambda function
-- name, the alias for its original version, and the alias for its
-- replacement version. The deployment shifts traffic from the original
-- version of the Lambda function to the replacement version.
--
-- For an Amazon ECS deployment, the content includes the task name,
-- information about the load balancer that serves traffic to the
-- container, and more.
--
-- For both types of deployments, the content can specify Lambda functions
-- that run at specified hooks, such as @BeforeInstall@, during a
-- deployment.
--
-- 'sha256', 'appSpecContent_sha256' - The SHA256 hash value of the revision content.
newAppSpecContent ::
  AppSpecContent
newAppSpecContent :: AppSpecContent
newAppSpecContent =
  AppSpecContent' :: Maybe Text -> Maybe Text -> AppSpecContent
AppSpecContent'
    { $sel:content:AppSpecContent' :: Maybe Text
content = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:sha256:AppSpecContent' :: Maybe Text
sha256 = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The YAML-formatted or JSON-formatted revision string.
--
-- For an AWS Lambda deployment, the content includes a Lambda function
-- name, the alias for its original version, and the alias for its
-- replacement version. The deployment shifts traffic from the original
-- version of the Lambda function to the replacement version.
--
-- For an Amazon ECS deployment, the content includes the task name,
-- information about the load balancer that serves traffic to the
-- container, and more.
--
-- For both types of deployments, the content can specify Lambda functions
-- that run at specified hooks, such as @BeforeInstall@, during a
-- deployment.
appSpecContent_content :: Lens.Lens' AppSpecContent (Prelude.Maybe Prelude.Text)
appSpecContent_content :: (Maybe Text -> f (Maybe Text))
-> AppSpecContent -> f AppSpecContent
appSpecContent_content = (AppSpecContent -> Maybe Text)
-> (AppSpecContent -> Maybe Text -> AppSpecContent)
-> Lens AppSpecContent AppSpecContent (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AppSpecContent' {Maybe Text
content :: Maybe Text
$sel:content:AppSpecContent' :: AppSpecContent -> Maybe Text
content} -> Maybe Text
content) (\s :: AppSpecContent
s@AppSpecContent' {} Maybe Text
a -> AppSpecContent
s {$sel:content:AppSpecContent' :: Maybe Text
content = Maybe Text
a} :: AppSpecContent)

-- | The SHA256 hash value of the revision content.
appSpecContent_sha256 :: Lens.Lens' AppSpecContent (Prelude.Maybe Prelude.Text)
appSpecContent_sha256 :: (Maybe Text -> f (Maybe Text))
-> AppSpecContent -> f AppSpecContent
appSpecContent_sha256 = (AppSpecContent -> Maybe Text)
-> (AppSpecContent -> Maybe Text -> AppSpecContent)
-> Lens AppSpecContent AppSpecContent (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AppSpecContent' {Maybe Text
sha256 :: Maybe Text
$sel:sha256:AppSpecContent' :: AppSpecContent -> Maybe Text
sha256} -> Maybe Text
sha256) (\s :: AppSpecContent
s@AppSpecContent' {} Maybe Text
a -> AppSpecContent
s {$sel:sha256:AppSpecContent' :: Maybe Text
sha256 = Maybe Text
a} :: AppSpecContent)

instance Core.FromJSON AppSpecContent where
  parseJSON :: Value -> Parser AppSpecContent
parseJSON =
    String
-> (Object -> Parser AppSpecContent)
-> Value
-> Parser AppSpecContent
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"AppSpecContent"
      ( \Object
x ->
          Maybe Text -> Maybe Text -> AppSpecContent
AppSpecContent'
            (Maybe Text -> Maybe Text -> AppSpecContent)
-> Parser (Maybe Text) -> Parser (Maybe Text -> AppSpecContent)
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
"content")
            Parser (Maybe Text -> AppSpecContent)
-> Parser (Maybe Text) -> Parser AppSpecContent
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
"sha256")
      )

instance Prelude.Hashable AppSpecContent

instance Prelude.NFData AppSpecContent

instance Core.ToJSON AppSpecContent where
  toJSON :: AppSpecContent -> Value
toJSON AppSpecContent' {Maybe Text
sha256 :: Maybe Text
content :: Maybe Text
$sel:sha256:AppSpecContent' :: AppSpecContent -> Maybe Text
$sel:content:AppSpecContent' :: AppSpecContent -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"content" 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
content,
            (Text
"sha256" 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
sha256
          ]
      )