{-# 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.IVS.GetPlaybackKeyPair
-- 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)
--
-- Gets a specified playback authorization key pair and returns the @arn@
-- and @fingerprint@. The @privateKey@ held by the caller can be used to
-- generate viewer authorization tokens, to grant viewers access to private
-- channels. For more information, see
-- <https://docs.aws.amazon.com/ivs/latest/userguide/private-channels.html Setting Up Private Channels>
-- in the /Amazon IVS User Guide/.
module Amazonka.IVS.GetPlaybackKeyPair
  ( -- * Creating a Request
    GetPlaybackKeyPair (..),
    newGetPlaybackKeyPair,

    -- * Request Lenses
    getPlaybackKeyPair_arn,

    -- * Destructuring the Response
    GetPlaybackKeyPairResponse (..),
    newGetPlaybackKeyPairResponse,

    -- * Response Lenses
    getPlaybackKeyPairResponse_keyPair,
    getPlaybackKeyPairResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.IVS.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:/ 'newGetPlaybackKeyPair' smart constructor.
data GetPlaybackKeyPair = GetPlaybackKeyPair'
  { -- | ARN of the key pair to be returned.
    GetPlaybackKeyPair -> Text
arn :: Prelude.Text
  }
  deriving (GetPlaybackKeyPair -> GetPlaybackKeyPair -> Bool
(GetPlaybackKeyPair -> GetPlaybackKeyPair -> Bool)
-> (GetPlaybackKeyPair -> GetPlaybackKeyPair -> Bool)
-> Eq GetPlaybackKeyPair
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetPlaybackKeyPair -> GetPlaybackKeyPair -> Bool
$c/= :: GetPlaybackKeyPair -> GetPlaybackKeyPair -> Bool
== :: GetPlaybackKeyPair -> GetPlaybackKeyPair -> Bool
$c== :: GetPlaybackKeyPair -> GetPlaybackKeyPair -> Bool
Prelude.Eq, ReadPrec [GetPlaybackKeyPair]
ReadPrec GetPlaybackKeyPair
Int -> ReadS GetPlaybackKeyPair
ReadS [GetPlaybackKeyPair]
(Int -> ReadS GetPlaybackKeyPair)
-> ReadS [GetPlaybackKeyPair]
-> ReadPrec GetPlaybackKeyPair
-> ReadPrec [GetPlaybackKeyPair]
-> Read GetPlaybackKeyPair
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetPlaybackKeyPair]
$creadListPrec :: ReadPrec [GetPlaybackKeyPair]
readPrec :: ReadPrec GetPlaybackKeyPair
$creadPrec :: ReadPrec GetPlaybackKeyPair
readList :: ReadS [GetPlaybackKeyPair]
$creadList :: ReadS [GetPlaybackKeyPair]
readsPrec :: Int -> ReadS GetPlaybackKeyPair
$creadsPrec :: Int -> ReadS GetPlaybackKeyPair
Prelude.Read, Int -> GetPlaybackKeyPair -> ShowS
[GetPlaybackKeyPair] -> ShowS
GetPlaybackKeyPair -> String
(Int -> GetPlaybackKeyPair -> ShowS)
-> (GetPlaybackKeyPair -> String)
-> ([GetPlaybackKeyPair] -> ShowS)
-> Show GetPlaybackKeyPair
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetPlaybackKeyPair] -> ShowS
$cshowList :: [GetPlaybackKeyPair] -> ShowS
show :: GetPlaybackKeyPair -> String
$cshow :: GetPlaybackKeyPair -> String
showsPrec :: Int -> GetPlaybackKeyPair -> ShowS
$cshowsPrec :: Int -> GetPlaybackKeyPair -> ShowS
Prelude.Show, (forall x. GetPlaybackKeyPair -> Rep GetPlaybackKeyPair x)
-> (forall x. Rep GetPlaybackKeyPair x -> GetPlaybackKeyPair)
-> Generic GetPlaybackKeyPair
forall x. Rep GetPlaybackKeyPair x -> GetPlaybackKeyPair
forall x. GetPlaybackKeyPair -> Rep GetPlaybackKeyPair x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetPlaybackKeyPair x -> GetPlaybackKeyPair
$cfrom :: forall x. GetPlaybackKeyPair -> Rep GetPlaybackKeyPair x
Prelude.Generic)

-- |
-- Create a value of 'GetPlaybackKeyPair' 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:
--
-- 'arn', 'getPlaybackKeyPair_arn' - ARN of the key pair to be returned.
newGetPlaybackKeyPair ::
  -- | 'arn'
  Prelude.Text ->
  GetPlaybackKeyPair
newGetPlaybackKeyPair :: Text -> GetPlaybackKeyPair
newGetPlaybackKeyPair Text
pArn_ =
  GetPlaybackKeyPair' :: Text -> GetPlaybackKeyPair
GetPlaybackKeyPair' {$sel:arn:GetPlaybackKeyPair' :: Text
arn = Text
pArn_}

-- | ARN of the key pair to be returned.
getPlaybackKeyPair_arn :: Lens.Lens' GetPlaybackKeyPair Prelude.Text
getPlaybackKeyPair_arn :: (Text -> f Text) -> GetPlaybackKeyPair -> f GetPlaybackKeyPair
getPlaybackKeyPair_arn = (GetPlaybackKeyPair -> Text)
-> (GetPlaybackKeyPair -> Text -> GetPlaybackKeyPair)
-> Lens GetPlaybackKeyPair GetPlaybackKeyPair Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetPlaybackKeyPair' {Text
arn :: Text
$sel:arn:GetPlaybackKeyPair' :: GetPlaybackKeyPair -> Text
arn} -> Text
arn) (\s :: GetPlaybackKeyPair
s@GetPlaybackKeyPair' {} Text
a -> GetPlaybackKeyPair
s {$sel:arn:GetPlaybackKeyPair' :: Text
arn = Text
a} :: GetPlaybackKeyPair)

instance Core.AWSRequest GetPlaybackKeyPair where
  type
    AWSResponse GetPlaybackKeyPair =
      GetPlaybackKeyPairResponse
  request :: GetPlaybackKeyPair -> Request GetPlaybackKeyPair
request = Service -> GetPlaybackKeyPair -> Request GetPlaybackKeyPair
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy GetPlaybackKeyPair
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetPlaybackKeyPair)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetPlaybackKeyPair))
-> Logger
-> Service
-> Proxy GetPlaybackKeyPair
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetPlaybackKeyPair)))
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 PlaybackKeyPair -> Int -> GetPlaybackKeyPairResponse
GetPlaybackKeyPairResponse'
            (Maybe PlaybackKeyPair -> Int -> GetPlaybackKeyPairResponse)
-> Either String (Maybe PlaybackKeyPair)
-> Either String (Int -> GetPlaybackKeyPairResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe PlaybackKeyPair)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"keyPair")
            Either String (Int -> GetPlaybackKeyPairResponse)
-> Either String Int -> Either String GetPlaybackKeyPairResponse
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 GetPlaybackKeyPair

instance Prelude.NFData GetPlaybackKeyPair

instance Core.ToHeaders GetPlaybackKeyPair where
  toHeaders :: GetPlaybackKeyPair -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetPlaybackKeyPair -> 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.ToJSON GetPlaybackKeyPair where
  toJSON :: GetPlaybackKeyPair -> Value
toJSON GetPlaybackKeyPair' {Text
arn :: Text
$sel:arn:GetPlaybackKeyPair' :: GetPlaybackKeyPair -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"arn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
arn)]
      )

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

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

-- | /See:/ 'newGetPlaybackKeyPairResponse' smart constructor.
data GetPlaybackKeyPairResponse = GetPlaybackKeyPairResponse'
  { GetPlaybackKeyPairResponse -> Maybe PlaybackKeyPair
keyPair :: Prelude.Maybe PlaybackKeyPair,
    -- | The response's http status code.
    GetPlaybackKeyPairResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetPlaybackKeyPairResponse -> GetPlaybackKeyPairResponse -> Bool
(GetPlaybackKeyPairResponse -> GetPlaybackKeyPairResponse -> Bool)
-> (GetPlaybackKeyPairResponse
    -> GetPlaybackKeyPairResponse -> Bool)
-> Eq GetPlaybackKeyPairResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetPlaybackKeyPairResponse -> GetPlaybackKeyPairResponse -> Bool
$c/= :: GetPlaybackKeyPairResponse -> GetPlaybackKeyPairResponse -> Bool
== :: GetPlaybackKeyPairResponse -> GetPlaybackKeyPairResponse -> Bool
$c== :: GetPlaybackKeyPairResponse -> GetPlaybackKeyPairResponse -> Bool
Prelude.Eq, ReadPrec [GetPlaybackKeyPairResponse]
ReadPrec GetPlaybackKeyPairResponse
Int -> ReadS GetPlaybackKeyPairResponse
ReadS [GetPlaybackKeyPairResponse]
(Int -> ReadS GetPlaybackKeyPairResponse)
-> ReadS [GetPlaybackKeyPairResponse]
-> ReadPrec GetPlaybackKeyPairResponse
-> ReadPrec [GetPlaybackKeyPairResponse]
-> Read GetPlaybackKeyPairResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetPlaybackKeyPairResponse]
$creadListPrec :: ReadPrec [GetPlaybackKeyPairResponse]
readPrec :: ReadPrec GetPlaybackKeyPairResponse
$creadPrec :: ReadPrec GetPlaybackKeyPairResponse
readList :: ReadS [GetPlaybackKeyPairResponse]
$creadList :: ReadS [GetPlaybackKeyPairResponse]
readsPrec :: Int -> ReadS GetPlaybackKeyPairResponse
$creadsPrec :: Int -> ReadS GetPlaybackKeyPairResponse
Prelude.Read, Int -> GetPlaybackKeyPairResponse -> ShowS
[GetPlaybackKeyPairResponse] -> ShowS
GetPlaybackKeyPairResponse -> String
(Int -> GetPlaybackKeyPairResponse -> ShowS)
-> (GetPlaybackKeyPairResponse -> String)
-> ([GetPlaybackKeyPairResponse] -> ShowS)
-> Show GetPlaybackKeyPairResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetPlaybackKeyPairResponse] -> ShowS
$cshowList :: [GetPlaybackKeyPairResponse] -> ShowS
show :: GetPlaybackKeyPairResponse -> String
$cshow :: GetPlaybackKeyPairResponse -> String
showsPrec :: Int -> GetPlaybackKeyPairResponse -> ShowS
$cshowsPrec :: Int -> GetPlaybackKeyPairResponse -> ShowS
Prelude.Show, (forall x.
 GetPlaybackKeyPairResponse -> Rep GetPlaybackKeyPairResponse x)
-> (forall x.
    Rep GetPlaybackKeyPairResponse x -> GetPlaybackKeyPairResponse)
-> Generic GetPlaybackKeyPairResponse
forall x.
Rep GetPlaybackKeyPairResponse x -> GetPlaybackKeyPairResponse
forall x.
GetPlaybackKeyPairResponse -> Rep GetPlaybackKeyPairResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetPlaybackKeyPairResponse x -> GetPlaybackKeyPairResponse
$cfrom :: forall x.
GetPlaybackKeyPairResponse -> Rep GetPlaybackKeyPairResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetPlaybackKeyPairResponse' 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:
--
-- 'keyPair', 'getPlaybackKeyPairResponse_keyPair' -
--
-- 'httpStatus', 'getPlaybackKeyPairResponse_httpStatus' - The response's http status code.
newGetPlaybackKeyPairResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetPlaybackKeyPairResponse
newGetPlaybackKeyPairResponse :: Int -> GetPlaybackKeyPairResponse
newGetPlaybackKeyPairResponse Int
pHttpStatus_ =
  GetPlaybackKeyPairResponse' :: Maybe PlaybackKeyPair -> Int -> GetPlaybackKeyPairResponse
GetPlaybackKeyPairResponse'
    { $sel:keyPair:GetPlaybackKeyPairResponse' :: Maybe PlaybackKeyPair
keyPair =
        Maybe PlaybackKeyPair
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetPlaybackKeyPairResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- |
getPlaybackKeyPairResponse_keyPair :: Lens.Lens' GetPlaybackKeyPairResponse (Prelude.Maybe PlaybackKeyPair)
getPlaybackKeyPairResponse_keyPair :: (Maybe PlaybackKeyPair -> f (Maybe PlaybackKeyPair))
-> GetPlaybackKeyPairResponse -> f GetPlaybackKeyPairResponse
getPlaybackKeyPairResponse_keyPair = (GetPlaybackKeyPairResponse -> Maybe PlaybackKeyPair)
-> (GetPlaybackKeyPairResponse
    -> Maybe PlaybackKeyPair -> GetPlaybackKeyPairResponse)
-> Lens
     GetPlaybackKeyPairResponse
     GetPlaybackKeyPairResponse
     (Maybe PlaybackKeyPair)
     (Maybe PlaybackKeyPair)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetPlaybackKeyPairResponse' {Maybe PlaybackKeyPair
keyPair :: Maybe PlaybackKeyPair
$sel:keyPair:GetPlaybackKeyPairResponse' :: GetPlaybackKeyPairResponse -> Maybe PlaybackKeyPair
keyPair} -> Maybe PlaybackKeyPair
keyPair) (\s :: GetPlaybackKeyPairResponse
s@GetPlaybackKeyPairResponse' {} Maybe PlaybackKeyPair
a -> GetPlaybackKeyPairResponse
s {$sel:keyPair:GetPlaybackKeyPairResponse' :: Maybe PlaybackKeyPair
keyPair = Maybe PlaybackKeyPair
a} :: GetPlaybackKeyPairResponse)

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

instance Prelude.NFData GetPlaybackKeyPairResponse