{-# 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.DescribeLayers
-- 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 layers in a specified stack.
--
-- This call accepts only one resource-identifying parameter.
--
-- __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.DescribeLayers
  ( -- * Creating a Request
    DescribeLayers (..),
    newDescribeLayers,

    -- * Request Lenses
    describeLayers_layerIds,
    describeLayers_stackId,

    -- * Destructuring the Response
    DescribeLayersResponse (..),
    newDescribeLayersResponse,

    -- * Response Lenses
    describeLayersResponse_layers,
    describeLayersResponse_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:/ 'newDescribeLayers' smart constructor.
data DescribeLayers = DescribeLayers'
  { -- | An array of layer IDs that specify the layers to be described. If you
    -- omit this parameter, @DescribeLayers@ returns a description of every
    -- layer in the specified stack.
    DescribeLayers -> Maybe [Text]
layerIds :: Prelude.Maybe [Prelude.Text],
    -- | The stack ID.
    DescribeLayers -> Maybe Text
stackId :: Prelude.Maybe Prelude.Text
  }
  deriving (DescribeLayers -> DescribeLayers -> Bool
(DescribeLayers -> DescribeLayers -> Bool)
-> (DescribeLayers -> DescribeLayers -> Bool) -> Eq DescribeLayers
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DescribeLayers -> DescribeLayers -> Bool
$c/= :: DescribeLayers -> DescribeLayers -> Bool
== :: DescribeLayers -> DescribeLayers -> Bool
$c== :: DescribeLayers -> DescribeLayers -> Bool
Prelude.Eq, ReadPrec [DescribeLayers]
ReadPrec DescribeLayers
Int -> ReadS DescribeLayers
ReadS [DescribeLayers]
(Int -> ReadS DescribeLayers)
-> ReadS [DescribeLayers]
-> ReadPrec DescribeLayers
-> ReadPrec [DescribeLayers]
-> Read DescribeLayers
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DescribeLayers]
$creadListPrec :: ReadPrec [DescribeLayers]
readPrec :: ReadPrec DescribeLayers
$creadPrec :: ReadPrec DescribeLayers
readList :: ReadS [DescribeLayers]
$creadList :: ReadS [DescribeLayers]
readsPrec :: Int -> ReadS DescribeLayers
$creadsPrec :: Int -> ReadS DescribeLayers
Prelude.Read, Int -> DescribeLayers -> ShowS
[DescribeLayers] -> ShowS
DescribeLayers -> String
(Int -> DescribeLayers -> ShowS)
-> (DescribeLayers -> String)
-> ([DescribeLayers] -> ShowS)
-> Show DescribeLayers
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DescribeLayers] -> ShowS
$cshowList :: [DescribeLayers] -> ShowS
show :: DescribeLayers -> String
$cshow :: DescribeLayers -> String
showsPrec :: Int -> DescribeLayers -> ShowS
$cshowsPrec :: Int -> DescribeLayers -> ShowS
Prelude.Show, (forall x. DescribeLayers -> Rep DescribeLayers x)
-> (forall x. Rep DescribeLayers x -> DescribeLayers)
-> Generic DescribeLayers
forall x. Rep DescribeLayers x -> DescribeLayers
forall x. DescribeLayers -> Rep DescribeLayers x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DescribeLayers x -> DescribeLayers
$cfrom :: forall x. DescribeLayers -> Rep DescribeLayers x
Prelude.Generic)

-- |
-- Create a value of 'DescribeLayers' 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:
--
-- 'layerIds', 'describeLayers_layerIds' - An array of layer IDs that specify the layers to be described. If you
-- omit this parameter, @DescribeLayers@ returns a description of every
-- layer in the specified stack.
--
-- 'stackId', 'describeLayers_stackId' - The stack ID.
newDescribeLayers ::
  DescribeLayers
newDescribeLayers :: DescribeLayers
newDescribeLayers =
  DescribeLayers' :: Maybe [Text] -> Maybe Text -> DescribeLayers
DescribeLayers'
    { $sel:layerIds:DescribeLayers' :: Maybe [Text]
layerIds = Maybe [Text]
forall a. Maybe a
Prelude.Nothing,
      $sel:stackId:DescribeLayers' :: Maybe Text
stackId = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | An array of layer IDs that specify the layers to be described. If you
-- omit this parameter, @DescribeLayers@ returns a description of every
-- layer in the specified stack.
describeLayers_layerIds :: Lens.Lens' DescribeLayers (Prelude.Maybe [Prelude.Text])
describeLayers_layerIds :: (Maybe [Text] -> f (Maybe [Text]))
-> DescribeLayers -> f DescribeLayers
describeLayers_layerIds = (DescribeLayers -> Maybe [Text])
-> (DescribeLayers -> Maybe [Text] -> DescribeLayers)
-> Lens DescribeLayers DescribeLayers (Maybe [Text]) (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeLayers' {Maybe [Text]
layerIds :: Maybe [Text]
$sel:layerIds:DescribeLayers' :: DescribeLayers -> Maybe [Text]
layerIds} -> Maybe [Text]
layerIds) (\s :: DescribeLayers
s@DescribeLayers' {} Maybe [Text]
a -> DescribeLayers
s {$sel:layerIds:DescribeLayers' :: Maybe [Text]
layerIds = Maybe [Text]
a} :: DescribeLayers) ((Maybe [Text] -> f (Maybe [Text]))
 -> DescribeLayers -> f DescribeLayers)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> DescribeLayers
-> f DescribeLayers
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

-- | The stack ID.
describeLayers_stackId :: Lens.Lens' DescribeLayers (Prelude.Maybe Prelude.Text)
describeLayers_stackId :: (Maybe Text -> f (Maybe Text))
-> DescribeLayers -> f DescribeLayers
describeLayers_stackId = (DescribeLayers -> Maybe Text)
-> (DescribeLayers -> Maybe Text -> DescribeLayers)
-> Lens DescribeLayers DescribeLayers (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeLayers' {Maybe Text
stackId :: Maybe Text
$sel:stackId:DescribeLayers' :: DescribeLayers -> Maybe Text
stackId} -> Maybe Text
stackId) (\s :: DescribeLayers
s@DescribeLayers' {} Maybe Text
a -> DescribeLayers
s {$sel:stackId:DescribeLayers' :: Maybe Text
stackId = Maybe Text
a} :: DescribeLayers)

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

instance Prelude.NFData DescribeLayers

instance Core.ToHeaders DescribeLayers where
  toHeaders :: DescribeLayers -> ResponseHeaders
toHeaders =
    ResponseHeaders -> DescribeLayers -> 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.DescribeLayers" ::
                          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 DescribeLayers where
  toJSON :: DescribeLayers -> Value
toJSON DescribeLayers' {Maybe [Text]
Maybe Text
stackId :: Maybe Text
layerIds :: Maybe [Text]
$sel:stackId:DescribeLayers' :: DescribeLayers -> Maybe Text
$sel:layerIds:DescribeLayers' :: DescribeLayers -> Maybe [Text]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"LayerIds" 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]
layerIds,
            (Text
"StackId" 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
stackId
          ]
      )

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

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

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

-- |
-- Create a value of 'DescribeLayersResponse' 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:
--
-- 'layers', 'describeLayersResponse_layers' - An array of @Layer@ objects that describe the layers.
--
-- 'httpStatus', 'describeLayersResponse_httpStatus' - The response's http status code.
newDescribeLayersResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DescribeLayersResponse
newDescribeLayersResponse :: Int -> DescribeLayersResponse
newDescribeLayersResponse Int
pHttpStatus_ =
  DescribeLayersResponse' :: Maybe [Layer] -> Int -> DescribeLayersResponse
DescribeLayersResponse'
    { $sel:layers:DescribeLayersResponse' :: Maybe [Layer]
layers = Maybe [Layer]
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DescribeLayersResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

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

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

instance Prelude.NFData DescribeLayersResponse