{-# 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.OpsWorks.Types.DeploymentCommand
-- 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.OpsWorks.Types.DeploymentCommand where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.OpsWorks.Types.DeploymentCommandName
import qualified Amazonka.Prelude as Prelude

-- | Used to specify a stack or deployment command.
--
-- /See:/ 'newDeploymentCommand' smart constructor.
data DeploymentCommand = DeploymentCommand'
  { -- | The arguments of those commands that take arguments. It should be set to
    -- a JSON object with the following format:
    --
    -- @{\"arg_name1\" : [\"value1\", \"value2\", ...], \"arg_name2\" : [\"value1\", \"value2\", ...], ...}@
    --
    -- The @update_dependencies@ command takes two arguments:
    --
    -- -   @upgrade_os_to@ - Specifies the desired Amazon Linux version for
    --     instances whose OS you want to upgrade, such as
    --     @Amazon Linux 2016.09@. You must also set the @allow_reboot@
    --     argument to true.
    --
    -- -   @allow_reboot@ - Specifies whether to allow AWS OpsWorks Stacks to
    --     reboot the instances if necessary, after installing the updates.
    --     This argument can be set to either @true@ or @false@. The default
    --     value is @false@.
    --
    -- For example, to upgrade an instance to Amazon Linux 2016.09, set @Args@
    -- to the following.
    --
    -- @ { \"upgrade_os_to\":[\"Amazon Linux 2016.09\"], \"allow_reboot\":[\"true\"] } @
    DeploymentCommand -> Maybe (HashMap Text [Text])
args :: Prelude.Maybe (Prelude.HashMap Prelude.Text [Prelude.Text]),
    -- | Specifies the operation. You can specify only one command.
    --
    -- For stacks, the following commands are available:
    --
    -- -   @execute_recipes@: Execute one or more recipes. To specify the
    --     recipes, set an @Args@ parameter named @recipes@ to the list of
    --     recipes to be executed. For example, to execute @phpapp::appsetup@,
    --     set @Args@ to @{\"recipes\":[\"phpapp::appsetup\"]}@.
    --
    -- -   @install_dependencies@: Install the stack\'s dependencies.
    --
    -- -   @update_custom_cookbooks@: Update the stack\'s custom cookbooks.
    --
    -- -   @update_dependencies@: Update the stack\'s dependencies.
    --
    -- The update_dependencies and install_dependencies commands are supported
    -- only for Linux instances. You can run the commands successfully on
    -- Windows instances, but they do nothing.
    --
    -- For apps, the following commands are available:
    --
    -- -   @deploy@: Deploy an app. Ruby on Rails apps have an optional @Args@
    --     parameter named @migrate@. Set @Args@ to {\"migrate\":[\"true\"]} to
    --     migrate the database. The default setting is
    --     {\"migrate\":[\"false\"]}.
    --
    -- -   @rollback@ Roll the app back to the previous version. When you
    --     update an app, AWS OpsWorks Stacks stores the previous version, up
    --     to a maximum of five versions. You can use this command to roll an
    --     app back as many as four versions.
    --
    -- -   @start@: Start the app\'s web or application server.
    --
    -- -   @stop@: Stop the app\'s web or application server.
    --
    -- -   @restart@: Restart the app\'s web or application server.
    --
    -- -   @undeploy@: Undeploy the app.
    DeploymentCommand -> DeploymentCommandName
name :: DeploymentCommandName
  }
  deriving (DeploymentCommand -> DeploymentCommand -> Bool
(DeploymentCommand -> DeploymentCommand -> Bool)
-> (DeploymentCommand -> DeploymentCommand -> Bool)
-> Eq DeploymentCommand
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeploymentCommand -> DeploymentCommand -> Bool
$c/= :: DeploymentCommand -> DeploymentCommand -> Bool
== :: DeploymentCommand -> DeploymentCommand -> Bool
$c== :: DeploymentCommand -> DeploymentCommand -> Bool
Prelude.Eq, ReadPrec [DeploymentCommand]
ReadPrec DeploymentCommand
Int -> ReadS DeploymentCommand
ReadS [DeploymentCommand]
(Int -> ReadS DeploymentCommand)
-> ReadS [DeploymentCommand]
-> ReadPrec DeploymentCommand
-> ReadPrec [DeploymentCommand]
-> Read DeploymentCommand
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeploymentCommand]
$creadListPrec :: ReadPrec [DeploymentCommand]
readPrec :: ReadPrec DeploymentCommand
$creadPrec :: ReadPrec DeploymentCommand
readList :: ReadS [DeploymentCommand]
$creadList :: ReadS [DeploymentCommand]
readsPrec :: Int -> ReadS DeploymentCommand
$creadsPrec :: Int -> ReadS DeploymentCommand
Prelude.Read, Int -> DeploymentCommand -> ShowS
[DeploymentCommand] -> ShowS
DeploymentCommand -> String
(Int -> DeploymentCommand -> ShowS)
-> (DeploymentCommand -> String)
-> ([DeploymentCommand] -> ShowS)
-> Show DeploymentCommand
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeploymentCommand] -> ShowS
$cshowList :: [DeploymentCommand] -> ShowS
show :: DeploymentCommand -> String
$cshow :: DeploymentCommand -> String
showsPrec :: Int -> DeploymentCommand -> ShowS
$cshowsPrec :: Int -> DeploymentCommand -> ShowS
Prelude.Show, (forall x. DeploymentCommand -> Rep DeploymentCommand x)
-> (forall x. Rep DeploymentCommand x -> DeploymentCommand)
-> Generic DeploymentCommand
forall x. Rep DeploymentCommand x -> DeploymentCommand
forall x. DeploymentCommand -> Rep DeploymentCommand x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeploymentCommand x -> DeploymentCommand
$cfrom :: forall x. DeploymentCommand -> Rep DeploymentCommand x
Prelude.Generic)

-- |
-- Create a value of 'DeploymentCommand' 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:
--
-- 'args', 'deploymentCommand_args' - The arguments of those commands that take arguments. It should be set to
-- a JSON object with the following format:
--
-- @{\"arg_name1\" : [\"value1\", \"value2\", ...], \"arg_name2\" : [\"value1\", \"value2\", ...], ...}@
--
-- The @update_dependencies@ command takes two arguments:
--
-- -   @upgrade_os_to@ - Specifies the desired Amazon Linux version for
--     instances whose OS you want to upgrade, such as
--     @Amazon Linux 2016.09@. You must also set the @allow_reboot@
--     argument to true.
--
-- -   @allow_reboot@ - Specifies whether to allow AWS OpsWorks Stacks to
--     reboot the instances if necessary, after installing the updates.
--     This argument can be set to either @true@ or @false@. The default
--     value is @false@.
--
-- For example, to upgrade an instance to Amazon Linux 2016.09, set @Args@
-- to the following.
--
-- @ { \"upgrade_os_to\":[\"Amazon Linux 2016.09\"], \"allow_reboot\":[\"true\"] } @
--
-- 'name', 'deploymentCommand_name' - Specifies the operation. You can specify only one command.
--
-- For stacks, the following commands are available:
--
-- -   @execute_recipes@: Execute one or more recipes. To specify the
--     recipes, set an @Args@ parameter named @recipes@ to the list of
--     recipes to be executed. For example, to execute @phpapp::appsetup@,
--     set @Args@ to @{\"recipes\":[\"phpapp::appsetup\"]}@.
--
-- -   @install_dependencies@: Install the stack\'s dependencies.
--
-- -   @update_custom_cookbooks@: Update the stack\'s custom cookbooks.
--
-- -   @update_dependencies@: Update the stack\'s dependencies.
--
-- The update_dependencies and install_dependencies commands are supported
-- only for Linux instances. You can run the commands successfully on
-- Windows instances, but they do nothing.
--
-- For apps, the following commands are available:
--
-- -   @deploy@: Deploy an app. Ruby on Rails apps have an optional @Args@
--     parameter named @migrate@. Set @Args@ to {\"migrate\":[\"true\"]} to
--     migrate the database. The default setting is
--     {\"migrate\":[\"false\"]}.
--
-- -   @rollback@ Roll the app back to the previous version. When you
--     update an app, AWS OpsWorks Stacks stores the previous version, up
--     to a maximum of five versions. You can use this command to roll an
--     app back as many as four versions.
--
-- -   @start@: Start the app\'s web or application server.
--
-- -   @stop@: Stop the app\'s web or application server.
--
-- -   @restart@: Restart the app\'s web or application server.
--
-- -   @undeploy@: Undeploy the app.
newDeploymentCommand ::
  -- | 'name'
  DeploymentCommandName ->
  DeploymentCommand
newDeploymentCommand :: DeploymentCommandName -> DeploymentCommand
newDeploymentCommand DeploymentCommandName
pName_ =
  DeploymentCommand' :: Maybe (HashMap Text [Text])
-> DeploymentCommandName -> DeploymentCommand
DeploymentCommand'
    { $sel:args:DeploymentCommand' :: Maybe (HashMap Text [Text])
args = Maybe (HashMap Text [Text])
forall a. Maybe a
Prelude.Nothing,
      $sel:name:DeploymentCommand' :: DeploymentCommandName
name = DeploymentCommandName
pName_
    }

-- | The arguments of those commands that take arguments. It should be set to
-- a JSON object with the following format:
--
-- @{\"arg_name1\" : [\"value1\", \"value2\", ...], \"arg_name2\" : [\"value1\", \"value2\", ...], ...}@
--
-- The @update_dependencies@ command takes two arguments:
--
-- -   @upgrade_os_to@ - Specifies the desired Amazon Linux version for
--     instances whose OS you want to upgrade, such as
--     @Amazon Linux 2016.09@. You must also set the @allow_reboot@
--     argument to true.
--
-- -   @allow_reboot@ - Specifies whether to allow AWS OpsWorks Stacks to
--     reboot the instances if necessary, after installing the updates.
--     This argument can be set to either @true@ or @false@. The default
--     value is @false@.
--
-- For example, to upgrade an instance to Amazon Linux 2016.09, set @Args@
-- to the following.
--
-- @ { \"upgrade_os_to\":[\"Amazon Linux 2016.09\"], \"allow_reboot\":[\"true\"] } @
deploymentCommand_args :: Lens.Lens' DeploymentCommand (Prelude.Maybe (Prelude.HashMap Prelude.Text [Prelude.Text]))
deploymentCommand_args :: (Maybe (HashMap Text [Text]) -> f (Maybe (HashMap Text [Text])))
-> DeploymentCommand -> f DeploymentCommand
deploymentCommand_args = (DeploymentCommand -> Maybe (HashMap Text [Text]))
-> (DeploymentCommand
    -> Maybe (HashMap Text [Text]) -> DeploymentCommand)
-> Lens
     DeploymentCommand
     DeploymentCommand
     (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 (\DeploymentCommand' {Maybe (HashMap Text [Text])
args :: Maybe (HashMap Text [Text])
$sel:args:DeploymentCommand' :: DeploymentCommand -> Maybe (HashMap Text [Text])
args} -> Maybe (HashMap Text [Text])
args) (\s :: DeploymentCommand
s@DeploymentCommand' {} Maybe (HashMap Text [Text])
a -> DeploymentCommand
s {$sel:args:DeploymentCommand' :: Maybe (HashMap Text [Text])
args = Maybe (HashMap Text [Text])
a} :: DeploymentCommand) ((Maybe (HashMap Text [Text]) -> f (Maybe (HashMap Text [Text])))
 -> DeploymentCommand -> f DeploymentCommand)
-> ((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])))
-> DeploymentCommand
-> f DeploymentCommand
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

-- | Specifies the operation. You can specify only one command.
--
-- For stacks, the following commands are available:
--
-- -   @execute_recipes@: Execute one or more recipes. To specify the
--     recipes, set an @Args@ parameter named @recipes@ to the list of
--     recipes to be executed. For example, to execute @phpapp::appsetup@,
--     set @Args@ to @{\"recipes\":[\"phpapp::appsetup\"]}@.
--
-- -   @install_dependencies@: Install the stack\'s dependencies.
--
-- -   @update_custom_cookbooks@: Update the stack\'s custom cookbooks.
--
-- -   @update_dependencies@: Update the stack\'s dependencies.
--
-- The update_dependencies and install_dependencies commands are supported
-- only for Linux instances. You can run the commands successfully on
-- Windows instances, but they do nothing.
--
-- For apps, the following commands are available:
--
-- -   @deploy@: Deploy an app. Ruby on Rails apps have an optional @Args@
--     parameter named @migrate@. Set @Args@ to {\"migrate\":[\"true\"]} to
--     migrate the database. The default setting is
--     {\"migrate\":[\"false\"]}.
--
-- -   @rollback@ Roll the app back to the previous version. When you
--     update an app, AWS OpsWorks Stacks stores the previous version, up
--     to a maximum of five versions. You can use this command to roll an
--     app back as many as four versions.
--
-- -   @start@: Start the app\'s web or application server.
--
-- -   @stop@: Stop the app\'s web or application server.
--
-- -   @restart@: Restart the app\'s web or application server.
--
-- -   @undeploy@: Undeploy the app.
deploymentCommand_name :: Lens.Lens' DeploymentCommand DeploymentCommandName
deploymentCommand_name :: (DeploymentCommandName -> f DeploymentCommandName)
-> DeploymentCommand -> f DeploymentCommand
deploymentCommand_name = (DeploymentCommand -> DeploymentCommandName)
-> (DeploymentCommand
    -> DeploymentCommandName -> DeploymentCommand)
-> Lens
     DeploymentCommand
     DeploymentCommand
     DeploymentCommandName
     DeploymentCommandName
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeploymentCommand' {DeploymentCommandName
name :: DeploymentCommandName
$sel:name:DeploymentCommand' :: DeploymentCommand -> DeploymentCommandName
name} -> DeploymentCommandName
name) (\s :: DeploymentCommand
s@DeploymentCommand' {} DeploymentCommandName
a -> DeploymentCommand
s {$sel:name:DeploymentCommand' :: DeploymentCommandName
name = DeploymentCommandName
a} :: DeploymentCommand)

instance Core.FromJSON DeploymentCommand where
  parseJSON :: Value -> Parser DeploymentCommand
parseJSON =
    String
-> (Object -> Parser DeploymentCommand)
-> Value
-> Parser DeploymentCommand
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"DeploymentCommand"
      ( \Object
x ->
          Maybe (HashMap Text [Text])
-> DeploymentCommandName -> DeploymentCommand
DeploymentCommand'
            (Maybe (HashMap Text [Text])
 -> DeploymentCommandName -> DeploymentCommand)
-> Parser (Maybe (HashMap Text [Text]))
-> Parser (DeploymentCommandName -> DeploymentCommand)
forall (f :: * -> *) a b. Functor 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
"Args" 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 (DeploymentCommandName -> DeploymentCommand)
-> Parser DeploymentCommandName -> Parser DeploymentCommand
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser DeploymentCommandName
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Name")
      )

instance Prelude.Hashable DeploymentCommand

instance Prelude.NFData DeploymentCommand

instance Core.ToJSON DeploymentCommand where
  toJSON :: DeploymentCommand -> Value
toJSON DeploymentCommand' {Maybe (HashMap Text [Text])
DeploymentCommandName
name :: DeploymentCommandName
args :: Maybe (HashMap Text [Text])
$sel:name:DeploymentCommand' :: DeploymentCommand -> DeploymentCommandName
$sel:args:DeploymentCommand' :: DeploymentCommand -> Maybe (HashMap Text [Text])
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Args" 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])
args,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Name" Text -> DeploymentCommandName -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= DeploymentCommandName
name)
          ]
      )