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

    -- * Request Lenses
    describePermissions_iamUserArn,
    describePermissions_stackId,

    -- * Destructuring the Response
    DescribePermissionsResponse (..),
    newDescribePermissionsResponse,

    -- * Response Lenses
    describePermissionsResponse_permissions,
    describePermissionsResponse_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:/ 'newDescribePermissions' smart constructor.
data DescribePermissions = DescribePermissions'
  { -- | The user\'s IAM ARN. This can also be a federated user\'s ARN. For more
    -- information about IAM ARNs, see
    -- <https://docs.aws.amazon.com/IAM/latest/UserGuide/Using_Identifiers.html Using Identifiers>.
    DescribePermissions -> Maybe Text
iamUserArn :: Prelude.Maybe Prelude.Text,
    -- | The stack ID.
    DescribePermissions -> Maybe Text
stackId :: Prelude.Maybe Prelude.Text
  }
  deriving (DescribePermissions -> DescribePermissions -> Bool
(DescribePermissions -> DescribePermissions -> Bool)
-> (DescribePermissions -> DescribePermissions -> Bool)
-> Eq DescribePermissions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DescribePermissions -> DescribePermissions -> Bool
$c/= :: DescribePermissions -> DescribePermissions -> Bool
== :: DescribePermissions -> DescribePermissions -> Bool
$c== :: DescribePermissions -> DescribePermissions -> Bool
Prelude.Eq, ReadPrec [DescribePermissions]
ReadPrec DescribePermissions
Int -> ReadS DescribePermissions
ReadS [DescribePermissions]
(Int -> ReadS DescribePermissions)
-> ReadS [DescribePermissions]
-> ReadPrec DescribePermissions
-> ReadPrec [DescribePermissions]
-> Read DescribePermissions
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DescribePermissions]
$creadListPrec :: ReadPrec [DescribePermissions]
readPrec :: ReadPrec DescribePermissions
$creadPrec :: ReadPrec DescribePermissions
readList :: ReadS [DescribePermissions]
$creadList :: ReadS [DescribePermissions]
readsPrec :: Int -> ReadS DescribePermissions
$creadsPrec :: Int -> ReadS DescribePermissions
Prelude.Read, Int -> DescribePermissions -> ShowS
[DescribePermissions] -> ShowS
DescribePermissions -> String
(Int -> DescribePermissions -> ShowS)
-> (DescribePermissions -> String)
-> ([DescribePermissions] -> ShowS)
-> Show DescribePermissions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DescribePermissions] -> ShowS
$cshowList :: [DescribePermissions] -> ShowS
show :: DescribePermissions -> String
$cshow :: DescribePermissions -> String
showsPrec :: Int -> DescribePermissions -> ShowS
$cshowsPrec :: Int -> DescribePermissions -> ShowS
Prelude.Show, (forall x. DescribePermissions -> Rep DescribePermissions x)
-> (forall x. Rep DescribePermissions x -> DescribePermissions)
-> Generic DescribePermissions
forall x. Rep DescribePermissions x -> DescribePermissions
forall x. DescribePermissions -> Rep DescribePermissions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DescribePermissions x -> DescribePermissions
$cfrom :: forall x. DescribePermissions -> Rep DescribePermissions x
Prelude.Generic)

-- |
-- Create a value of 'DescribePermissions' 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:
--
-- 'iamUserArn', 'describePermissions_iamUserArn' - The user\'s IAM ARN. This can also be a federated user\'s ARN. For more
-- information about IAM ARNs, see
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/Using_Identifiers.html Using Identifiers>.
--
-- 'stackId', 'describePermissions_stackId' - The stack ID.
newDescribePermissions ::
  DescribePermissions
newDescribePermissions :: DescribePermissions
newDescribePermissions =
  DescribePermissions' :: Maybe Text -> Maybe Text -> DescribePermissions
DescribePermissions'
    { $sel:iamUserArn:DescribePermissions' :: Maybe Text
iamUserArn = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:stackId:DescribePermissions' :: Maybe Text
stackId = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The user\'s IAM ARN. This can also be a federated user\'s ARN. For more
-- information about IAM ARNs, see
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/Using_Identifiers.html Using Identifiers>.
describePermissions_iamUserArn :: Lens.Lens' DescribePermissions (Prelude.Maybe Prelude.Text)
describePermissions_iamUserArn :: (Maybe Text -> f (Maybe Text))
-> DescribePermissions -> f DescribePermissions
describePermissions_iamUserArn = (DescribePermissions -> Maybe Text)
-> (DescribePermissions -> Maybe Text -> DescribePermissions)
-> Lens
     DescribePermissions DescribePermissions (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribePermissions' {Maybe Text
iamUserArn :: Maybe Text
$sel:iamUserArn:DescribePermissions' :: DescribePermissions -> Maybe Text
iamUserArn} -> Maybe Text
iamUserArn) (\s :: DescribePermissions
s@DescribePermissions' {} Maybe Text
a -> DescribePermissions
s {$sel:iamUserArn:DescribePermissions' :: Maybe Text
iamUserArn = Maybe Text
a} :: DescribePermissions)

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

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

instance Prelude.NFData DescribePermissions

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

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

-- | Contains the response to a @DescribePermissions@ request.
--
-- /See:/ 'newDescribePermissionsResponse' smart constructor.
data DescribePermissionsResponse = DescribePermissionsResponse'
  { -- | An array of @Permission@ objects that describe the stack permissions.
    --
    -- -   If the request object contains only a stack ID, the array contains a
    --     @Permission@ object with permissions for each of the stack IAM ARNs.
    --
    -- -   If the request object contains only an IAM ARN, the array contains a
    --     @Permission@ object with permissions for each of the user\'s stack
    --     IDs.
    --
    -- -   If the request contains a stack ID and an IAM ARN, the array
    --     contains a single @Permission@ object with permissions for the
    --     specified stack and IAM ARN.
    DescribePermissionsResponse -> Maybe [Permission]
permissions :: Prelude.Maybe [Permission],
    -- | The response's http status code.
    DescribePermissionsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (DescribePermissionsResponse -> DescribePermissionsResponse -> Bool
(DescribePermissionsResponse
 -> DescribePermissionsResponse -> Bool)
-> (DescribePermissionsResponse
    -> DescribePermissionsResponse -> Bool)
-> Eq DescribePermissionsResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DescribePermissionsResponse -> DescribePermissionsResponse -> Bool
$c/= :: DescribePermissionsResponse -> DescribePermissionsResponse -> Bool
== :: DescribePermissionsResponse -> DescribePermissionsResponse -> Bool
$c== :: DescribePermissionsResponse -> DescribePermissionsResponse -> Bool
Prelude.Eq, ReadPrec [DescribePermissionsResponse]
ReadPrec DescribePermissionsResponse
Int -> ReadS DescribePermissionsResponse
ReadS [DescribePermissionsResponse]
(Int -> ReadS DescribePermissionsResponse)
-> ReadS [DescribePermissionsResponse]
-> ReadPrec DescribePermissionsResponse
-> ReadPrec [DescribePermissionsResponse]
-> Read DescribePermissionsResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DescribePermissionsResponse]
$creadListPrec :: ReadPrec [DescribePermissionsResponse]
readPrec :: ReadPrec DescribePermissionsResponse
$creadPrec :: ReadPrec DescribePermissionsResponse
readList :: ReadS [DescribePermissionsResponse]
$creadList :: ReadS [DescribePermissionsResponse]
readsPrec :: Int -> ReadS DescribePermissionsResponse
$creadsPrec :: Int -> ReadS DescribePermissionsResponse
Prelude.Read, Int -> DescribePermissionsResponse -> ShowS
[DescribePermissionsResponse] -> ShowS
DescribePermissionsResponse -> String
(Int -> DescribePermissionsResponse -> ShowS)
-> (DescribePermissionsResponse -> String)
-> ([DescribePermissionsResponse] -> ShowS)
-> Show DescribePermissionsResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DescribePermissionsResponse] -> ShowS
$cshowList :: [DescribePermissionsResponse] -> ShowS
show :: DescribePermissionsResponse -> String
$cshow :: DescribePermissionsResponse -> String
showsPrec :: Int -> DescribePermissionsResponse -> ShowS
$cshowsPrec :: Int -> DescribePermissionsResponse -> ShowS
Prelude.Show, (forall x.
 DescribePermissionsResponse -> Rep DescribePermissionsResponse x)
-> (forall x.
    Rep DescribePermissionsResponse x -> DescribePermissionsResponse)
-> Generic DescribePermissionsResponse
forall x.
Rep DescribePermissionsResponse x -> DescribePermissionsResponse
forall x.
DescribePermissionsResponse -> Rep DescribePermissionsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep DescribePermissionsResponse x -> DescribePermissionsResponse
$cfrom :: forall x.
DescribePermissionsResponse -> Rep DescribePermissionsResponse x
Prelude.Generic)

-- |
-- Create a value of 'DescribePermissionsResponse' 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:
--
-- 'permissions', 'describePermissionsResponse_permissions' - An array of @Permission@ objects that describe the stack permissions.
--
-- -   If the request object contains only a stack ID, the array contains a
--     @Permission@ object with permissions for each of the stack IAM ARNs.
--
-- -   If the request object contains only an IAM ARN, the array contains a
--     @Permission@ object with permissions for each of the user\'s stack
--     IDs.
--
-- -   If the request contains a stack ID and an IAM ARN, the array
--     contains a single @Permission@ object with permissions for the
--     specified stack and IAM ARN.
--
-- 'httpStatus', 'describePermissionsResponse_httpStatus' - The response's http status code.
newDescribePermissionsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DescribePermissionsResponse
newDescribePermissionsResponse :: Int -> DescribePermissionsResponse
newDescribePermissionsResponse Int
pHttpStatus_ =
  DescribePermissionsResponse' :: Maybe [Permission] -> Int -> DescribePermissionsResponse
DescribePermissionsResponse'
    { $sel:permissions:DescribePermissionsResponse' :: Maybe [Permission]
permissions =
        Maybe [Permission]
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DescribePermissionsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | An array of @Permission@ objects that describe the stack permissions.
--
-- -   If the request object contains only a stack ID, the array contains a
--     @Permission@ object with permissions for each of the stack IAM ARNs.
--
-- -   If the request object contains only an IAM ARN, the array contains a
--     @Permission@ object with permissions for each of the user\'s stack
--     IDs.
--
-- -   If the request contains a stack ID and an IAM ARN, the array
--     contains a single @Permission@ object with permissions for the
--     specified stack and IAM ARN.
describePermissionsResponse_permissions :: Lens.Lens' DescribePermissionsResponse (Prelude.Maybe [Permission])
describePermissionsResponse_permissions :: (Maybe [Permission] -> f (Maybe [Permission]))
-> DescribePermissionsResponse -> f DescribePermissionsResponse
describePermissionsResponse_permissions = (DescribePermissionsResponse -> Maybe [Permission])
-> (DescribePermissionsResponse
    -> Maybe [Permission] -> DescribePermissionsResponse)
-> Lens
     DescribePermissionsResponse
     DescribePermissionsResponse
     (Maybe [Permission])
     (Maybe [Permission])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribePermissionsResponse' {Maybe [Permission]
permissions :: Maybe [Permission]
$sel:permissions:DescribePermissionsResponse' :: DescribePermissionsResponse -> Maybe [Permission]
permissions} -> Maybe [Permission]
permissions) (\s :: DescribePermissionsResponse
s@DescribePermissionsResponse' {} Maybe [Permission]
a -> DescribePermissionsResponse
s {$sel:permissions:DescribePermissionsResponse' :: Maybe [Permission]
permissions = Maybe [Permission]
a} :: DescribePermissionsResponse) ((Maybe [Permission] -> f (Maybe [Permission]))
 -> DescribePermissionsResponse -> f DescribePermissionsResponse)
-> ((Maybe [Permission] -> f (Maybe [Permission]))
    -> Maybe [Permission] -> f (Maybe [Permission]))
-> (Maybe [Permission] -> f (Maybe [Permission]))
-> DescribePermissionsResponse
-> f DescribePermissionsResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Permission] [Permission] [Permission] [Permission]
-> Iso
     (Maybe [Permission])
     (Maybe [Permission])
     (Maybe [Permission])
     (Maybe [Permission])
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 [Permission] [Permission] [Permission] [Permission]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.NFData DescribePermissionsResponse