{-# 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.DescribeApps
-- 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 a specified set of apps.
--
-- 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.DescribeApps
  ( -- * Creating a Request
    DescribeApps (..),
    newDescribeApps,

    -- * Request Lenses
    describeApps_appIds,
    describeApps_stackId,

    -- * Destructuring the Response
    DescribeAppsResponse (..),
    newDescribeAppsResponse,

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

-- |
-- Create a value of 'DescribeApps' 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:
--
-- 'appIds', 'describeApps_appIds' - An array of app IDs for the apps to be described. If you use this
-- parameter, @DescribeApps@ returns a description of the specified apps.
-- Otherwise, it returns a description of every app.
--
-- 'stackId', 'describeApps_stackId' - The app stack ID. If you use this parameter, @DescribeApps@ returns a
-- description of the apps in the specified stack.
newDescribeApps ::
  DescribeApps
newDescribeApps :: DescribeApps
newDescribeApps =
  DescribeApps' :: Maybe [Text] -> Maybe Text -> DescribeApps
DescribeApps'
    { $sel:appIds:DescribeApps' :: Maybe [Text]
appIds = Maybe [Text]
forall a. Maybe a
Prelude.Nothing,
      $sel:stackId:DescribeApps' :: Maybe Text
stackId = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | An array of app IDs for the apps to be described. If you use this
-- parameter, @DescribeApps@ returns a description of the specified apps.
-- Otherwise, it returns a description of every app.
describeApps_appIds :: Lens.Lens' DescribeApps (Prelude.Maybe [Prelude.Text])
describeApps_appIds :: (Maybe [Text] -> f (Maybe [Text]))
-> DescribeApps -> f DescribeApps
describeApps_appIds = (DescribeApps -> Maybe [Text])
-> (DescribeApps -> Maybe [Text] -> DescribeApps)
-> Lens DescribeApps DescribeApps (Maybe [Text]) (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeApps' {Maybe [Text]
appIds :: Maybe [Text]
$sel:appIds:DescribeApps' :: DescribeApps -> Maybe [Text]
appIds} -> Maybe [Text]
appIds) (\s :: DescribeApps
s@DescribeApps' {} Maybe [Text]
a -> DescribeApps
s {$sel:appIds:DescribeApps' :: Maybe [Text]
appIds = Maybe [Text]
a} :: DescribeApps) ((Maybe [Text] -> f (Maybe [Text]))
 -> DescribeApps -> f DescribeApps)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> DescribeApps
-> f DescribeApps
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 app stack ID. If you use this parameter, @DescribeApps@ returns a
-- description of the apps in the specified stack.
describeApps_stackId :: Lens.Lens' DescribeApps (Prelude.Maybe Prelude.Text)
describeApps_stackId :: (Maybe Text -> f (Maybe Text)) -> DescribeApps -> f DescribeApps
describeApps_stackId = (DescribeApps -> Maybe Text)
-> (DescribeApps -> Maybe Text -> DescribeApps)
-> Lens DescribeApps DescribeApps (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeApps' {Maybe Text
stackId :: Maybe Text
$sel:stackId:DescribeApps' :: DescribeApps -> Maybe Text
stackId} -> Maybe Text
stackId) (\s :: DescribeApps
s@DescribeApps' {} Maybe Text
a -> DescribeApps
s {$sel:stackId:DescribeApps' :: Maybe Text
stackId = Maybe Text
a} :: DescribeApps)

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

instance Prelude.NFData DescribeApps

instance Core.ToHeaders DescribeApps where
  toHeaders :: DescribeApps -> ResponseHeaders
toHeaders =
    ResponseHeaders -> DescribeApps -> 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.DescribeApps" ::
                          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 DescribeApps where
  toJSON :: DescribeApps -> Value
toJSON DescribeApps' {Maybe [Text]
Maybe Text
stackId :: Maybe Text
appIds :: Maybe [Text]
$sel:stackId:DescribeApps' :: DescribeApps -> Maybe Text
$sel:appIds:DescribeApps' :: DescribeApps -> Maybe [Text]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"AppIds" 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]
appIds,
            (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 DescribeApps where
  toPath :: DescribeApps -> ByteString
toPath = ByteString -> DescribeApps -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

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

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

-- |
-- Create a value of 'DescribeAppsResponse' 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:
--
-- 'apps', 'describeAppsResponse_apps' - An array of @App@ objects that describe the specified apps.
--
-- 'httpStatus', 'describeAppsResponse_httpStatus' - The response's http status code.
newDescribeAppsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DescribeAppsResponse
newDescribeAppsResponse :: Int -> DescribeAppsResponse
newDescribeAppsResponse Int
pHttpStatus_ =
  DescribeAppsResponse' :: Maybe [App] -> Int -> DescribeAppsResponse
DescribeAppsResponse'
    { $sel:apps:DescribeAppsResponse' :: Maybe [App]
apps = Maybe [App]
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DescribeAppsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

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

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

instance Prelude.NFData DescribeAppsResponse