{-# 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.GetPipeline
-- 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)
--
-- Returns the metadata, structure, stages, and actions of a pipeline. Can
-- be used to return the entire structure of a pipeline in JSON format,
-- which can then be modified and used to update the pipeline structure
-- with UpdatePipeline.
module Amazonka.CodePipeline.GetPipeline
  ( -- * Creating a Request
    GetPipeline (..),
    newGetPipeline,

    -- * Request Lenses
    getPipeline_version,
    getPipeline_name,

    -- * Destructuring the Response
    GetPipelineResponse (..),
    newGetPipelineResponse,

    -- * Response Lenses
    getPipelineResponse_pipeline,
    getPipelineResponse_metadata,
    getPipelineResponse_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 @GetPipeline@ action.
--
-- /See:/ 'newGetPipeline' smart constructor.
data GetPipeline = GetPipeline'
  { -- | The version number of the pipeline. If you do not specify a version,
    -- defaults to the current version.
    GetPipeline -> Maybe Natural
version :: Prelude.Maybe Prelude.Natural,
    -- | The name of the pipeline for which you want to get information. Pipeline
    -- names must be unique under an AWS user account.
    GetPipeline -> Text
name :: Prelude.Text
  }
  deriving (GetPipeline -> GetPipeline -> Bool
(GetPipeline -> GetPipeline -> Bool)
-> (GetPipeline -> GetPipeline -> Bool) -> Eq GetPipeline
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetPipeline -> GetPipeline -> Bool
$c/= :: GetPipeline -> GetPipeline -> Bool
== :: GetPipeline -> GetPipeline -> Bool
$c== :: GetPipeline -> GetPipeline -> Bool
Prelude.Eq, ReadPrec [GetPipeline]
ReadPrec GetPipeline
Int -> ReadS GetPipeline
ReadS [GetPipeline]
(Int -> ReadS GetPipeline)
-> ReadS [GetPipeline]
-> ReadPrec GetPipeline
-> ReadPrec [GetPipeline]
-> Read GetPipeline
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetPipeline]
$creadListPrec :: ReadPrec [GetPipeline]
readPrec :: ReadPrec GetPipeline
$creadPrec :: ReadPrec GetPipeline
readList :: ReadS [GetPipeline]
$creadList :: ReadS [GetPipeline]
readsPrec :: Int -> ReadS GetPipeline
$creadsPrec :: Int -> ReadS GetPipeline
Prelude.Read, Int -> GetPipeline -> ShowS
[GetPipeline] -> ShowS
GetPipeline -> String
(Int -> GetPipeline -> ShowS)
-> (GetPipeline -> String)
-> ([GetPipeline] -> ShowS)
-> Show GetPipeline
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetPipeline] -> ShowS
$cshowList :: [GetPipeline] -> ShowS
show :: GetPipeline -> String
$cshow :: GetPipeline -> String
showsPrec :: Int -> GetPipeline -> ShowS
$cshowsPrec :: Int -> GetPipeline -> ShowS
Prelude.Show, (forall x. GetPipeline -> Rep GetPipeline x)
-> (forall x. Rep GetPipeline x -> GetPipeline)
-> Generic GetPipeline
forall x. Rep GetPipeline x -> GetPipeline
forall x. GetPipeline -> Rep GetPipeline x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetPipeline x -> GetPipeline
$cfrom :: forall x. GetPipeline -> Rep GetPipeline x
Prelude.Generic)

-- |
-- Create a value of 'GetPipeline' 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:
--
-- 'version', 'getPipeline_version' - The version number of the pipeline. If you do not specify a version,
-- defaults to the current version.
--
-- 'name', 'getPipeline_name' - The name of the pipeline for which you want to get information. Pipeline
-- names must be unique under an AWS user account.
newGetPipeline ::
  -- | 'name'
  Prelude.Text ->
  GetPipeline
newGetPipeline :: Text -> GetPipeline
newGetPipeline Text
pName_ =
  GetPipeline' :: Maybe Natural -> Text -> GetPipeline
GetPipeline'
    { $sel:version:GetPipeline' :: Maybe Natural
version = Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:name:GetPipeline' :: Text
name = Text
pName_
    }

-- | The version number of the pipeline. If you do not specify a version,
-- defaults to the current version.
getPipeline_version :: Lens.Lens' GetPipeline (Prelude.Maybe Prelude.Natural)
getPipeline_version :: (Maybe Natural -> f (Maybe Natural))
-> GetPipeline -> f GetPipeline
getPipeline_version = (GetPipeline -> Maybe Natural)
-> (GetPipeline -> Maybe Natural -> GetPipeline)
-> Lens GetPipeline GetPipeline (Maybe Natural) (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetPipeline' {Maybe Natural
version :: Maybe Natural
$sel:version:GetPipeline' :: GetPipeline -> Maybe Natural
version} -> Maybe Natural
version) (\s :: GetPipeline
s@GetPipeline' {} Maybe Natural
a -> GetPipeline
s {$sel:version:GetPipeline' :: Maybe Natural
version = Maybe Natural
a} :: GetPipeline)

-- | The name of the pipeline for which you want to get information. Pipeline
-- names must be unique under an AWS user account.
getPipeline_name :: Lens.Lens' GetPipeline Prelude.Text
getPipeline_name :: (Text -> f Text) -> GetPipeline -> f GetPipeline
getPipeline_name = (GetPipeline -> Text)
-> (GetPipeline -> Text -> GetPipeline)
-> Lens GetPipeline GetPipeline Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetPipeline' {Text
name :: Text
$sel:name:GetPipeline' :: GetPipeline -> Text
name} -> Text
name) (\s :: GetPipeline
s@GetPipeline' {} Text
a -> GetPipeline
s {$sel:name:GetPipeline' :: Text
name = Text
a} :: GetPipeline)

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

instance Prelude.NFData GetPipeline

instance Core.ToHeaders GetPipeline where
  toHeaders :: GetPipeline -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetPipeline -> 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.GetPipeline" ::
                          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 GetPipeline where
  toJSON :: GetPipeline -> Value
toJSON GetPipeline' {Maybe Natural
Text
name :: Text
version :: Maybe Natural
$sel:name:GetPipeline' :: GetPipeline -> Text
$sel:version:GetPipeline' :: GetPipeline -> Maybe Natural
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"version" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Natural -> Pair) -> Maybe Natural -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
version,
            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 GetPipeline where
  toPath :: GetPipeline -> ByteString
toPath = ByteString -> GetPipeline -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

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

-- | Represents the output of a @GetPipeline@ action.
--
-- /See:/ 'newGetPipelineResponse' smart constructor.
data GetPipelineResponse = GetPipelineResponse'
  { -- | Represents the structure of actions and stages to be performed in the
    -- pipeline.
    GetPipelineResponse -> Maybe PipelineDeclaration
pipeline :: Prelude.Maybe PipelineDeclaration,
    -- | Represents the pipeline metadata information returned as part of the
    -- output of a @GetPipeline@ action.
    GetPipelineResponse -> Maybe PipelineMetadata
metadata :: Prelude.Maybe PipelineMetadata,
    -- | The response's http status code.
    GetPipelineResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetPipelineResponse -> GetPipelineResponse -> Bool
(GetPipelineResponse -> GetPipelineResponse -> Bool)
-> (GetPipelineResponse -> GetPipelineResponse -> Bool)
-> Eq GetPipelineResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetPipelineResponse -> GetPipelineResponse -> Bool
$c/= :: GetPipelineResponse -> GetPipelineResponse -> Bool
== :: GetPipelineResponse -> GetPipelineResponse -> Bool
$c== :: GetPipelineResponse -> GetPipelineResponse -> Bool
Prelude.Eq, ReadPrec [GetPipelineResponse]
ReadPrec GetPipelineResponse
Int -> ReadS GetPipelineResponse
ReadS [GetPipelineResponse]
(Int -> ReadS GetPipelineResponse)
-> ReadS [GetPipelineResponse]
-> ReadPrec GetPipelineResponse
-> ReadPrec [GetPipelineResponse]
-> Read GetPipelineResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetPipelineResponse]
$creadListPrec :: ReadPrec [GetPipelineResponse]
readPrec :: ReadPrec GetPipelineResponse
$creadPrec :: ReadPrec GetPipelineResponse
readList :: ReadS [GetPipelineResponse]
$creadList :: ReadS [GetPipelineResponse]
readsPrec :: Int -> ReadS GetPipelineResponse
$creadsPrec :: Int -> ReadS GetPipelineResponse
Prelude.Read, Int -> GetPipelineResponse -> ShowS
[GetPipelineResponse] -> ShowS
GetPipelineResponse -> String
(Int -> GetPipelineResponse -> ShowS)
-> (GetPipelineResponse -> String)
-> ([GetPipelineResponse] -> ShowS)
-> Show GetPipelineResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetPipelineResponse] -> ShowS
$cshowList :: [GetPipelineResponse] -> ShowS
show :: GetPipelineResponse -> String
$cshow :: GetPipelineResponse -> String
showsPrec :: Int -> GetPipelineResponse -> ShowS
$cshowsPrec :: Int -> GetPipelineResponse -> ShowS
Prelude.Show, (forall x. GetPipelineResponse -> Rep GetPipelineResponse x)
-> (forall x. Rep GetPipelineResponse x -> GetPipelineResponse)
-> Generic GetPipelineResponse
forall x. Rep GetPipelineResponse x -> GetPipelineResponse
forall x. GetPipelineResponse -> Rep GetPipelineResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetPipelineResponse x -> GetPipelineResponse
$cfrom :: forall x. GetPipelineResponse -> Rep GetPipelineResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetPipelineResponse' 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:
--
-- 'pipeline', 'getPipelineResponse_pipeline' - Represents the structure of actions and stages to be performed in the
-- pipeline.
--
-- 'metadata', 'getPipelineResponse_metadata' - Represents the pipeline metadata information returned as part of the
-- output of a @GetPipeline@ action.
--
-- 'httpStatus', 'getPipelineResponse_httpStatus' - The response's http status code.
newGetPipelineResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetPipelineResponse
newGetPipelineResponse :: Int -> GetPipelineResponse
newGetPipelineResponse Int
pHttpStatus_ =
  GetPipelineResponse' :: Maybe PipelineDeclaration
-> Maybe PipelineMetadata -> Int -> GetPipelineResponse
GetPipelineResponse'
    { $sel:pipeline:GetPipelineResponse' :: Maybe PipelineDeclaration
pipeline = Maybe PipelineDeclaration
forall a. Maybe a
Prelude.Nothing,
      $sel:metadata:GetPipelineResponse' :: Maybe PipelineMetadata
metadata = Maybe PipelineMetadata
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetPipelineResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Represents the structure of actions and stages to be performed in the
-- pipeline.
getPipelineResponse_pipeline :: Lens.Lens' GetPipelineResponse (Prelude.Maybe PipelineDeclaration)
getPipelineResponse_pipeline :: (Maybe PipelineDeclaration -> f (Maybe PipelineDeclaration))
-> GetPipelineResponse -> f GetPipelineResponse
getPipelineResponse_pipeline = (GetPipelineResponse -> Maybe PipelineDeclaration)
-> (GetPipelineResponse
    -> Maybe PipelineDeclaration -> GetPipelineResponse)
-> Lens
     GetPipelineResponse
     GetPipelineResponse
     (Maybe PipelineDeclaration)
     (Maybe PipelineDeclaration)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetPipelineResponse' {Maybe PipelineDeclaration
pipeline :: Maybe PipelineDeclaration
$sel:pipeline:GetPipelineResponse' :: GetPipelineResponse -> Maybe PipelineDeclaration
pipeline} -> Maybe PipelineDeclaration
pipeline) (\s :: GetPipelineResponse
s@GetPipelineResponse' {} Maybe PipelineDeclaration
a -> GetPipelineResponse
s {$sel:pipeline:GetPipelineResponse' :: Maybe PipelineDeclaration
pipeline = Maybe PipelineDeclaration
a} :: GetPipelineResponse)

-- | Represents the pipeline metadata information returned as part of the
-- output of a @GetPipeline@ action.
getPipelineResponse_metadata :: Lens.Lens' GetPipelineResponse (Prelude.Maybe PipelineMetadata)
getPipelineResponse_metadata :: (Maybe PipelineMetadata -> f (Maybe PipelineMetadata))
-> GetPipelineResponse -> f GetPipelineResponse
getPipelineResponse_metadata = (GetPipelineResponse -> Maybe PipelineMetadata)
-> (GetPipelineResponse
    -> Maybe PipelineMetadata -> GetPipelineResponse)
-> Lens
     GetPipelineResponse
     GetPipelineResponse
     (Maybe PipelineMetadata)
     (Maybe PipelineMetadata)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetPipelineResponse' {Maybe PipelineMetadata
metadata :: Maybe PipelineMetadata
$sel:metadata:GetPipelineResponse' :: GetPipelineResponse -> Maybe PipelineMetadata
metadata} -> Maybe PipelineMetadata
metadata) (\s :: GetPipelineResponse
s@GetPipelineResponse' {} Maybe PipelineMetadata
a -> GetPipelineResponse
s {$sel:metadata:GetPipelineResponse' :: Maybe PipelineMetadata
metadata = Maybe PipelineMetadata
a} :: GetPipelineResponse)

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

instance Prelude.NFData GetPipelineResponse