{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# 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.StartDeployment
-- 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)
--
-- Initiate a manual deployment of the latest commit in a source code
-- repository or the latest image in a source image repository to an App
-- Runner service.
--
-- For a source code repository, App Runner retrieves the commit and builds
-- a Docker image. For a source image repository, App Runner retrieves the
-- latest Docker image. In both cases, App Runner then deploys the new
-- image to your service and starts a new container instance.
--
-- This is an asynchronous operation. On a successful call, you can use the
-- returned @OperationId@ and the ListOperations call to track the
-- operation\'s progress.
module Amazonka.AppRunner.StartDeployment
  ( -- * Creating a Request
    StartDeployment (..),
    newStartDeployment,

    -- * Request Lenses
    startDeployment_serviceArn,

    -- * Destructuring the Response
    StartDeploymentResponse (..),
    newStartDeploymentResponse,

    -- * Response Lenses
    startDeploymentResponse_httpStatus,
    startDeploymentResponse_operationId,
  )
where

import Amazonka.AppRunner.Types
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newStartDeployment' smart constructor.
data StartDeployment = StartDeployment'
  { -- | The Amazon Resource Name (ARN) of the App Runner service that you want
    -- to manually deploy to.
    StartDeployment -> Text
serviceArn :: Prelude.Text
  }
  deriving (StartDeployment -> StartDeployment -> Bool
(StartDeployment -> StartDeployment -> Bool)
-> (StartDeployment -> StartDeployment -> Bool)
-> Eq StartDeployment
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StartDeployment -> StartDeployment -> Bool
$c/= :: StartDeployment -> StartDeployment -> Bool
== :: StartDeployment -> StartDeployment -> Bool
$c== :: StartDeployment -> StartDeployment -> Bool
Prelude.Eq, ReadPrec [StartDeployment]
ReadPrec StartDeployment
Int -> ReadS StartDeployment
ReadS [StartDeployment]
(Int -> ReadS StartDeployment)
-> ReadS [StartDeployment]
-> ReadPrec StartDeployment
-> ReadPrec [StartDeployment]
-> Read StartDeployment
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StartDeployment]
$creadListPrec :: ReadPrec [StartDeployment]
readPrec :: ReadPrec StartDeployment
$creadPrec :: ReadPrec StartDeployment
readList :: ReadS [StartDeployment]
$creadList :: ReadS [StartDeployment]
readsPrec :: Int -> ReadS StartDeployment
$creadsPrec :: Int -> ReadS StartDeployment
Prelude.Read, Int -> StartDeployment -> ShowS
[StartDeployment] -> ShowS
StartDeployment -> String
(Int -> StartDeployment -> ShowS)
-> (StartDeployment -> String)
-> ([StartDeployment] -> ShowS)
-> Show StartDeployment
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StartDeployment] -> ShowS
$cshowList :: [StartDeployment] -> ShowS
show :: StartDeployment -> String
$cshow :: StartDeployment -> String
showsPrec :: Int -> StartDeployment -> ShowS
$cshowsPrec :: Int -> StartDeployment -> ShowS
Prelude.Show, (forall x. StartDeployment -> Rep StartDeployment x)
-> (forall x. Rep StartDeployment x -> StartDeployment)
-> Generic StartDeployment
forall x. Rep StartDeployment x -> StartDeployment
forall x. StartDeployment -> Rep StartDeployment x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StartDeployment x -> StartDeployment
$cfrom :: forall x. StartDeployment -> Rep StartDeployment x
Prelude.Generic)

-- |
-- Create a value of 'StartDeployment' 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:
--
-- 'serviceArn', 'startDeployment_serviceArn' - The Amazon Resource Name (ARN) of the App Runner service that you want
-- to manually deploy to.
newStartDeployment ::
  -- | 'serviceArn'
  Prelude.Text ->
  StartDeployment
newStartDeployment :: Text -> StartDeployment
newStartDeployment Text
pServiceArn_ =
  StartDeployment' :: Text -> StartDeployment
StartDeployment' {$sel:serviceArn:StartDeployment' :: Text
serviceArn = Text
pServiceArn_}

-- | The Amazon Resource Name (ARN) of the App Runner service that you want
-- to manually deploy to.
startDeployment_serviceArn :: Lens.Lens' StartDeployment Prelude.Text
startDeployment_serviceArn :: (Text -> f Text) -> StartDeployment -> f StartDeployment
startDeployment_serviceArn = (StartDeployment -> Text)
-> (StartDeployment -> Text -> StartDeployment)
-> Lens StartDeployment StartDeployment Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartDeployment' {Text
serviceArn :: Text
$sel:serviceArn:StartDeployment' :: StartDeployment -> Text
serviceArn} -> Text
serviceArn) (\s :: StartDeployment
s@StartDeployment' {} Text
a -> StartDeployment
s {$sel:serviceArn:StartDeployment' :: Text
serviceArn = Text
a} :: StartDeployment)

instance Core.AWSRequest StartDeployment where
  type
    AWSResponse StartDeployment =
      StartDeploymentResponse
  request :: StartDeployment -> Request StartDeployment
request = Service -> StartDeployment -> Request StartDeployment
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy StartDeployment
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse StartDeployment)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse StartDeployment))
-> Logger
-> Service
-> Proxy StartDeployment
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse StartDeployment)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Int -> Text -> StartDeploymentResponse
StartDeploymentResponse'
            (Int -> Text -> StartDeploymentResponse)
-> Either String Int
-> Either String (Text -> StartDeploymentResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
            Either String (Text -> StartDeploymentResponse)
-> Either String Text -> Either String StartDeploymentResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String Text
forall a. FromJSON a => Object -> Text -> Either String a
Core..:> Text
"OperationId")
      )

instance Prelude.Hashable StartDeployment

instance Prelude.NFData StartDeployment

instance Core.ToHeaders StartDeployment where
  toHeaders :: StartDeployment -> ResponseHeaders
toHeaders =
    ResponseHeaders -> StartDeployment -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# (ByteString
"AppRunner.StartDeployment" :: Prelude.ByteString),
            HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.0" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON StartDeployment where
  toJSON :: StartDeployment -> Value
toJSON StartDeployment' {Text
serviceArn :: Text
$sel:serviceArn:StartDeployment' :: StartDeployment -> 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
"ServiceArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
serviceArn)]
      )

instance Core.ToPath StartDeployment where
  toPath :: StartDeployment -> ByteString
toPath = ByteString -> StartDeployment -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Core.ToQuery StartDeployment where
  toQuery :: StartDeployment -> QueryString
toQuery = QueryString -> StartDeployment -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newStartDeploymentResponse' smart constructor.
data StartDeploymentResponse = StartDeploymentResponse'
  { -- | The response's http status code.
    StartDeploymentResponse -> Int
httpStatus :: Prelude.Int,
    -- | The unique ID of the asynchronous operation that this request started.
    -- You can use it combined with the ListOperations call to track the
    -- operation\'s progress.
    StartDeploymentResponse -> Text
operationId :: Prelude.Text
  }
  deriving (StartDeploymentResponse -> StartDeploymentResponse -> Bool
(StartDeploymentResponse -> StartDeploymentResponse -> Bool)
-> (StartDeploymentResponse -> StartDeploymentResponse -> Bool)
-> Eq StartDeploymentResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StartDeploymentResponse -> StartDeploymentResponse -> Bool
$c/= :: StartDeploymentResponse -> StartDeploymentResponse -> Bool
== :: StartDeploymentResponse -> StartDeploymentResponse -> Bool
$c== :: StartDeploymentResponse -> StartDeploymentResponse -> Bool
Prelude.Eq, ReadPrec [StartDeploymentResponse]
ReadPrec StartDeploymentResponse
Int -> ReadS StartDeploymentResponse
ReadS [StartDeploymentResponse]
(Int -> ReadS StartDeploymentResponse)
-> ReadS [StartDeploymentResponse]
-> ReadPrec StartDeploymentResponse
-> ReadPrec [StartDeploymentResponse]
-> Read StartDeploymentResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StartDeploymentResponse]
$creadListPrec :: ReadPrec [StartDeploymentResponse]
readPrec :: ReadPrec StartDeploymentResponse
$creadPrec :: ReadPrec StartDeploymentResponse
readList :: ReadS [StartDeploymentResponse]
$creadList :: ReadS [StartDeploymentResponse]
readsPrec :: Int -> ReadS StartDeploymentResponse
$creadsPrec :: Int -> ReadS StartDeploymentResponse
Prelude.Read, Int -> StartDeploymentResponse -> ShowS
[StartDeploymentResponse] -> ShowS
StartDeploymentResponse -> String
(Int -> StartDeploymentResponse -> ShowS)
-> (StartDeploymentResponse -> String)
-> ([StartDeploymentResponse] -> ShowS)
-> Show StartDeploymentResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StartDeploymentResponse] -> ShowS
$cshowList :: [StartDeploymentResponse] -> ShowS
show :: StartDeploymentResponse -> String
$cshow :: StartDeploymentResponse -> String
showsPrec :: Int -> StartDeploymentResponse -> ShowS
$cshowsPrec :: Int -> StartDeploymentResponse -> ShowS
Prelude.Show, (forall x.
 StartDeploymentResponse -> Rep StartDeploymentResponse x)
-> (forall x.
    Rep StartDeploymentResponse x -> StartDeploymentResponse)
-> Generic StartDeploymentResponse
forall x. Rep StartDeploymentResponse x -> StartDeploymentResponse
forall x. StartDeploymentResponse -> Rep StartDeploymentResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StartDeploymentResponse x -> StartDeploymentResponse
$cfrom :: forall x. StartDeploymentResponse -> Rep StartDeploymentResponse x
Prelude.Generic)

-- |
-- Create a value of 'StartDeploymentResponse' 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:
--
-- 'httpStatus', 'startDeploymentResponse_httpStatus' - The response's http status code.
--
-- 'operationId', 'startDeploymentResponse_operationId' - The unique ID of the asynchronous operation that this request started.
-- You can use it combined with the ListOperations call to track the
-- operation\'s progress.
newStartDeploymentResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'operationId'
  Prelude.Text ->
  StartDeploymentResponse
newStartDeploymentResponse :: Int -> Text -> StartDeploymentResponse
newStartDeploymentResponse Int
pHttpStatus_ Text
pOperationId_ =
  StartDeploymentResponse' :: Int -> Text -> StartDeploymentResponse
StartDeploymentResponse'
    { $sel:httpStatus:StartDeploymentResponse' :: Int
httpStatus = Int
pHttpStatus_,
      $sel:operationId:StartDeploymentResponse' :: Text
operationId = Text
pOperationId_
    }

-- | The response's http status code.
startDeploymentResponse_httpStatus :: Lens.Lens' StartDeploymentResponse Prelude.Int
startDeploymentResponse_httpStatus :: (Int -> f Int)
-> StartDeploymentResponse -> f StartDeploymentResponse
startDeploymentResponse_httpStatus = (StartDeploymentResponse -> Int)
-> (StartDeploymentResponse -> Int -> StartDeploymentResponse)
-> Lens StartDeploymentResponse StartDeploymentResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartDeploymentResponse' {Int
httpStatus :: Int
$sel:httpStatus:StartDeploymentResponse' :: StartDeploymentResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: StartDeploymentResponse
s@StartDeploymentResponse' {} Int
a -> StartDeploymentResponse
s {$sel:httpStatus:StartDeploymentResponse' :: Int
httpStatus = Int
a} :: StartDeploymentResponse)

-- | The unique ID of the asynchronous operation that this request started.
-- You can use it combined with the ListOperations call to track the
-- operation\'s progress.
startDeploymentResponse_operationId :: Lens.Lens' StartDeploymentResponse Prelude.Text
startDeploymentResponse_operationId :: (Text -> f Text)
-> StartDeploymentResponse -> f StartDeploymentResponse
startDeploymentResponse_operationId = (StartDeploymentResponse -> Text)
-> (StartDeploymentResponse -> Text -> StartDeploymentResponse)
-> Lens StartDeploymentResponse StartDeploymentResponse Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartDeploymentResponse' {Text
operationId :: Text
$sel:operationId:StartDeploymentResponse' :: StartDeploymentResponse -> Text
operationId} -> Text
operationId) (\s :: StartDeploymentResponse
s@StartDeploymentResponse' {} Text
a -> StartDeploymentResponse
s {$sel:operationId:StartDeploymentResponse' :: Text
operationId = Text
a} :: StartDeploymentResponse)

instance Prelude.NFData StartDeploymentResponse