{-# 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.Lightsail.GetKeyPair
-- 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)
--
-- Returns information about a specific key pair.
module Amazonka.Lightsail.GetKeyPair
  ( -- * Creating a Request
    GetKeyPair (..),
    newGetKeyPair,

    -- * Request Lenses
    getKeyPair_keyPairName,

    -- * Destructuring the Response
    GetKeyPairResponse (..),
    newGetKeyPairResponse,

    -- * Response Lenses
    getKeyPairResponse_keyPair,
    getKeyPairResponse_httpStatus,
  )
where

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

-- | /See:/ 'newGetKeyPair' smart constructor.
data GetKeyPair = GetKeyPair'
  { -- | The name of the key pair for which you are requesting information.
    GetKeyPair -> Text
keyPairName :: Prelude.Text
  }
  deriving (GetKeyPair -> GetKeyPair -> Bool
(GetKeyPair -> GetKeyPair -> Bool)
-> (GetKeyPair -> GetKeyPair -> Bool) -> Eq GetKeyPair
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetKeyPair -> GetKeyPair -> Bool
$c/= :: GetKeyPair -> GetKeyPair -> Bool
== :: GetKeyPair -> GetKeyPair -> Bool
$c== :: GetKeyPair -> GetKeyPair -> Bool
Prelude.Eq, ReadPrec [GetKeyPair]
ReadPrec GetKeyPair
Int -> ReadS GetKeyPair
ReadS [GetKeyPair]
(Int -> ReadS GetKeyPair)
-> ReadS [GetKeyPair]
-> ReadPrec GetKeyPair
-> ReadPrec [GetKeyPair]
-> Read GetKeyPair
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetKeyPair]
$creadListPrec :: ReadPrec [GetKeyPair]
readPrec :: ReadPrec GetKeyPair
$creadPrec :: ReadPrec GetKeyPair
readList :: ReadS [GetKeyPair]
$creadList :: ReadS [GetKeyPair]
readsPrec :: Int -> ReadS GetKeyPair
$creadsPrec :: Int -> ReadS GetKeyPair
Prelude.Read, Int -> GetKeyPair -> ShowS
[GetKeyPair] -> ShowS
GetKeyPair -> String
(Int -> GetKeyPair -> ShowS)
-> (GetKeyPair -> String)
-> ([GetKeyPair] -> ShowS)
-> Show GetKeyPair
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetKeyPair] -> ShowS
$cshowList :: [GetKeyPair] -> ShowS
show :: GetKeyPair -> String
$cshow :: GetKeyPair -> String
showsPrec :: Int -> GetKeyPair -> ShowS
$cshowsPrec :: Int -> GetKeyPair -> ShowS
Prelude.Show, (forall x. GetKeyPair -> Rep GetKeyPair x)
-> (forall x. Rep GetKeyPair x -> GetKeyPair) -> Generic GetKeyPair
forall x. Rep GetKeyPair x -> GetKeyPair
forall x. GetKeyPair -> Rep GetKeyPair x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetKeyPair x -> GetKeyPair
$cfrom :: forall x. GetKeyPair -> Rep GetKeyPair x
Prelude.Generic)

-- |
-- Create a value of 'GetKeyPair' 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:
--
-- 'keyPairName', 'getKeyPair_keyPairName' - The name of the key pair for which you are requesting information.
newGetKeyPair ::
  -- | 'keyPairName'
  Prelude.Text ->
  GetKeyPair
newGetKeyPair :: Text -> GetKeyPair
newGetKeyPair Text
pKeyPairName_ =
  GetKeyPair' :: Text -> GetKeyPair
GetKeyPair' {$sel:keyPairName:GetKeyPair' :: Text
keyPairName = Text
pKeyPairName_}

-- | The name of the key pair for which you are requesting information.
getKeyPair_keyPairName :: Lens.Lens' GetKeyPair Prelude.Text
getKeyPair_keyPairName :: (Text -> f Text) -> GetKeyPair -> f GetKeyPair
getKeyPair_keyPairName = (GetKeyPair -> Text)
-> (GetKeyPair -> Text -> GetKeyPair)
-> Lens GetKeyPair GetKeyPair Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetKeyPair' {Text
keyPairName :: Text
$sel:keyPairName:GetKeyPair' :: GetKeyPair -> Text
keyPairName} -> Text
keyPairName) (\s :: GetKeyPair
s@GetKeyPair' {} Text
a -> GetKeyPair
s {$sel:keyPairName:GetKeyPair' :: Text
keyPairName = Text
a} :: GetKeyPair)

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

instance Prelude.NFData GetKeyPair

instance Core.ToHeaders GetKeyPair where
  toHeaders :: GetKeyPair -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetKeyPair -> 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
"Lightsail_20161128.GetKeyPair" ::
                          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 GetKeyPair where
  toJSON :: GetKeyPair -> Value
toJSON GetKeyPair' {Text
keyPairName :: Text
$sel:keyPairName:GetKeyPair' :: GetKeyPair -> 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
"keyPairName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
keyPairName)]
      )

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

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

-- | /See:/ 'newGetKeyPairResponse' smart constructor.
data GetKeyPairResponse = GetKeyPairResponse'
  { -- | An array of key-value pairs containing information about the key pair.
    GetKeyPairResponse -> Maybe KeyPair
keyPair :: Prelude.Maybe KeyPair,
    -- | The response's http status code.
    GetKeyPairResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetKeyPairResponse -> GetKeyPairResponse -> Bool
(GetKeyPairResponse -> GetKeyPairResponse -> Bool)
-> (GetKeyPairResponse -> GetKeyPairResponse -> Bool)
-> Eq GetKeyPairResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetKeyPairResponse -> GetKeyPairResponse -> Bool
$c/= :: GetKeyPairResponse -> GetKeyPairResponse -> Bool
== :: GetKeyPairResponse -> GetKeyPairResponse -> Bool
$c== :: GetKeyPairResponse -> GetKeyPairResponse -> Bool
Prelude.Eq, ReadPrec [GetKeyPairResponse]
ReadPrec GetKeyPairResponse
Int -> ReadS GetKeyPairResponse
ReadS [GetKeyPairResponse]
(Int -> ReadS GetKeyPairResponse)
-> ReadS [GetKeyPairResponse]
-> ReadPrec GetKeyPairResponse
-> ReadPrec [GetKeyPairResponse]
-> Read GetKeyPairResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetKeyPairResponse]
$creadListPrec :: ReadPrec [GetKeyPairResponse]
readPrec :: ReadPrec GetKeyPairResponse
$creadPrec :: ReadPrec GetKeyPairResponse
readList :: ReadS [GetKeyPairResponse]
$creadList :: ReadS [GetKeyPairResponse]
readsPrec :: Int -> ReadS GetKeyPairResponse
$creadsPrec :: Int -> ReadS GetKeyPairResponse
Prelude.Read, Int -> GetKeyPairResponse -> ShowS
[GetKeyPairResponse] -> ShowS
GetKeyPairResponse -> String
(Int -> GetKeyPairResponse -> ShowS)
-> (GetKeyPairResponse -> String)
-> ([GetKeyPairResponse] -> ShowS)
-> Show GetKeyPairResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetKeyPairResponse] -> ShowS
$cshowList :: [GetKeyPairResponse] -> ShowS
show :: GetKeyPairResponse -> String
$cshow :: GetKeyPairResponse -> String
showsPrec :: Int -> GetKeyPairResponse -> ShowS
$cshowsPrec :: Int -> GetKeyPairResponse -> ShowS
Prelude.Show, (forall x. GetKeyPairResponse -> Rep GetKeyPairResponse x)
-> (forall x. Rep GetKeyPairResponse x -> GetKeyPairResponse)
-> Generic GetKeyPairResponse
forall x. Rep GetKeyPairResponse x -> GetKeyPairResponse
forall x. GetKeyPairResponse -> Rep GetKeyPairResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetKeyPairResponse x -> GetKeyPairResponse
$cfrom :: forall x. GetKeyPairResponse -> Rep GetKeyPairResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetKeyPairResponse' 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', 'getKeyPairResponse_keyPair' - An array of key-value pairs containing information about the key pair.
--
-- 'httpStatus', 'getKeyPairResponse_httpStatus' - The response's http status code.
newGetKeyPairResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetKeyPairResponse
newGetKeyPairResponse :: Int -> GetKeyPairResponse
newGetKeyPairResponse Int
pHttpStatus_ =
  GetKeyPairResponse' :: Maybe KeyPair -> Int -> GetKeyPairResponse
GetKeyPairResponse'
    { $sel:keyPair:GetKeyPairResponse' :: Maybe KeyPair
keyPair = Maybe KeyPair
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetKeyPairResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | An array of key-value pairs containing information about the key pair.
getKeyPairResponse_keyPair :: Lens.Lens' GetKeyPairResponse (Prelude.Maybe KeyPair)
getKeyPairResponse_keyPair :: (Maybe KeyPair -> f (Maybe KeyPair))
-> GetKeyPairResponse -> f GetKeyPairResponse
getKeyPairResponse_keyPair = (GetKeyPairResponse -> Maybe KeyPair)
-> (GetKeyPairResponse -> Maybe KeyPair -> GetKeyPairResponse)
-> Lens
     GetKeyPairResponse
     GetKeyPairResponse
     (Maybe KeyPair)
     (Maybe KeyPair)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetKeyPairResponse' {Maybe KeyPair
keyPair :: Maybe KeyPair
$sel:keyPair:GetKeyPairResponse' :: GetKeyPairResponse -> Maybe KeyPair
keyPair} -> Maybe KeyPair
keyPair) (\s :: GetKeyPairResponse
s@GetKeyPairResponse' {} Maybe KeyPair
a -> GetKeyPairResponse
s {$sel:keyPair:GetKeyPairResponse' :: Maybe KeyPair
keyPair = Maybe KeyPair
a} :: GetKeyPairResponse)

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

instance Prelude.NFData GetKeyPairResponse