{-# 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.Greengrass.GetAssociatedRole
-- 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)
--
-- Retrieves the role associated with a particular group.
module Amazonka.Greengrass.GetAssociatedRole
  ( -- * Creating a Request
    GetAssociatedRole (..),
    newGetAssociatedRole,

    -- * Request Lenses
    getAssociatedRole_groupId,

    -- * Destructuring the Response
    GetAssociatedRoleResponse (..),
    newGetAssociatedRoleResponse,

    -- * Response Lenses
    getAssociatedRoleResponse_associatedAt,
    getAssociatedRoleResponse_roleArn,
    getAssociatedRoleResponse_httpStatus,
  )
where

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

-- | /See:/ 'newGetAssociatedRole' smart constructor.
data GetAssociatedRole = GetAssociatedRole'
  { -- | The ID of the Greengrass group.
    GetAssociatedRole -> Text
groupId :: Prelude.Text
  }
  deriving (GetAssociatedRole -> GetAssociatedRole -> Bool
(GetAssociatedRole -> GetAssociatedRole -> Bool)
-> (GetAssociatedRole -> GetAssociatedRole -> Bool)
-> Eq GetAssociatedRole
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetAssociatedRole -> GetAssociatedRole -> Bool
$c/= :: GetAssociatedRole -> GetAssociatedRole -> Bool
== :: GetAssociatedRole -> GetAssociatedRole -> Bool
$c== :: GetAssociatedRole -> GetAssociatedRole -> Bool
Prelude.Eq, ReadPrec [GetAssociatedRole]
ReadPrec GetAssociatedRole
Int -> ReadS GetAssociatedRole
ReadS [GetAssociatedRole]
(Int -> ReadS GetAssociatedRole)
-> ReadS [GetAssociatedRole]
-> ReadPrec GetAssociatedRole
-> ReadPrec [GetAssociatedRole]
-> Read GetAssociatedRole
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetAssociatedRole]
$creadListPrec :: ReadPrec [GetAssociatedRole]
readPrec :: ReadPrec GetAssociatedRole
$creadPrec :: ReadPrec GetAssociatedRole
readList :: ReadS [GetAssociatedRole]
$creadList :: ReadS [GetAssociatedRole]
readsPrec :: Int -> ReadS GetAssociatedRole
$creadsPrec :: Int -> ReadS GetAssociatedRole
Prelude.Read, Int -> GetAssociatedRole -> ShowS
[GetAssociatedRole] -> ShowS
GetAssociatedRole -> String
(Int -> GetAssociatedRole -> ShowS)
-> (GetAssociatedRole -> String)
-> ([GetAssociatedRole] -> ShowS)
-> Show GetAssociatedRole
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetAssociatedRole] -> ShowS
$cshowList :: [GetAssociatedRole] -> ShowS
show :: GetAssociatedRole -> String
$cshow :: GetAssociatedRole -> String
showsPrec :: Int -> GetAssociatedRole -> ShowS
$cshowsPrec :: Int -> GetAssociatedRole -> ShowS
Prelude.Show, (forall x. GetAssociatedRole -> Rep GetAssociatedRole x)
-> (forall x. Rep GetAssociatedRole x -> GetAssociatedRole)
-> Generic GetAssociatedRole
forall x. Rep GetAssociatedRole x -> GetAssociatedRole
forall x. GetAssociatedRole -> Rep GetAssociatedRole x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetAssociatedRole x -> GetAssociatedRole
$cfrom :: forall x. GetAssociatedRole -> Rep GetAssociatedRole x
Prelude.Generic)

-- |
-- Create a value of 'GetAssociatedRole' 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:
--
-- 'groupId', 'getAssociatedRole_groupId' - The ID of the Greengrass group.
newGetAssociatedRole ::
  -- | 'groupId'
  Prelude.Text ->
  GetAssociatedRole
newGetAssociatedRole :: Text -> GetAssociatedRole
newGetAssociatedRole Text
pGroupId_ =
  GetAssociatedRole' :: Text -> GetAssociatedRole
GetAssociatedRole' {$sel:groupId:GetAssociatedRole' :: Text
groupId = Text
pGroupId_}

-- | The ID of the Greengrass group.
getAssociatedRole_groupId :: Lens.Lens' GetAssociatedRole Prelude.Text
getAssociatedRole_groupId :: (Text -> f Text) -> GetAssociatedRole -> f GetAssociatedRole
getAssociatedRole_groupId = (GetAssociatedRole -> Text)
-> (GetAssociatedRole -> Text -> GetAssociatedRole)
-> Lens GetAssociatedRole GetAssociatedRole Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetAssociatedRole' {Text
groupId :: Text
$sel:groupId:GetAssociatedRole' :: GetAssociatedRole -> Text
groupId} -> Text
groupId) (\s :: GetAssociatedRole
s@GetAssociatedRole' {} Text
a -> GetAssociatedRole
s {$sel:groupId:GetAssociatedRole' :: Text
groupId = Text
a} :: GetAssociatedRole)

instance Core.AWSRequest GetAssociatedRole where
  type
    AWSResponse GetAssociatedRole =
      GetAssociatedRoleResponse
  request :: GetAssociatedRole -> Request GetAssociatedRole
request = Service -> GetAssociatedRole -> Request GetAssociatedRole
forall a. ToRequest a => Service -> a -> Request a
Request.get Service
defaultService
  response :: Logger
-> Service
-> Proxy GetAssociatedRole
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetAssociatedRole)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetAssociatedRole))
-> Logger
-> Service
-> Proxy GetAssociatedRole
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetAssociatedRole)))
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 Text -> Maybe Text -> Int -> GetAssociatedRoleResponse
GetAssociatedRoleResponse'
            (Maybe Text -> Maybe Text -> Int -> GetAssociatedRoleResponse)
-> Either String (Maybe Text)
-> Either String (Maybe Text -> Int -> GetAssociatedRoleResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"AssociatedAt")
            Either String (Maybe Text -> Int -> GetAssociatedRoleResponse)
-> Either String (Maybe Text)
-> Either String (Int -> GetAssociatedRoleResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"RoleArn")
            Either String (Int -> GetAssociatedRoleResponse)
-> Either String Int -> Either String GetAssociatedRoleResponse
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 GetAssociatedRole

instance Prelude.NFData GetAssociatedRole

instance Core.ToHeaders GetAssociatedRole where
  toHeaders :: GetAssociatedRole -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetAssociatedRole -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ 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.ToPath GetAssociatedRole where
  toPath :: GetAssociatedRole -> ByteString
toPath GetAssociatedRole' {Text
groupId :: Text
$sel:groupId:GetAssociatedRole' :: GetAssociatedRole -> Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/greengrass/groups/", Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
groupId, ByteString
"/role"]

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

-- | /See:/ 'newGetAssociatedRoleResponse' smart constructor.
data GetAssociatedRoleResponse = GetAssociatedRoleResponse'
  { -- | The time when the role was associated with the group.
    GetAssociatedRoleResponse -> Maybe Text
associatedAt :: Prelude.Maybe Prelude.Text,
    -- | The ARN of the role that is associated with the group.
    GetAssociatedRoleResponse -> Maybe Text
roleArn :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    GetAssociatedRoleResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetAssociatedRoleResponse -> GetAssociatedRoleResponse -> Bool
(GetAssociatedRoleResponse -> GetAssociatedRoleResponse -> Bool)
-> (GetAssociatedRoleResponse -> GetAssociatedRoleResponse -> Bool)
-> Eq GetAssociatedRoleResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetAssociatedRoleResponse -> GetAssociatedRoleResponse -> Bool
$c/= :: GetAssociatedRoleResponse -> GetAssociatedRoleResponse -> Bool
== :: GetAssociatedRoleResponse -> GetAssociatedRoleResponse -> Bool
$c== :: GetAssociatedRoleResponse -> GetAssociatedRoleResponse -> Bool
Prelude.Eq, ReadPrec [GetAssociatedRoleResponse]
ReadPrec GetAssociatedRoleResponse
Int -> ReadS GetAssociatedRoleResponse
ReadS [GetAssociatedRoleResponse]
(Int -> ReadS GetAssociatedRoleResponse)
-> ReadS [GetAssociatedRoleResponse]
-> ReadPrec GetAssociatedRoleResponse
-> ReadPrec [GetAssociatedRoleResponse]
-> Read GetAssociatedRoleResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetAssociatedRoleResponse]
$creadListPrec :: ReadPrec [GetAssociatedRoleResponse]
readPrec :: ReadPrec GetAssociatedRoleResponse
$creadPrec :: ReadPrec GetAssociatedRoleResponse
readList :: ReadS [GetAssociatedRoleResponse]
$creadList :: ReadS [GetAssociatedRoleResponse]
readsPrec :: Int -> ReadS GetAssociatedRoleResponse
$creadsPrec :: Int -> ReadS GetAssociatedRoleResponse
Prelude.Read, Int -> GetAssociatedRoleResponse -> ShowS
[GetAssociatedRoleResponse] -> ShowS
GetAssociatedRoleResponse -> String
(Int -> GetAssociatedRoleResponse -> ShowS)
-> (GetAssociatedRoleResponse -> String)
-> ([GetAssociatedRoleResponse] -> ShowS)
-> Show GetAssociatedRoleResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetAssociatedRoleResponse] -> ShowS
$cshowList :: [GetAssociatedRoleResponse] -> ShowS
show :: GetAssociatedRoleResponse -> String
$cshow :: GetAssociatedRoleResponse -> String
showsPrec :: Int -> GetAssociatedRoleResponse -> ShowS
$cshowsPrec :: Int -> GetAssociatedRoleResponse -> ShowS
Prelude.Show, (forall x.
 GetAssociatedRoleResponse -> Rep GetAssociatedRoleResponse x)
-> (forall x.
    Rep GetAssociatedRoleResponse x -> GetAssociatedRoleResponse)
-> Generic GetAssociatedRoleResponse
forall x.
Rep GetAssociatedRoleResponse x -> GetAssociatedRoleResponse
forall x.
GetAssociatedRoleResponse -> Rep GetAssociatedRoleResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetAssociatedRoleResponse x -> GetAssociatedRoleResponse
$cfrom :: forall x.
GetAssociatedRoleResponse -> Rep GetAssociatedRoleResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetAssociatedRoleResponse' 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:
--
-- 'associatedAt', 'getAssociatedRoleResponse_associatedAt' - The time when the role was associated with the group.
--
-- 'roleArn', 'getAssociatedRoleResponse_roleArn' - The ARN of the role that is associated with the group.
--
-- 'httpStatus', 'getAssociatedRoleResponse_httpStatus' - The response's http status code.
newGetAssociatedRoleResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetAssociatedRoleResponse
newGetAssociatedRoleResponse :: Int -> GetAssociatedRoleResponse
newGetAssociatedRoleResponse Int
pHttpStatus_ =
  GetAssociatedRoleResponse' :: Maybe Text -> Maybe Text -> Int -> GetAssociatedRoleResponse
GetAssociatedRoleResponse'
    { $sel:associatedAt:GetAssociatedRoleResponse' :: Maybe Text
associatedAt =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:roleArn:GetAssociatedRoleResponse' :: Maybe Text
roleArn = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetAssociatedRoleResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The time when the role was associated with the group.
getAssociatedRoleResponse_associatedAt :: Lens.Lens' GetAssociatedRoleResponse (Prelude.Maybe Prelude.Text)
getAssociatedRoleResponse_associatedAt :: (Maybe Text -> f (Maybe Text))
-> GetAssociatedRoleResponse -> f GetAssociatedRoleResponse
getAssociatedRoleResponse_associatedAt = (GetAssociatedRoleResponse -> Maybe Text)
-> (GetAssociatedRoleResponse
    -> Maybe Text -> GetAssociatedRoleResponse)
-> Lens
     GetAssociatedRoleResponse
     GetAssociatedRoleResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetAssociatedRoleResponse' {Maybe Text
associatedAt :: Maybe Text
$sel:associatedAt:GetAssociatedRoleResponse' :: GetAssociatedRoleResponse -> Maybe Text
associatedAt} -> Maybe Text
associatedAt) (\s :: GetAssociatedRoleResponse
s@GetAssociatedRoleResponse' {} Maybe Text
a -> GetAssociatedRoleResponse
s {$sel:associatedAt:GetAssociatedRoleResponse' :: Maybe Text
associatedAt = Maybe Text
a} :: GetAssociatedRoleResponse)

-- | The ARN of the role that is associated with the group.
getAssociatedRoleResponse_roleArn :: Lens.Lens' GetAssociatedRoleResponse (Prelude.Maybe Prelude.Text)
getAssociatedRoleResponse_roleArn :: (Maybe Text -> f (Maybe Text))
-> GetAssociatedRoleResponse -> f GetAssociatedRoleResponse
getAssociatedRoleResponse_roleArn = (GetAssociatedRoleResponse -> Maybe Text)
-> (GetAssociatedRoleResponse
    -> Maybe Text -> GetAssociatedRoleResponse)
-> Lens
     GetAssociatedRoleResponse
     GetAssociatedRoleResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetAssociatedRoleResponse' {Maybe Text
roleArn :: Maybe Text
$sel:roleArn:GetAssociatedRoleResponse' :: GetAssociatedRoleResponse -> Maybe Text
roleArn} -> Maybe Text
roleArn) (\s :: GetAssociatedRoleResponse
s@GetAssociatedRoleResponse' {} Maybe Text
a -> GetAssociatedRoleResponse
s {$sel:roleArn:GetAssociatedRoleResponse' :: Maybe Text
roleArn = Maybe Text
a} :: GetAssociatedRoleResponse)

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

instance Prelude.NFData GetAssociatedRoleResponse