{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Downloads the regional Amazon Lightsail default key pair.
--
-- This action also creates a Lightsail default key pair if a default key
-- pair does not currently exist in the Amazon Web Services Region.
module Amazonka.Lightsail.DownloadDefaultKeyPair
  ( -- * Creating a Request
    DownloadDefaultKeyPair (..),
    newDownloadDefaultKeyPair,

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

    -- * Response Lenses
    downloadDefaultKeyPairResponse_createdAt,
    downloadDefaultKeyPairResponse_privateKeyBase64,
    downloadDefaultKeyPairResponse_publicKeyBase64,
    downloadDefaultKeyPairResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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
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]
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
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. 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 :: (Service -> Service)
-> DownloadDefaultKeyPair -> Request DownloadDefaultKeyPair
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 DownloadDefaultKeyPair
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse DownloadDefaultKeyPair)))
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 POSIX
-> Maybe Text
-> Maybe Text
-> Int
-> DownloadDefaultKeyPairResponse
DownloadDefaultKeyPairResponse'
            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
"createdAt")
            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
"privateKeyBase64")
            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
"publicKeyBase64")
            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 DownloadDefaultKeyPair where
  hashWithSalt :: Int -> DownloadDefaultKeyPair -> Int
hashWithSalt Int
_salt DownloadDefaultKeyPair
_ =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` ()

instance Prelude.NFData DownloadDefaultKeyPair where
  rnf :: DownloadDefaultKeyPair -> ()
rnf DownloadDefaultKeyPair
_ = ()

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

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

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

-- | /See:/ 'newDownloadDefaultKeyPairResponse' smart constructor.
data DownloadDefaultKeyPairResponse = DownloadDefaultKeyPairResponse'
  { -- | The timestamp when the default key pair was created.
    DownloadDefaultKeyPairResponse -> Maybe POSIX
createdAt :: Prelude.Maybe Data.POSIX,
    -- | A base64-encoded RSA private key.
    DownloadDefaultKeyPairResponse -> Maybe Text
privateKeyBase64 :: Prelude.Maybe Prelude.Text,
    -- | A base64-encoded public key of the @ssh-rsa@ type.
    DownloadDefaultKeyPairResponse -> Maybe Text
publicKeyBase64 :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    DownloadDefaultKeyPairResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (DownloadDefaultKeyPairResponse
-> DownloadDefaultKeyPairResponse -> Bool
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]
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
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.
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:
--
-- 'createdAt', 'downloadDefaultKeyPairResponse_createdAt' - The timestamp when the default key pair was created.
--
-- 'privateKeyBase64', 'downloadDefaultKeyPairResponse_privateKeyBase64' - A base64-encoded RSA private key.
--
-- 'publicKeyBase64', 'downloadDefaultKeyPairResponse_publicKeyBase64' - A base64-encoded public key of the @ssh-rsa@ type.
--
-- 'httpStatus', 'downloadDefaultKeyPairResponse_httpStatus' - The response's http status code.
newDownloadDefaultKeyPairResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DownloadDefaultKeyPairResponse
newDownloadDefaultKeyPairResponse :: Int -> DownloadDefaultKeyPairResponse
newDownloadDefaultKeyPairResponse Int
pHttpStatus_ =
  DownloadDefaultKeyPairResponse'
    { $sel:createdAt:DownloadDefaultKeyPairResponse' :: Maybe POSIX
createdAt =
        forall a. Maybe a
Prelude.Nothing,
      $sel:privateKeyBase64:DownloadDefaultKeyPairResponse' :: Maybe Text
privateKeyBase64 = forall a. Maybe a
Prelude.Nothing,
      $sel:publicKeyBase64:DownloadDefaultKeyPairResponse' :: Maybe Text
publicKeyBase64 = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DownloadDefaultKeyPairResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The timestamp when the default key pair was created.
downloadDefaultKeyPairResponse_createdAt :: Lens.Lens' DownloadDefaultKeyPairResponse (Prelude.Maybe Prelude.UTCTime)
downloadDefaultKeyPairResponse_createdAt :: Lens' DownloadDefaultKeyPairResponse (Maybe UTCTime)
downloadDefaultKeyPairResponse_createdAt = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DownloadDefaultKeyPairResponse' {Maybe POSIX
createdAt :: Maybe POSIX
$sel:createdAt:DownloadDefaultKeyPairResponse' :: DownloadDefaultKeyPairResponse -> Maybe POSIX
createdAt} -> Maybe POSIX
createdAt) (\s :: DownloadDefaultKeyPairResponse
s@DownloadDefaultKeyPairResponse' {} Maybe POSIX
a -> DownloadDefaultKeyPairResponse
s {$sel:createdAt:DownloadDefaultKeyPairResponse' :: Maybe POSIX
createdAt = Maybe POSIX
a} :: DownloadDefaultKeyPairResponse) 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

-- | A base64-encoded RSA private key.
downloadDefaultKeyPairResponse_privateKeyBase64 :: Lens.Lens' DownloadDefaultKeyPairResponse (Prelude.Maybe Prelude.Text)
downloadDefaultKeyPairResponse_privateKeyBase64 :: Lens' DownloadDefaultKeyPairResponse (Maybe Text)
downloadDefaultKeyPairResponse_privateKeyBase64 = 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)

-- | A base64-encoded public key of the @ssh-rsa@ type.
downloadDefaultKeyPairResponse_publicKeyBase64 :: Lens.Lens' DownloadDefaultKeyPairResponse (Prelude.Maybe Prelude.Text)
downloadDefaultKeyPairResponse_publicKeyBase64 :: Lens' DownloadDefaultKeyPairResponse (Maybe Text)
downloadDefaultKeyPairResponse_publicKeyBase64 = 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)

-- | The response's http status code.
downloadDefaultKeyPairResponse_httpStatus :: Lens.Lens' DownloadDefaultKeyPairResponse Prelude.Int
downloadDefaultKeyPairResponse_httpStatus :: Lens' DownloadDefaultKeyPairResponse Int
downloadDefaultKeyPairResponse_httpStatus = 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
  where
  rnf :: DownloadDefaultKeyPairResponse -> ()
rnf DownloadDefaultKeyPairResponse' {Int
Maybe Text
Maybe POSIX
httpStatus :: Int
publicKeyBase64 :: Maybe Text
privateKeyBase64 :: Maybe Text
createdAt :: Maybe POSIX
$sel:httpStatus:DownloadDefaultKeyPairResponse' :: DownloadDefaultKeyPairResponse -> Int
$sel:publicKeyBase64:DownloadDefaultKeyPairResponse' :: DownloadDefaultKeyPairResponse -> Maybe Text
$sel:privateKeyBase64:DownloadDefaultKeyPairResponse' :: DownloadDefaultKeyPairResponse -> Maybe Text
$sel:createdAt:DownloadDefaultKeyPairResponse' :: DownloadDefaultKeyPairResponse -> Maybe POSIX
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe POSIX
createdAt
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
privateKeyBase64
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
publicKeyBase64
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus