{-# 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.CodePipeline.StartPipelineExecution
-- 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)
--
-- Starts the specified pipeline. Specifically, it begins processing the
-- latest commit to the source location specified as part of the pipeline.
module Amazonka.CodePipeline.StartPipelineExecution
  ( -- * Creating a Request
    StartPipelineExecution (..),
    newStartPipelineExecution,

    -- * Request Lenses
    startPipelineExecution_clientRequestToken,
    startPipelineExecution_name,

    -- * Destructuring the Response
    StartPipelineExecutionResponse (..),
    newStartPipelineExecutionResponse,

    -- * Response Lenses
    startPipelineExecutionResponse_pipelineExecutionId,
    startPipelineExecutionResponse_httpStatus,
  )
where

import Amazonka.CodePipeline.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

-- | Represents the input of a @StartPipelineExecution@ action.
--
-- /See:/ 'newStartPipelineExecution' smart constructor.
data StartPipelineExecution = StartPipelineExecution'
  { -- | The system-generated unique ID used to identify a unique execution
    -- request.
    StartPipelineExecution -> Maybe Text
clientRequestToken :: Prelude.Maybe Prelude.Text,
    -- | The name of the pipeline to start.
    StartPipelineExecution -> Text
name :: Prelude.Text
  }
  deriving (StartPipelineExecution -> StartPipelineExecution -> Bool
(StartPipelineExecution -> StartPipelineExecution -> Bool)
-> (StartPipelineExecution -> StartPipelineExecution -> Bool)
-> Eq StartPipelineExecution
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StartPipelineExecution -> StartPipelineExecution -> Bool
$c/= :: StartPipelineExecution -> StartPipelineExecution -> Bool
== :: StartPipelineExecution -> StartPipelineExecution -> Bool
$c== :: StartPipelineExecution -> StartPipelineExecution -> Bool
Prelude.Eq, ReadPrec [StartPipelineExecution]
ReadPrec StartPipelineExecution
Int -> ReadS StartPipelineExecution
ReadS [StartPipelineExecution]
(Int -> ReadS StartPipelineExecution)
-> ReadS [StartPipelineExecution]
-> ReadPrec StartPipelineExecution
-> ReadPrec [StartPipelineExecution]
-> Read StartPipelineExecution
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StartPipelineExecution]
$creadListPrec :: ReadPrec [StartPipelineExecution]
readPrec :: ReadPrec StartPipelineExecution
$creadPrec :: ReadPrec StartPipelineExecution
readList :: ReadS [StartPipelineExecution]
$creadList :: ReadS [StartPipelineExecution]
readsPrec :: Int -> ReadS StartPipelineExecution
$creadsPrec :: Int -> ReadS StartPipelineExecution
Prelude.Read, Int -> StartPipelineExecution -> ShowS
[StartPipelineExecution] -> ShowS
StartPipelineExecution -> String
(Int -> StartPipelineExecution -> ShowS)
-> (StartPipelineExecution -> String)
-> ([StartPipelineExecution] -> ShowS)
-> Show StartPipelineExecution
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StartPipelineExecution] -> ShowS
$cshowList :: [StartPipelineExecution] -> ShowS
show :: StartPipelineExecution -> String
$cshow :: StartPipelineExecution -> String
showsPrec :: Int -> StartPipelineExecution -> ShowS
$cshowsPrec :: Int -> StartPipelineExecution -> ShowS
Prelude.Show, (forall x. StartPipelineExecution -> Rep StartPipelineExecution x)
-> (forall x.
    Rep StartPipelineExecution x -> StartPipelineExecution)
-> Generic StartPipelineExecution
forall x. Rep StartPipelineExecution x -> StartPipelineExecution
forall x. StartPipelineExecution -> Rep StartPipelineExecution x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StartPipelineExecution x -> StartPipelineExecution
$cfrom :: forall x. StartPipelineExecution -> Rep StartPipelineExecution x
Prelude.Generic)

-- |
-- Create a value of 'StartPipelineExecution' 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:
--
-- 'clientRequestToken', 'startPipelineExecution_clientRequestToken' - The system-generated unique ID used to identify a unique execution
-- request.
--
-- 'name', 'startPipelineExecution_name' - The name of the pipeline to start.
newStartPipelineExecution ::
  -- | 'name'
  Prelude.Text ->
  StartPipelineExecution
newStartPipelineExecution :: Text -> StartPipelineExecution
newStartPipelineExecution Text
pName_ =
  StartPipelineExecution' :: Maybe Text -> Text -> StartPipelineExecution
StartPipelineExecution'
    { $sel:clientRequestToken:StartPipelineExecution' :: Maybe Text
clientRequestToken =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:name:StartPipelineExecution' :: Text
name = Text
pName_
    }

-- | The system-generated unique ID used to identify a unique execution
-- request.
startPipelineExecution_clientRequestToken :: Lens.Lens' StartPipelineExecution (Prelude.Maybe Prelude.Text)
startPipelineExecution_clientRequestToken :: (Maybe Text -> f (Maybe Text))
-> StartPipelineExecution -> f StartPipelineExecution
startPipelineExecution_clientRequestToken = (StartPipelineExecution -> Maybe Text)
-> (StartPipelineExecution -> Maybe Text -> StartPipelineExecution)
-> Lens
     StartPipelineExecution
     StartPipelineExecution
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartPipelineExecution' {Maybe Text
clientRequestToken :: Maybe Text
$sel:clientRequestToken:StartPipelineExecution' :: StartPipelineExecution -> Maybe Text
clientRequestToken} -> Maybe Text
clientRequestToken) (\s :: StartPipelineExecution
s@StartPipelineExecution' {} Maybe Text
a -> StartPipelineExecution
s {$sel:clientRequestToken:StartPipelineExecution' :: Maybe Text
clientRequestToken = Maybe Text
a} :: StartPipelineExecution)

-- | The name of the pipeline to start.
startPipelineExecution_name :: Lens.Lens' StartPipelineExecution Prelude.Text
startPipelineExecution_name :: (Text -> f Text)
-> StartPipelineExecution -> f StartPipelineExecution
startPipelineExecution_name = (StartPipelineExecution -> Text)
-> (StartPipelineExecution -> Text -> StartPipelineExecution)
-> Lens StartPipelineExecution StartPipelineExecution Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartPipelineExecution' {Text
name :: Text
$sel:name:StartPipelineExecution' :: StartPipelineExecution -> Text
name} -> Text
name) (\s :: StartPipelineExecution
s@StartPipelineExecution' {} Text
a -> StartPipelineExecution
s {$sel:name:StartPipelineExecution' :: Text
name = Text
a} :: StartPipelineExecution)

instance Core.AWSRequest StartPipelineExecution where
  type
    AWSResponse StartPipelineExecution =
      StartPipelineExecutionResponse
  request :: StartPipelineExecution -> Request StartPipelineExecution
request = Service -> StartPipelineExecution -> Request StartPipelineExecution
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy StartPipelineExecution
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse StartPipelineExecution)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse StartPipelineExecution))
-> Logger
-> Service
-> Proxy StartPipelineExecution
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse StartPipelineExecution)))
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 ->
          Maybe Text -> Int -> StartPipelineExecutionResponse
StartPipelineExecutionResponse'
            (Maybe Text -> Int -> StartPipelineExecutionResponse)
-> Either String (Maybe Text)
-> Either String (Int -> StartPipelineExecutionResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"pipelineExecutionId")
            Either String (Int -> StartPipelineExecutionResponse)
-> Either String Int
-> Either String StartPipelineExecutionResponse
forall (f :: * -> *) a b. Applicative f => 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))
      )

instance Prelude.Hashable StartPipelineExecution

instance Prelude.NFData StartPipelineExecution

instance Core.ToHeaders StartPipelineExecution where
  toHeaders :: StartPipelineExecution -> ResponseHeaders
toHeaders =
    ResponseHeaders -> StartPipelineExecution -> 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
"CodePipeline_20150709.StartPipelineExecution" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

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

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

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

-- | Represents the output of a @StartPipelineExecution@ action.
--
-- /See:/ 'newStartPipelineExecutionResponse' smart constructor.
data StartPipelineExecutionResponse = StartPipelineExecutionResponse'
  { -- | The unique system-generated ID of the pipeline execution that was
    -- started.
    StartPipelineExecutionResponse -> Maybe Text
pipelineExecutionId :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    StartPipelineExecutionResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (StartPipelineExecutionResponse
-> StartPipelineExecutionResponse -> Bool
(StartPipelineExecutionResponse
 -> StartPipelineExecutionResponse -> Bool)
-> (StartPipelineExecutionResponse
    -> StartPipelineExecutionResponse -> Bool)
-> Eq StartPipelineExecutionResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StartPipelineExecutionResponse
-> StartPipelineExecutionResponse -> Bool
$c/= :: StartPipelineExecutionResponse
-> StartPipelineExecutionResponse -> Bool
== :: StartPipelineExecutionResponse
-> StartPipelineExecutionResponse -> Bool
$c== :: StartPipelineExecutionResponse
-> StartPipelineExecutionResponse -> Bool
Prelude.Eq, ReadPrec [StartPipelineExecutionResponse]
ReadPrec StartPipelineExecutionResponse
Int -> ReadS StartPipelineExecutionResponse
ReadS [StartPipelineExecutionResponse]
(Int -> ReadS StartPipelineExecutionResponse)
-> ReadS [StartPipelineExecutionResponse]
-> ReadPrec StartPipelineExecutionResponse
-> ReadPrec [StartPipelineExecutionResponse]
-> Read StartPipelineExecutionResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StartPipelineExecutionResponse]
$creadListPrec :: ReadPrec [StartPipelineExecutionResponse]
readPrec :: ReadPrec StartPipelineExecutionResponse
$creadPrec :: ReadPrec StartPipelineExecutionResponse
readList :: ReadS [StartPipelineExecutionResponse]
$creadList :: ReadS [StartPipelineExecutionResponse]
readsPrec :: Int -> ReadS StartPipelineExecutionResponse
$creadsPrec :: Int -> ReadS StartPipelineExecutionResponse
Prelude.Read, Int -> StartPipelineExecutionResponse -> ShowS
[StartPipelineExecutionResponse] -> ShowS
StartPipelineExecutionResponse -> String
(Int -> StartPipelineExecutionResponse -> ShowS)
-> (StartPipelineExecutionResponse -> String)
-> ([StartPipelineExecutionResponse] -> ShowS)
-> Show StartPipelineExecutionResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StartPipelineExecutionResponse] -> ShowS
$cshowList :: [StartPipelineExecutionResponse] -> ShowS
show :: StartPipelineExecutionResponse -> String
$cshow :: StartPipelineExecutionResponse -> String
showsPrec :: Int -> StartPipelineExecutionResponse -> ShowS
$cshowsPrec :: Int -> StartPipelineExecutionResponse -> ShowS
Prelude.Show, (forall x.
 StartPipelineExecutionResponse
 -> Rep StartPipelineExecutionResponse x)
-> (forall x.
    Rep StartPipelineExecutionResponse x
    -> StartPipelineExecutionResponse)
-> Generic StartPipelineExecutionResponse
forall x.
Rep StartPipelineExecutionResponse x
-> StartPipelineExecutionResponse
forall x.
StartPipelineExecutionResponse
-> Rep StartPipelineExecutionResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep StartPipelineExecutionResponse x
-> StartPipelineExecutionResponse
$cfrom :: forall x.
StartPipelineExecutionResponse
-> Rep StartPipelineExecutionResponse x
Prelude.Generic)

-- |
-- Create a value of 'StartPipelineExecutionResponse' 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:
--
-- 'pipelineExecutionId', 'startPipelineExecutionResponse_pipelineExecutionId' - The unique system-generated ID of the pipeline execution that was
-- started.
--
-- 'httpStatus', 'startPipelineExecutionResponse_httpStatus' - The response's http status code.
newStartPipelineExecutionResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  StartPipelineExecutionResponse
newStartPipelineExecutionResponse :: Int -> StartPipelineExecutionResponse
newStartPipelineExecutionResponse Int
pHttpStatus_ =
  StartPipelineExecutionResponse' :: Maybe Text -> Int -> StartPipelineExecutionResponse
StartPipelineExecutionResponse'
    { $sel:pipelineExecutionId:StartPipelineExecutionResponse' :: Maybe Text
pipelineExecutionId =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:StartPipelineExecutionResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The unique system-generated ID of the pipeline execution that was
-- started.
startPipelineExecutionResponse_pipelineExecutionId :: Lens.Lens' StartPipelineExecutionResponse (Prelude.Maybe Prelude.Text)
startPipelineExecutionResponse_pipelineExecutionId :: (Maybe Text -> f (Maybe Text))
-> StartPipelineExecutionResponse
-> f StartPipelineExecutionResponse
startPipelineExecutionResponse_pipelineExecutionId = (StartPipelineExecutionResponse -> Maybe Text)
-> (StartPipelineExecutionResponse
    -> Maybe Text -> StartPipelineExecutionResponse)
-> Lens
     StartPipelineExecutionResponse
     StartPipelineExecutionResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartPipelineExecutionResponse' {Maybe Text
pipelineExecutionId :: Maybe Text
$sel:pipelineExecutionId:StartPipelineExecutionResponse' :: StartPipelineExecutionResponse -> Maybe Text
pipelineExecutionId} -> Maybe Text
pipelineExecutionId) (\s :: StartPipelineExecutionResponse
s@StartPipelineExecutionResponse' {} Maybe Text
a -> StartPipelineExecutionResponse
s {$sel:pipelineExecutionId:StartPipelineExecutionResponse' :: Maybe Text
pipelineExecutionId = Maybe Text
a} :: StartPipelineExecutionResponse)

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

instance
  Prelude.NFData
    StartPipelineExecutionResponse