{-# 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.DeleteKeyPair
-- 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)
--
-- Deletes a specific SSH key pair.
--
-- The @delete key pair@ operation supports tag-based access control via
-- resource tags applied to the resource identified by @key pair name@. For
-- more information, see the
-- <https://lightsail.aws.amazon.com/ls/docs/en_us/articles/amazon-lightsail-controlling-access-using-tags Amazon Lightsail Developer Guide>.
module Amazonka.Lightsail.DeleteKeyPair
  ( -- * Creating a Request
    DeleteKeyPair (..),
    newDeleteKeyPair,

    -- * Request Lenses
    deleteKeyPair_keyPairName,

    -- * Destructuring the Response
    DeleteKeyPairResponse (..),
    newDeleteKeyPairResponse,

    -- * Response Lenses
    deleteKeyPairResponse_operation,
    deleteKeyPairResponse_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:/ 'newDeleteKeyPair' smart constructor.
data DeleteKeyPair = DeleteKeyPair'
  { -- | The name of the key pair to delete.
    DeleteKeyPair -> Text
keyPairName :: Prelude.Text
  }
  deriving (DeleteKeyPair -> DeleteKeyPair -> Bool
(DeleteKeyPair -> DeleteKeyPair -> Bool)
-> (DeleteKeyPair -> DeleteKeyPair -> Bool) -> Eq DeleteKeyPair
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeleteKeyPair -> DeleteKeyPair -> Bool
$c/= :: DeleteKeyPair -> DeleteKeyPair -> Bool
== :: DeleteKeyPair -> DeleteKeyPair -> Bool
$c== :: DeleteKeyPair -> DeleteKeyPair -> Bool
Prelude.Eq, ReadPrec [DeleteKeyPair]
ReadPrec DeleteKeyPair
Int -> ReadS DeleteKeyPair
ReadS [DeleteKeyPair]
(Int -> ReadS DeleteKeyPair)
-> ReadS [DeleteKeyPair]
-> ReadPrec DeleteKeyPair
-> ReadPrec [DeleteKeyPair]
-> Read DeleteKeyPair
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeleteKeyPair]
$creadListPrec :: ReadPrec [DeleteKeyPair]
readPrec :: ReadPrec DeleteKeyPair
$creadPrec :: ReadPrec DeleteKeyPair
readList :: ReadS [DeleteKeyPair]
$creadList :: ReadS [DeleteKeyPair]
readsPrec :: Int -> ReadS DeleteKeyPair
$creadsPrec :: Int -> ReadS DeleteKeyPair
Prelude.Read, Int -> DeleteKeyPair -> ShowS
[DeleteKeyPair] -> ShowS
DeleteKeyPair -> String
(Int -> DeleteKeyPair -> ShowS)
-> (DeleteKeyPair -> String)
-> ([DeleteKeyPair] -> ShowS)
-> Show DeleteKeyPair
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeleteKeyPair] -> ShowS
$cshowList :: [DeleteKeyPair] -> ShowS
show :: DeleteKeyPair -> String
$cshow :: DeleteKeyPair -> String
showsPrec :: Int -> DeleteKeyPair -> ShowS
$cshowsPrec :: Int -> DeleteKeyPair -> ShowS
Prelude.Show, (forall x. DeleteKeyPair -> Rep DeleteKeyPair x)
-> (forall x. Rep DeleteKeyPair x -> DeleteKeyPair)
-> Generic DeleteKeyPair
forall x. Rep DeleteKeyPair x -> DeleteKeyPair
forall x. DeleteKeyPair -> Rep DeleteKeyPair x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeleteKeyPair x -> DeleteKeyPair
$cfrom :: forall x. DeleteKeyPair -> Rep DeleteKeyPair x
Prelude.Generic)

-- |
-- Create a value of 'DeleteKeyPair' 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', 'deleteKeyPair_keyPairName' - The name of the key pair to delete.
newDeleteKeyPair ::
  -- | 'keyPairName'
  Prelude.Text ->
  DeleteKeyPair
newDeleteKeyPair :: Text -> DeleteKeyPair
newDeleteKeyPair Text
pKeyPairName_ =
  DeleteKeyPair' :: Text -> DeleteKeyPair
DeleteKeyPair' {$sel:keyPairName:DeleteKeyPair' :: Text
keyPairName = Text
pKeyPairName_}

-- | The name of the key pair to delete.
deleteKeyPair_keyPairName :: Lens.Lens' DeleteKeyPair Prelude.Text
deleteKeyPair_keyPairName :: (Text -> f Text) -> DeleteKeyPair -> f DeleteKeyPair
deleteKeyPair_keyPairName = (DeleteKeyPair -> Text)
-> (DeleteKeyPair -> Text -> DeleteKeyPair)
-> Lens DeleteKeyPair DeleteKeyPair Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteKeyPair' {Text
keyPairName :: Text
$sel:keyPairName:DeleteKeyPair' :: DeleteKeyPair -> Text
keyPairName} -> Text
keyPairName) (\s :: DeleteKeyPair
s@DeleteKeyPair' {} Text
a -> DeleteKeyPair
s {$sel:keyPairName:DeleteKeyPair' :: Text
keyPairName = Text
a} :: DeleteKeyPair)

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

instance Prelude.NFData DeleteKeyPair

instance Core.ToHeaders DeleteKeyPair where
  toHeaders :: DeleteKeyPair -> ResponseHeaders
toHeaders =
    ResponseHeaders -> DeleteKeyPair -> 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.DeleteKeyPair" ::
                          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 DeleteKeyPair where
  toJSON :: DeleteKeyPair -> Value
toJSON DeleteKeyPair' {Text
keyPairName :: Text
$sel:keyPairName:DeleteKeyPair' :: DeleteKeyPair -> 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 DeleteKeyPair where
  toPath :: DeleteKeyPair -> ByteString
toPath = ByteString -> DeleteKeyPair -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

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

-- | /See:/ 'newDeleteKeyPairResponse' smart constructor.
data DeleteKeyPairResponse = DeleteKeyPairResponse'
  { -- | An array of objects that describe the result of the action, such as the
    -- status of the request, the timestamp of the request, and the resources
    -- affected by the request.
    DeleteKeyPairResponse -> Maybe Operation
operation :: Prelude.Maybe Operation,
    -- | The response's http status code.
    DeleteKeyPairResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (DeleteKeyPairResponse -> DeleteKeyPairResponse -> Bool
(DeleteKeyPairResponse -> DeleteKeyPairResponse -> Bool)
-> (DeleteKeyPairResponse -> DeleteKeyPairResponse -> Bool)
-> Eq DeleteKeyPairResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeleteKeyPairResponse -> DeleteKeyPairResponse -> Bool
$c/= :: DeleteKeyPairResponse -> DeleteKeyPairResponse -> Bool
== :: DeleteKeyPairResponse -> DeleteKeyPairResponse -> Bool
$c== :: DeleteKeyPairResponse -> DeleteKeyPairResponse -> Bool
Prelude.Eq, ReadPrec [DeleteKeyPairResponse]
ReadPrec DeleteKeyPairResponse
Int -> ReadS DeleteKeyPairResponse
ReadS [DeleteKeyPairResponse]
(Int -> ReadS DeleteKeyPairResponse)
-> ReadS [DeleteKeyPairResponse]
-> ReadPrec DeleteKeyPairResponse
-> ReadPrec [DeleteKeyPairResponse]
-> Read DeleteKeyPairResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeleteKeyPairResponse]
$creadListPrec :: ReadPrec [DeleteKeyPairResponse]
readPrec :: ReadPrec DeleteKeyPairResponse
$creadPrec :: ReadPrec DeleteKeyPairResponse
readList :: ReadS [DeleteKeyPairResponse]
$creadList :: ReadS [DeleteKeyPairResponse]
readsPrec :: Int -> ReadS DeleteKeyPairResponse
$creadsPrec :: Int -> ReadS DeleteKeyPairResponse
Prelude.Read, Int -> DeleteKeyPairResponse -> ShowS
[DeleteKeyPairResponse] -> ShowS
DeleteKeyPairResponse -> String
(Int -> DeleteKeyPairResponse -> ShowS)
-> (DeleteKeyPairResponse -> String)
-> ([DeleteKeyPairResponse] -> ShowS)
-> Show DeleteKeyPairResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeleteKeyPairResponse] -> ShowS
$cshowList :: [DeleteKeyPairResponse] -> ShowS
show :: DeleteKeyPairResponse -> String
$cshow :: DeleteKeyPairResponse -> String
showsPrec :: Int -> DeleteKeyPairResponse -> ShowS
$cshowsPrec :: Int -> DeleteKeyPairResponse -> ShowS
Prelude.Show, (forall x. DeleteKeyPairResponse -> Rep DeleteKeyPairResponse x)
-> (forall x. Rep DeleteKeyPairResponse x -> DeleteKeyPairResponse)
-> Generic DeleteKeyPairResponse
forall x. Rep DeleteKeyPairResponse x -> DeleteKeyPairResponse
forall x. DeleteKeyPairResponse -> Rep DeleteKeyPairResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeleteKeyPairResponse x -> DeleteKeyPairResponse
$cfrom :: forall x. DeleteKeyPairResponse -> Rep DeleteKeyPairResponse x
Prelude.Generic)

-- |
-- Create a value of 'DeleteKeyPairResponse' 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:
--
-- 'operation', 'deleteKeyPairResponse_operation' - An array of objects that describe the result of the action, such as the
-- status of the request, the timestamp of the request, and the resources
-- affected by the request.
--
-- 'httpStatus', 'deleteKeyPairResponse_httpStatus' - The response's http status code.
newDeleteKeyPairResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DeleteKeyPairResponse
newDeleteKeyPairResponse :: Int -> DeleteKeyPairResponse
newDeleteKeyPairResponse Int
pHttpStatus_ =
  DeleteKeyPairResponse' :: Maybe Operation -> Int -> DeleteKeyPairResponse
DeleteKeyPairResponse'
    { $sel:operation:DeleteKeyPairResponse' :: Maybe Operation
operation = Maybe Operation
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DeleteKeyPairResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | An array of objects that describe the result of the action, such as the
-- status of the request, the timestamp of the request, and the resources
-- affected by the request.
deleteKeyPairResponse_operation :: Lens.Lens' DeleteKeyPairResponse (Prelude.Maybe Operation)
deleteKeyPairResponse_operation :: (Maybe Operation -> f (Maybe Operation))
-> DeleteKeyPairResponse -> f DeleteKeyPairResponse
deleteKeyPairResponse_operation = (DeleteKeyPairResponse -> Maybe Operation)
-> (DeleteKeyPairResponse
    -> Maybe Operation -> DeleteKeyPairResponse)
-> Lens
     DeleteKeyPairResponse
     DeleteKeyPairResponse
     (Maybe Operation)
     (Maybe Operation)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteKeyPairResponse' {Maybe Operation
operation :: Maybe Operation
$sel:operation:DeleteKeyPairResponse' :: DeleteKeyPairResponse -> Maybe Operation
operation} -> Maybe Operation
operation) (\s :: DeleteKeyPairResponse
s@DeleteKeyPairResponse' {} Maybe Operation
a -> DeleteKeyPairResponse
s {$sel:operation:DeleteKeyPairResponse' :: Maybe Operation
operation = Maybe Operation
a} :: DeleteKeyPairResponse)

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

instance Prelude.NFData DeleteKeyPairResponse