{-# 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.EMR.GetClusterSessionCredentials
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Provides Temporary, basic HTTP credentials that are associated with a
-- given runtime IAM role and used by a cluster with fine-grained access
-- control activated. You can use these credentials to connect to cluster
-- endpoints that support username-based and password-based authentication.
module Amazonka.EMR.GetClusterSessionCredentials
  ( -- * Creating a Request
    GetClusterSessionCredentials (..),
    newGetClusterSessionCredentials,

    -- * Request Lenses
    getClusterSessionCredentials_clusterId,
    getClusterSessionCredentials_executionRoleArn,

    -- * Destructuring the Response
    GetClusterSessionCredentialsResponse (..),
    newGetClusterSessionCredentialsResponse,

    -- * Response Lenses
    getClusterSessionCredentialsResponse_credentials,
    getClusterSessionCredentialsResponse_expiresAt,
    getClusterSessionCredentialsResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.EMR.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newGetClusterSessionCredentials' smart constructor.
data GetClusterSessionCredentials = GetClusterSessionCredentials'
  { -- | The unique identifier of the cluster.
    GetClusterSessionCredentials -> Text
clusterId :: Prelude.Text,
    -- | The Amazon Resource Name (ARN) of the runtime role for interactive
    -- workload submission on the cluster. The runtime role can be a
    -- cross-account IAM role. The runtime role ARN is a combination of account
    -- ID, role name, and role type using the following format:
    -- @arn:partition:service:region:account:resource@.
    GetClusterSessionCredentials -> Text
executionRoleArn :: Prelude.Text
  }
  deriving (GetClusterSessionCredentials
-> GetClusterSessionCredentials -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetClusterSessionCredentials
-> GetClusterSessionCredentials -> Bool
$c/= :: GetClusterSessionCredentials
-> GetClusterSessionCredentials -> Bool
== :: GetClusterSessionCredentials
-> GetClusterSessionCredentials -> Bool
$c== :: GetClusterSessionCredentials
-> GetClusterSessionCredentials -> Bool
Prelude.Eq, ReadPrec [GetClusterSessionCredentials]
ReadPrec GetClusterSessionCredentials
Int -> ReadS GetClusterSessionCredentials
ReadS [GetClusterSessionCredentials]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetClusterSessionCredentials]
$creadListPrec :: ReadPrec [GetClusterSessionCredentials]
readPrec :: ReadPrec GetClusterSessionCredentials
$creadPrec :: ReadPrec GetClusterSessionCredentials
readList :: ReadS [GetClusterSessionCredentials]
$creadList :: ReadS [GetClusterSessionCredentials]
readsPrec :: Int -> ReadS GetClusterSessionCredentials
$creadsPrec :: Int -> ReadS GetClusterSessionCredentials
Prelude.Read, Int -> GetClusterSessionCredentials -> ShowS
[GetClusterSessionCredentials] -> ShowS
GetClusterSessionCredentials -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetClusterSessionCredentials] -> ShowS
$cshowList :: [GetClusterSessionCredentials] -> ShowS
show :: GetClusterSessionCredentials -> String
$cshow :: GetClusterSessionCredentials -> String
showsPrec :: Int -> GetClusterSessionCredentials -> ShowS
$cshowsPrec :: Int -> GetClusterSessionCredentials -> ShowS
Prelude.Show, forall x.
Rep GetClusterSessionCredentials x -> GetClusterSessionCredentials
forall x.
GetClusterSessionCredentials -> Rep GetClusterSessionCredentials x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetClusterSessionCredentials x -> GetClusterSessionCredentials
$cfrom :: forall x.
GetClusterSessionCredentials -> Rep GetClusterSessionCredentials x
Prelude.Generic)

-- |
-- Create a value of 'GetClusterSessionCredentials' 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:
--
-- 'clusterId', 'getClusterSessionCredentials_clusterId' - The unique identifier of the cluster.
--
-- 'executionRoleArn', 'getClusterSessionCredentials_executionRoleArn' - The Amazon Resource Name (ARN) of the runtime role for interactive
-- workload submission on the cluster. The runtime role can be a
-- cross-account IAM role. The runtime role ARN is a combination of account
-- ID, role name, and role type using the following format:
-- @arn:partition:service:region:account:resource@.
newGetClusterSessionCredentials ::
  -- | 'clusterId'
  Prelude.Text ->
  -- | 'executionRoleArn'
  Prelude.Text ->
  GetClusterSessionCredentials
newGetClusterSessionCredentials :: Text -> Text -> GetClusterSessionCredentials
newGetClusterSessionCredentials
  Text
pClusterId_
  Text
pExecutionRoleArn_ =
    GetClusterSessionCredentials'
      { $sel:clusterId:GetClusterSessionCredentials' :: Text
clusterId =
          Text
pClusterId_,
        $sel:executionRoleArn:GetClusterSessionCredentials' :: Text
executionRoleArn = Text
pExecutionRoleArn_
      }

-- | The unique identifier of the cluster.
getClusterSessionCredentials_clusterId :: Lens.Lens' GetClusterSessionCredentials Prelude.Text
getClusterSessionCredentials_clusterId :: Lens' GetClusterSessionCredentials Text
getClusterSessionCredentials_clusterId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetClusterSessionCredentials' {Text
clusterId :: Text
$sel:clusterId:GetClusterSessionCredentials' :: GetClusterSessionCredentials -> Text
clusterId} -> Text
clusterId) (\s :: GetClusterSessionCredentials
s@GetClusterSessionCredentials' {} Text
a -> GetClusterSessionCredentials
s {$sel:clusterId:GetClusterSessionCredentials' :: Text
clusterId = Text
a} :: GetClusterSessionCredentials)

-- | The Amazon Resource Name (ARN) of the runtime role for interactive
-- workload submission on the cluster. The runtime role can be a
-- cross-account IAM role. The runtime role ARN is a combination of account
-- ID, role name, and role type using the following format:
-- @arn:partition:service:region:account:resource@.
getClusterSessionCredentials_executionRoleArn :: Lens.Lens' GetClusterSessionCredentials Prelude.Text
getClusterSessionCredentials_executionRoleArn :: Lens' GetClusterSessionCredentials Text
getClusterSessionCredentials_executionRoleArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetClusterSessionCredentials' {Text
executionRoleArn :: Text
$sel:executionRoleArn:GetClusterSessionCredentials' :: GetClusterSessionCredentials -> Text
executionRoleArn} -> Text
executionRoleArn) (\s :: GetClusterSessionCredentials
s@GetClusterSessionCredentials' {} Text
a -> GetClusterSessionCredentials
s {$sel:executionRoleArn:GetClusterSessionCredentials' :: Text
executionRoleArn = Text
a} :: GetClusterSessionCredentials)

instance Core.AWSRequest GetClusterSessionCredentials where
  type
    AWSResponse GetClusterSessionCredentials =
      GetClusterSessionCredentialsResponse
  request :: (Service -> Service)
-> GetClusterSessionCredentials
-> Request GetClusterSessionCredentials
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy GetClusterSessionCredentials
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetClusterSessionCredentials)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Credentials
-> Maybe POSIX -> Int -> GetClusterSessionCredentialsResponse
GetClusterSessionCredentialsResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"Credentials")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"ExpiresAt")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance
  Prelude.Hashable
    GetClusterSessionCredentials
  where
  hashWithSalt :: Int -> GetClusterSessionCredentials -> Int
hashWithSalt Int
_salt GetClusterSessionCredentials' {Text
executionRoleArn :: Text
clusterId :: Text
$sel:executionRoleArn:GetClusterSessionCredentials' :: GetClusterSessionCredentials -> Text
$sel:clusterId:GetClusterSessionCredentials' :: GetClusterSessionCredentials -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
clusterId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
executionRoleArn

instance Prelude.NFData GetClusterSessionCredentials where
  rnf :: GetClusterSessionCredentials -> ()
rnf GetClusterSessionCredentials' {Text
executionRoleArn :: Text
clusterId :: Text
$sel:executionRoleArn:GetClusterSessionCredentials' :: GetClusterSessionCredentials -> Text
$sel:clusterId:GetClusterSessionCredentials' :: GetClusterSessionCredentials -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
clusterId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
executionRoleArn

instance Data.ToHeaders GetClusterSessionCredentials where
  toHeaders :: GetClusterSessionCredentials -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"ElasticMapReduce.GetClusterSessionCredentials" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON GetClusterSessionCredentials where
  toJSON :: GetClusterSessionCredentials -> Value
toJSON GetClusterSessionCredentials' {Text
executionRoleArn :: Text
clusterId :: Text
$sel:executionRoleArn:GetClusterSessionCredentials' :: GetClusterSessionCredentials -> Text
$sel:clusterId:GetClusterSessionCredentials' :: GetClusterSessionCredentials -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"ClusterId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
clusterId),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"ExecutionRoleArn" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
executionRoleArn)
          ]
      )

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

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

-- | /See:/ 'newGetClusterSessionCredentialsResponse' smart constructor.
data GetClusterSessionCredentialsResponse = GetClusterSessionCredentialsResponse'
  { -- | The credentials that you can use to connect to cluster endpoints that
    -- support username-based and password-based authentication.
    GetClusterSessionCredentialsResponse -> Maybe Credentials
credentials :: Prelude.Maybe Credentials,
    -- | The time when the credentials that are returned by the
    -- @GetClusterSessionCredentials@ API expire.
    GetClusterSessionCredentialsResponse -> Maybe POSIX
expiresAt :: Prelude.Maybe Data.POSIX,
    -- | The response's http status code.
    GetClusterSessionCredentialsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetClusterSessionCredentialsResponse
-> GetClusterSessionCredentialsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetClusterSessionCredentialsResponse
-> GetClusterSessionCredentialsResponse -> Bool
$c/= :: GetClusterSessionCredentialsResponse
-> GetClusterSessionCredentialsResponse -> Bool
== :: GetClusterSessionCredentialsResponse
-> GetClusterSessionCredentialsResponse -> Bool
$c== :: GetClusterSessionCredentialsResponse
-> GetClusterSessionCredentialsResponse -> Bool
Prelude.Eq, Int -> GetClusterSessionCredentialsResponse -> ShowS
[GetClusterSessionCredentialsResponse] -> ShowS
GetClusterSessionCredentialsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetClusterSessionCredentialsResponse] -> ShowS
$cshowList :: [GetClusterSessionCredentialsResponse] -> ShowS
show :: GetClusterSessionCredentialsResponse -> String
$cshow :: GetClusterSessionCredentialsResponse -> String
showsPrec :: Int -> GetClusterSessionCredentialsResponse -> ShowS
$cshowsPrec :: Int -> GetClusterSessionCredentialsResponse -> ShowS
Prelude.Show, forall x.
Rep GetClusterSessionCredentialsResponse x
-> GetClusterSessionCredentialsResponse
forall x.
GetClusterSessionCredentialsResponse
-> Rep GetClusterSessionCredentialsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetClusterSessionCredentialsResponse x
-> GetClusterSessionCredentialsResponse
$cfrom :: forall x.
GetClusterSessionCredentialsResponse
-> Rep GetClusterSessionCredentialsResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetClusterSessionCredentialsResponse' 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:
--
-- 'credentials', 'getClusterSessionCredentialsResponse_credentials' - The credentials that you can use to connect to cluster endpoints that
-- support username-based and password-based authentication.
--
-- 'expiresAt', 'getClusterSessionCredentialsResponse_expiresAt' - The time when the credentials that are returned by the
-- @GetClusterSessionCredentials@ API expire.
--
-- 'httpStatus', 'getClusterSessionCredentialsResponse_httpStatus' - The response's http status code.
newGetClusterSessionCredentialsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetClusterSessionCredentialsResponse
newGetClusterSessionCredentialsResponse :: Int -> GetClusterSessionCredentialsResponse
newGetClusterSessionCredentialsResponse Int
pHttpStatus_ =
  GetClusterSessionCredentialsResponse'
    { $sel:credentials:GetClusterSessionCredentialsResponse' :: Maybe Credentials
credentials =
        forall a. Maybe a
Prelude.Nothing,
      $sel:expiresAt:GetClusterSessionCredentialsResponse' :: Maybe POSIX
expiresAt = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetClusterSessionCredentialsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The credentials that you can use to connect to cluster endpoints that
-- support username-based and password-based authentication.
getClusterSessionCredentialsResponse_credentials :: Lens.Lens' GetClusterSessionCredentialsResponse (Prelude.Maybe Credentials)
getClusterSessionCredentialsResponse_credentials :: Lens' GetClusterSessionCredentialsResponse (Maybe Credentials)
getClusterSessionCredentialsResponse_credentials = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetClusterSessionCredentialsResponse' {Maybe Credentials
credentials :: Maybe Credentials
$sel:credentials:GetClusterSessionCredentialsResponse' :: GetClusterSessionCredentialsResponse -> Maybe Credentials
credentials} -> Maybe Credentials
credentials) (\s :: GetClusterSessionCredentialsResponse
s@GetClusterSessionCredentialsResponse' {} Maybe Credentials
a -> GetClusterSessionCredentialsResponse
s {$sel:credentials:GetClusterSessionCredentialsResponse' :: Maybe Credentials
credentials = Maybe Credentials
a} :: GetClusterSessionCredentialsResponse)

-- | The time when the credentials that are returned by the
-- @GetClusterSessionCredentials@ API expire.
getClusterSessionCredentialsResponse_expiresAt :: Lens.Lens' GetClusterSessionCredentialsResponse (Prelude.Maybe Prelude.UTCTime)
getClusterSessionCredentialsResponse_expiresAt :: Lens' GetClusterSessionCredentialsResponse (Maybe UTCTime)
getClusterSessionCredentialsResponse_expiresAt = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetClusterSessionCredentialsResponse' {Maybe POSIX
expiresAt :: Maybe POSIX
$sel:expiresAt:GetClusterSessionCredentialsResponse' :: GetClusterSessionCredentialsResponse -> Maybe POSIX
expiresAt} -> Maybe POSIX
expiresAt) (\s :: GetClusterSessionCredentialsResponse
s@GetClusterSessionCredentialsResponse' {} Maybe POSIX
a -> GetClusterSessionCredentialsResponse
s {$sel:expiresAt:GetClusterSessionCredentialsResponse' :: Maybe POSIX
expiresAt = Maybe POSIX
a} :: GetClusterSessionCredentialsResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall (a :: Format). Iso' (Time a) UTCTime
Data._Time

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

instance
  Prelude.NFData
    GetClusterSessionCredentialsResponse
  where
  rnf :: GetClusterSessionCredentialsResponse -> ()
rnf GetClusterSessionCredentialsResponse' {Int
Maybe POSIX
Maybe Credentials
httpStatus :: Int
expiresAt :: Maybe POSIX
credentials :: Maybe Credentials
$sel:httpStatus:GetClusterSessionCredentialsResponse' :: GetClusterSessionCredentialsResponse -> Int
$sel:expiresAt:GetClusterSessionCredentialsResponse' :: GetClusterSessionCredentialsResponse -> Maybe POSIX
$sel:credentials:GetClusterSessionCredentialsResponse' :: GetClusterSessionCredentialsResponse -> Maybe Credentials
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Credentials
credentials
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe POSIX
expiresAt
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus