{-# 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.OpsWorks.DescribeStacks
-- 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)
--
-- Requests a description of one or more stacks.
--
-- __Required Permissions__: To use this action, an IAM user must have a
-- Show, Deploy, or Manage permissions level for the stack, or an attached
-- policy that explicitly grants permissions. For more information about
-- user permissions, see
-- <https://docs.aws.amazon.com/opsworks/latest/userguide/opsworks-security-users.html Managing User Permissions>.
module Amazonka.OpsWorks.DescribeStacks
  ( -- * Creating a Request
    DescribeStacks (..),
    newDescribeStacks,

    -- * Request Lenses
    describeStacks_stackIds,

    -- * Destructuring the Response
    DescribeStacksResponse (..),
    newDescribeStacksResponse,

    -- * Response Lenses
    describeStacksResponse_stacks,
    describeStacksResponse_httpStatus,
  )
where

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

-- | /See:/ 'newDescribeStacks' smart constructor.
data DescribeStacks = DescribeStacks'
  { -- | An array of stack IDs that specify the stacks to be described. If you
    -- omit this parameter, @DescribeStacks@ returns a description of every
    -- stack.
    DescribeStacks -> Maybe [Text]
stackIds :: Prelude.Maybe [Prelude.Text]
  }
  deriving (DescribeStacks -> DescribeStacks -> Bool
(DescribeStacks -> DescribeStacks -> Bool)
-> (DescribeStacks -> DescribeStacks -> Bool) -> Eq DescribeStacks
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DescribeStacks -> DescribeStacks -> Bool
$c/= :: DescribeStacks -> DescribeStacks -> Bool
== :: DescribeStacks -> DescribeStacks -> Bool
$c== :: DescribeStacks -> DescribeStacks -> Bool
Prelude.Eq, ReadPrec [DescribeStacks]
ReadPrec DescribeStacks
Int -> ReadS DescribeStacks
ReadS [DescribeStacks]
(Int -> ReadS DescribeStacks)
-> ReadS [DescribeStacks]
-> ReadPrec DescribeStacks
-> ReadPrec [DescribeStacks]
-> Read DescribeStacks
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DescribeStacks]
$creadListPrec :: ReadPrec [DescribeStacks]
readPrec :: ReadPrec DescribeStacks
$creadPrec :: ReadPrec DescribeStacks
readList :: ReadS [DescribeStacks]
$creadList :: ReadS [DescribeStacks]
readsPrec :: Int -> ReadS DescribeStacks
$creadsPrec :: Int -> ReadS DescribeStacks
Prelude.Read, Int -> DescribeStacks -> ShowS
[DescribeStacks] -> ShowS
DescribeStacks -> String
(Int -> DescribeStacks -> ShowS)
-> (DescribeStacks -> String)
-> ([DescribeStacks] -> ShowS)
-> Show DescribeStacks
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DescribeStacks] -> ShowS
$cshowList :: [DescribeStacks] -> ShowS
show :: DescribeStacks -> String
$cshow :: DescribeStacks -> String
showsPrec :: Int -> DescribeStacks -> ShowS
$cshowsPrec :: Int -> DescribeStacks -> ShowS
Prelude.Show, (forall x. DescribeStacks -> Rep DescribeStacks x)
-> (forall x. Rep DescribeStacks x -> DescribeStacks)
-> Generic DescribeStacks
forall x. Rep DescribeStacks x -> DescribeStacks
forall x. DescribeStacks -> Rep DescribeStacks x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DescribeStacks x -> DescribeStacks
$cfrom :: forall x. DescribeStacks -> Rep DescribeStacks x
Prelude.Generic)

-- |
-- Create a value of 'DescribeStacks' 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:
--
-- 'stackIds', 'describeStacks_stackIds' - An array of stack IDs that specify the stacks to be described. If you
-- omit this parameter, @DescribeStacks@ returns a description of every
-- stack.
newDescribeStacks ::
  DescribeStacks
newDescribeStacks :: DescribeStacks
newDescribeStacks =
  DescribeStacks' :: Maybe [Text] -> DescribeStacks
DescribeStacks' {$sel:stackIds:DescribeStacks' :: Maybe [Text]
stackIds = Maybe [Text]
forall a. Maybe a
Prelude.Nothing}

-- | An array of stack IDs that specify the stacks to be described. If you
-- omit this parameter, @DescribeStacks@ returns a description of every
-- stack.
describeStacks_stackIds :: Lens.Lens' DescribeStacks (Prelude.Maybe [Prelude.Text])
describeStacks_stackIds :: (Maybe [Text] -> f (Maybe [Text]))
-> DescribeStacks -> f DescribeStacks
describeStacks_stackIds = (DescribeStacks -> Maybe [Text])
-> (DescribeStacks -> Maybe [Text] -> DescribeStacks)
-> Lens DescribeStacks DescribeStacks (Maybe [Text]) (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeStacks' {Maybe [Text]
stackIds :: Maybe [Text]
$sel:stackIds:DescribeStacks' :: DescribeStacks -> Maybe [Text]
stackIds} -> Maybe [Text]
stackIds) (\s :: DescribeStacks
s@DescribeStacks' {} Maybe [Text]
a -> DescribeStacks
s {$sel:stackIds:DescribeStacks' :: Maybe [Text]
stackIds = Maybe [Text]
a} :: DescribeStacks) ((Maybe [Text] -> f (Maybe [Text]))
 -> DescribeStacks -> f DescribeStacks)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> DescribeStacks
-> f DescribeStacks
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Text] [Text] [Text] [Text]
-> Iso (Maybe [Text]) (Maybe [Text]) (Maybe [Text]) (Maybe [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 [Text] [Text] [Text] [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest DescribeStacks where
  type
    AWSResponse DescribeStacks =
      DescribeStacksResponse
  request :: DescribeStacks -> Request DescribeStacks
request = Service -> DescribeStacks -> Request DescribeStacks
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy DescribeStacks
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DescribeStacks)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse DescribeStacks))
-> Logger
-> Service
-> Proxy DescribeStacks
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DescribeStacks)))
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 [Stack] -> Int -> DescribeStacksResponse
DescribeStacksResponse'
            (Maybe [Stack] -> Int -> DescribeStacksResponse)
-> Either String (Maybe [Stack])
-> Either String (Int -> DescribeStacksResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe (Maybe [Stack]))
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"Stacks" Either String (Maybe (Maybe [Stack]))
-> Maybe [Stack] -> Either String (Maybe [Stack])
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ Maybe [Stack]
forall a. Monoid a => a
Prelude.mempty)
            Either String (Int -> DescribeStacksResponse)
-> Either String Int -> Either String DescribeStacksResponse
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 DescribeStacks

instance Prelude.NFData DescribeStacks

instance Core.ToHeaders DescribeStacks where
  toHeaders :: DescribeStacks -> ResponseHeaders
toHeaders =
    ResponseHeaders -> DescribeStacks -> 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
"OpsWorks_20130218.DescribeStacks" ::
                          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 DescribeStacks where
  toJSON :: DescribeStacks -> Value
toJSON DescribeStacks' {Maybe [Text]
stackIds :: Maybe [Text]
$sel:stackIds:DescribeStacks' :: DescribeStacks -> Maybe [Text]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [(Text
"StackIds" 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]
stackIds]
      )

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

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

-- | Contains the response to a @DescribeStacks@ request.
--
-- /See:/ 'newDescribeStacksResponse' smart constructor.
data DescribeStacksResponse = DescribeStacksResponse'
  { -- | An array of @Stack@ objects that describe the stacks.
    DescribeStacksResponse -> Maybe [Stack]
stacks :: Prelude.Maybe [Stack],
    -- | The response's http status code.
    DescribeStacksResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (DescribeStacksResponse -> DescribeStacksResponse -> Bool
(DescribeStacksResponse -> DescribeStacksResponse -> Bool)
-> (DescribeStacksResponse -> DescribeStacksResponse -> Bool)
-> Eq DescribeStacksResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DescribeStacksResponse -> DescribeStacksResponse -> Bool
$c/= :: DescribeStacksResponse -> DescribeStacksResponse -> Bool
== :: DescribeStacksResponse -> DescribeStacksResponse -> Bool
$c== :: DescribeStacksResponse -> DescribeStacksResponse -> Bool
Prelude.Eq, ReadPrec [DescribeStacksResponse]
ReadPrec DescribeStacksResponse
Int -> ReadS DescribeStacksResponse
ReadS [DescribeStacksResponse]
(Int -> ReadS DescribeStacksResponse)
-> ReadS [DescribeStacksResponse]
-> ReadPrec DescribeStacksResponse
-> ReadPrec [DescribeStacksResponse]
-> Read DescribeStacksResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DescribeStacksResponse]
$creadListPrec :: ReadPrec [DescribeStacksResponse]
readPrec :: ReadPrec DescribeStacksResponse
$creadPrec :: ReadPrec DescribeStacksResponse
readList :: ReadS [DescribeStacksResponse]
$creadList :: ReadS [DescribeStacksResponse]
readsPrec :: Int -> ReadS DescribeStacksResponse
$creadsPrec :: Int -> ReadS DescribeStacksResponse
Prelude.Read, Int -> DescribeStacksResponse -> ShowS
[DescribeStacksResponse] -> ShowS
DescribeStacksResponse -> String
(Int -> DescribeStacksResponse -> ShowS)
-> (DescribeStacksResponse -> String)
-> ([DescribeStacksResponse] -> ShowS)
-> Show DescribeStacksResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DescribeStacksResponse] -> ShowS
$cshowList :: [DescribeStacksResponse] -> ShowS
show :: DescribeStacksResponse -> String
$cshow :: DescribeStacksResponse -> String
showsPrec :: Int -> DescribeStacksResponse -> ShowS
$cshowsPrec :: Int -> DescribeStacksResponse -> ShowS
Prelude.Show, (forall x. DescribeStacksResponse -> Rep DescribeStacksResponse x)
-> (forall x.
    Rep DescribeStacksResponse x -> DescribeStacksResponse)
-> Generic DescribeStacksResponse
forall x. Rep DescribeStacksResponse x -> DescribeStacksResponse
forall x. DescribeStacksResponse -> Rep DescribeStacksResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DescribeStacksResponse x -> DescribeStacksResponse
$cfrom :: forall x. DescribeStacksResponse -> Rep DescribeStacksResponse x
Prelude.Generic)

-- |
-- Create a value of 'DescribeStacksResponse' 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:
--
-- 'stacks', 'describeStacksResponse_stacks' - An array of @Stack@ objects that describe the stacks.
--
-- 'httpStatus', 'describeStacksResponse_httpStatus' - The response's http status code.
newDescribeStacksResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DescribeStacksResponse
newDescribeStacksResponse :: Int -> DescribeStacksResponse
newDescribeStacksResponse Int
pHttpStatus_ =
  DescribeStacksResponse' :: Maybe [Stack] -> Int -> DescribeStacksResponse
DescribeStacksResponse'
    { $sel:stacks:DescribeStacksResponse' :: Maybe [Stack]
stacks = Maybe [Stack]
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DescribeStacksResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | An array of @Stack@ objects that describe the stacks.
describeStacksResponse_stacks :: Lens.Lens' DescribeStacksResponse (Prelude.Maybe [Stack])
describeStacksResponse_stacks :: (Maybe [Stack] -> f (Maybe [Stack]))
-> DescribeStacksResponse -> f DescribeStacksResponse
describeStacksResponse_stacks = (DescribeStacksResponse -> Maybe [Stack])
-> (DescribeStacksResponse
    -> Maybe [Stack] -> DescribeStacksResponse)
-> Lens
     DescribeStacksResponse
     DescribeStacksResponse
     (Maybe [Stack])
     (Maybe [Stack])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeStacksResponse' {Maybe [Stack]
stacks :: Maybe [Stack]
$sel:stacks:DescribeStacksResponse' :: DescribeStacksResponse -> Maybe [Stack]
stacks} -> Maybe [Stack]
stacks) (\s :: DescribeStacksResponse
s@DescribeStacksResponse' {} Maybe [Stack]
a -> DescribeStacksResponse
s {$sel:stacks:DescribeStacksResponse' :: Maybe [Stack]
stacks = Maybe [Stack]
a} :: DescribeStacksResponse) ((Maybe [Stack] -> f (Maybe [Stack]))
 -> DescribeStacksResponse -> f DescribeStacksResponse)
-> ((Maybe [Stack] -> f (Maybe [Stack]))
    -> Maybe [Stack] -> f (Maybe [Stack]))
-> (Maybe [Stack] -> f (Maybe [Stack]))
-> DescribeStacksResponse
-> f DescribeStacksResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Stack] [Stack] [Stack] [Stack]
-> Iso
     (Maybe [Stack]) (Maybe [Stack]) (Maybe [Stack]) (Maybe [Stack])
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 [Stack] [Stack] [Stack] [Stack]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.NFData DescribeStacksResponse