{-# 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.DownloadDefaultKeyPair
-- 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)
--
-- Downloads the default SSH key pair from the user\'s account.
module Amazonka.Lightsail.DownloadDefaultKeyPair
  ( -- * Creating a Request
    DownloadDefaultKeyPair (..),
    newDownloadDefaultKeyPair,

    -- * Destructuring the Response
    DownloadDefaultKeyPairResponse (..),
    newDownloadDefaultKeyPairResponse,

    -- * Response Lenses
    downloadDefaultKeyPairResponse_publicKeyBase64,
    downloadDefaultKeyPairResponse_privateKeyBase64,
    downloadDefaultKeyPairResponse_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:/ 'newDownloadDefaultKeyPair' smart constructor.
data DownloadDefaultKeyPair = DownloadDefaultKeyPair'
  {
  }
  deriving (DownloadDefaultKeyPair -> DownloadDefaultKeyPair -> Bool
(DownloadDefaultKeyPair -> DownloadDefaultKeyPair -> Bool)
-> (DownloadDefaultKeyPair -> DownloadDefaultKeyPair -> Bool)
-> Eq DownloadDefaultKeyPair
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DownloadDefaultKeyPair -> DownloadDefaultKeyPair -> Bool
$c/= :: DownloadDefaultKeyPair -> DownloadDefaultKeyPair -> Bool
== :: DownloadDefaultKeyPair -> DownloadDefaultKeyPair -> Bool
$c== :: DownloadDefaultKeyPair -> DownloadDefaultKeyPair -> Bool
Prelude.Eq, ReadPrec [DownloadDefaultKeyPair]
ReadPrec DownloadDefaultKeyPair
Int -> ReadS DownloadDefaultKeyPair
ReadS [DownloadDefaultKeyPair]
(Int -> ReadS DownloadDefaultKeyPair)
-> ReadS [DownloadDefaultKeyPair]
-> ReadPrec DownloadDefaultKeyPair
-> ReadPrec [DownloadDefaultKeyPair]
-> Read DownloadDefaultKeyPair
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DownloadDefaultKeyPair]
$creadListPrec :: ReadPrec [DownloadDefaultKeyPair]
readPrec :: ReadPrec DownloadDefaultKeyPair
$creadPrec :: ReadPrec DownloadDefaultKeyPair
readList :: ReadS [DownloadDefaultKeyPair]
$creadList :: ReadS [DownloadDefaultKeyPair]
readsPrec :: Int -> ReadS DownloadDefaultKeyPair
$creadsPrec :: Int -> ReadS DownloadDefaultKeyPair
Prelude.Read, Int -> DownloadDefaultKeyPair -> ShowS
[DownloadDefaultKeyPair] -> ShowS
DownloadDefaultKeyPair -> String
(Int -> DownloadDefaultKeyPair -> ShowS)
-> (DownloadDefaultKeyPair -> String)
-> ([DownloadDefaultKeyPair] -> ShowS)
-> Show DownloadDefaultKeyPair
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DownloadDefaultKeyPair] -> ShowS
$cshowList :: [DownloadDefaultKeyPair] -> ShowS
show :: DownloadDefaultKeyPair -> String
$cshow :: DownloadDefaultKeyPair -> String
showsPrec :: Int -> DownloadDefaultKeyPair -> ShowS
$cshowsPrec :: Int -> DownloadDefaultKeyPair -> ShowS
Prelude.Show, (forall x. DownloadDefaultKeyPair -> Rep DownloadDefaultKeyPair x)
-> (forall x.
    Rep DownloadDefaultKeyPair x -> DownloadDefaultKeyPair)
-> Generic DownloadDefaultKeyPair
forall x. Rep DownloadDefaultKeyPair x -> DownloadDefaultKeyPair
forall x. DownloadDefaultKeyPair -> Rep DownloadDefaultKeyPair x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DownloadDefaultKeyPair x -> DownloadDefaultKeyPair
$cfrom :: forall x. DownloadDefaultKeyPair -> Rep DownloadDefaultKeyPair x
Prelude.Generic)

-- |
-- Create a value of 'DownloadDefaultKeyPair' 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.
newDownloadDefaultKeyPair ::
  DownloadDefaultKeyPair
newDownloadDefaultKeyPair :: DownloadDefaultKeyPair
newDownloadDefaultKeyPair = DownloadDefaultKeyPair
DownloadDefaultKeyPair'

instance Core.AWSRequest DownloadDefaultKeyPair where
  type
    AWSResponse DownloadDefaultKeyPair =
      DownloadDefaultKeyPairResponse
  request :: DownloadDefaultKeyPair -> Request DownloadDefaultKeyPair
request = Service -> DownloadDefaultKeyPair -> Request DownloadDefaultKeyPair
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy DownloadDefaultKeyPair
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse DownloadDefaultKeyPair)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse DownloadDefaultKeyPair))
-> Logger
-> Service
-> Proxy DownloadDefaultKeyPair
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse DownloadDefaultKeyPair)))
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 -> DownloadDefaultKeyPairResponse
DownloadDefaultKeyPairResponse'
            (Maybe Text -> Maybe Text -> Int -> DownloadDefaultKeyPairResponse)
-> Either String (Maybe Text)
-> Either
     String (Maybe Text -> Int -> DownloadDefaultKeyPairResponse)
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
"publicKeyBase64")
            Either String (Maybe Text -> Int -> DownloadDefaultKeyPairResponse)
-> Either String (Maybe Text)
-> Either String (Int -> DownloadDefaultKeyPairResponse)
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
"privateKeyBase64")
            Either String (Int -> DownloadDefaultKeyPairResponse)
-> Either String Int
-> Either String DownloadDefaultKeyPairResponse
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 DownloadDefaultKeyPair

instance Prelude.NFData DownloadDefaultKeyPair

instance Core.ToHeaders DownloadDefaultKeyPair where
  toHeaders :: DownloadDefaultKeyPair -> ResponseHeaders
toHeaders =
    ResponseHeaders -> DownloadDefaultKeyPair -> 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.DownloadDefaultKeyPair" ::
                          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 DownloadDefaultKeyPair where
  toJSON :: DownloadDefaultKeyPair -> Value
toJSON = Value -> DownloadDefaultKeyPair -> Value
forall a b. a -> b -> a
Prelude.const (Object -> Value
Core.Object Object
forall a. Monoid a => a
Prelude.mempty)

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

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

-- | /See:/ 'newDownloadDefaultKeyPairResponse' smart constructor.
data DownloadDefaultKeyPairResponse = DownloadDefaultKeyPairResponse'
  { -- | A base64-encoded public key of the @ssh-rsa@ type.
    DownloadDefaultKeyPairResponse -> Maybe Text
publicKeyBase64 :: Prelude.Maybe Prelude.Text,
    -- | A base64-encoded RSA private key.
    DownloadDefaultKeyPairResponse -> Maybe Text
privateKeyBase64 :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    DownloadDefaultKeyPairResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (DownloadDefaultKeyPairResponse
-> DownloadDefaultKeyPairResponse -> Bool
(DownloadDefaultKeyPairResponse
 -> DownloadDefaultKeyPairResponse -> Bool)
-> (DownloadDefaultKeyPairResponse
    -> DownloadDefaultKeyPairResponse -> Bool)
-> Eq DownloadDefaultKeyPairResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DownloadDefaultKeyPairResponse
-> DownloadDefaultKeyPairResponse -> Bool
$c/= :: DownloadDefaultKeyPairResponse
-> DownloadDefaultKeyPairResponse -> Bool
== :: DownloadDefaultKeyPairResponse
-> DownloadDefaultKeyPairResponse -> Bool
$c== :: DownloadDefaultKeyPairResponse
-> DownloadDefaultKeyPairResponse -> Bool
Prelude.Eq, ReadPrec [DownloadDefaultKeyPairResponse]
ReadPrec DownloadDefaultKeyPairResponse
Int -> ReadS DownloadDefaultKeyPairResponse
ReadS [DownloadDefaultKeyPairResponse]
(Int -> ReadS DownloadDefaultKeyPairResponse)
-> ReadS [DownloadDefaultKeyPairResponse]
-> ReadPrec DownloadDefaultKeyPairResponse
-> ReadPrec [DownloadDefaultKeyPairResponse]
-> Read DownloadDefaultKeyPairResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DownloadDefaultKeyPairResponse]
$creadListPrec :: ReadPrec [DownloadDefaultKeyPairResponse]
readPrec :: ReadPrec DownloadDefaultKeyPairResponse
$creadPrec :: ReadPrec DownloadDefaultKeyPairResponse
readList :: ReadS [DownloadDefaultKeyPairResponse]
$creadList :: ReadS [DownloadDefaultKeyPairResponse]
readsPrec :: Int -> ReadS DownloadDefaultKeyPairResponse
$creadsPrec :: Int -> ReadS DownloadDefaultKeyPairResponse
Prelude.Read, Int -> DownloadDefaultKeyPairResponse -> ShowS
[DownloadDefaultKeyPairResponse] -> ShowS
DownloadDefaultKeyPairResponse -> String
(Int -> DownloadDefaultKeyPairResponse -> ShowS)
-> (DownloadDefaultKeyPairResponse -> String)
-> ([DownloadDefaultKeyPairResponse] -> ShowS)
-> Show DownloadDefaultKeyPairResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DownloadDefaultKeyPairResponse] -> ShowS
$cshowList :: [DownloadDefaultKeyPairResponse] -> ShowS
show :: DownloadDefaultKeyPairResponse -> String
$cshow :: DownloadDefaultKeyPairResponse -> String
showsPrec :: Int -> DownloadDefaultKeyPairResponse -> ShowS
$cshowsPrec :: Int -> DownloadDefaultKeyPairResponse -> ShowS
Prelude.Show, (forall x.
 DownloadDefaultKeyPairResponse
 -> Rep DownloadDefaultKeyPairResponse x)
-> (forall x.
    Rep DownloadDefaultKeyPairResponse x
    -> DownloadDefaultKeyPairResponse)
-> Generic DownloadDefaultKeyPairResponse
forall x.
Rep DownloadDefaultKeyPairResponse x
-> DownloadDefaultKeyPairResponse
forall x.
DownloadDefaultKeyPairResponse
-> Rep DownloadDefaultKeyPairResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep DownloadDefaultKeyPairResponse x
-> DownloadDefaultKeyPairResponse
$cfrom :: forall x.
DownloadDefaultKeyPairResponse
-> Rep DownloadDefaultKeyPairResponse x
Prelude.Generic)

-- |
-- Create a value of 'DownloadDefaultKeyPairResponse' 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:
--
-- 'publicKeyBase64', 'downloadDefaultKeyPairResponse_publicKeyBase64' - A base64-encoded public key of the @ssh-rsa@ type.
--
-- 'privateKeyBase64', 'downloadDefaultKeyPairResponse_privateKeyBase64' - A base64-encoded RSA private key.
--
-- 'httpStatus', 'downloadDefaultKeyPairResponse_httpStatus' - The response's http status code.
newDownloadDefaultKeyPairResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DownloadDefaultKeyPairResponse
newDownloadDefaultKeyPairResponse :: Int -> DownloadDefaultKeyPairResponse
newDownloadDefaultKeyPairResponse Int
pHttpStatus_ =
  DownloadDefaultKeyPairResponse' :: Maybe Text -> Maybe Text -> Int -> DownloadDefaultKeyPairResponse
DownloadDefaultKeyPairResponse'
    { $sel:publicKeyBase64:DownloadDefaultKeyPairResponse' :: Maybe Text
publicKeyBase64 =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:privateKeyBase64:DownloadDefaultKeyPairResponse' :: Maybe Text
privateKeyBase64 = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DownloadDefaultKeyPairResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A base64-encoded public key of the @ssh-rsa@ type.
downloadDefaultKeyPairResponse_publicKeyBase64 :: Lens.Lens' DownloadDefaultKeyPairResponse (Prelude.Maybe Prelude.Text)
downloadDefaultKeyPairResponse_publicKeyBase64 :: (Maybe Text -> f (Maybe Text))
-> DownloadDefaultKeyPairResponse
-> f DownloadDefaultKeyPairResponse
downloadDefaultKeyPairResponse_publicKeyBase64 = (DownloadDefaultKeyPairResponse -> Maybe Text)
-> (DownloadDefaultKeyPairResponse
    -> Maybe Text -> DownloadDefaultKeyPairResponse)
-> Lens
     DownloadDefaultKeyPairResponse
     DownloadDefaultKeyPairResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DownloadDefaultKeyPairResponse' {Maybe Text
publicKeyBase64 :: Maybe Text
$sel:publicKeyBase64:DownloadDefaultKeyPairResponse' :: DownloadDefaultKeyPairResponse -> Maybe Text
publicKeyBase64} -> Maybe Text
publicKeyBase64) (\s :: DownloadDefaultKeyPairResponse
s@DownloadDefaultKeyPairResponse' {} Maybe Text
a -> DownloadDefaultKeyPairResponse
s {$sel:publicKeyBase64:DownloadDefaultKeyPairResponse' :: Maybe Text
publicKeyBase64 = Maybe Text
a} :: DownloadDefaultKeyPairResponse)

-- | A base64-encoded RSA private key.
downloadDefaultKeyPairResponse_privateKeyBase64 :: Lens.Lens' DownloadDefaultKeyPairResponse (Prelude.Maybe Prelude.Text)
downloadDefaultKeyPairResponse_privateKeyBase64 :: (Maybe Text -> f (Maybe Text))
-> DownloadDefaultKeyPairResponse
-> f DownloadDefaultKeyPairResponse
downloadDefaultKeyPairResponse_privateKeyBase64 = (DownloadDefaultKeyPairResponse -> Maybe Text)
-> (DownloadDefaultKeyPairResponse
    -> Maybe Text -> DownloadDefaultKeyPairResponse)
-> Lens
     DownloadDefaultKeyPairResponse
     DownloadDefaultKeyPairResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DownloadDefaultKeyPairResponse' {Maybe Text
privateKeyBase64 :: Maybe Text
$sel:privateKeyBase64:DownloadDefaultKeyPairResponse' :: DownloadDefaultKeyPairResponse -> Maybe Text
privateKeyBase64} -> Maybe Text
privateKeyBase64) (\s :: DownloadDefaultKeyPairResponse
s@DownloadDefaultKeyPairResponse' {} Maybe Text
a -> DownloadDefaultKeyPairResponse
s {$sel:privateKeyBase64:DownloadDefaultKeyPairResponse' :: Maybe Text
privateKeyBase64 = Maybe Text
a} :: DownloadDefaultKeyPairResponse)

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

instance
  Prelude.NFData
    DownloadDefaultKeyPairResponse