{-# 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.SecretsManager.RestoreSecret
-- 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)
--
-- Cancels the scheduled deletion of a secret by removing the @DeletedDate@
-- time stamp. This makes the secret accessible to query once again.
--
-- __Minimum permissions__
--
-- To run this command, you must have the following permissions:
--
-- -   secretsmanager:RestoreSecret
--
-- __Related operations__
--
-- -   To delete a secret, use DeleteSecret.
module Amazonka.SecretsManager.RestoreSecret
  ( -- * Creating a Request
    RestoreSecret (..),
    newRestoreSecret,

    -- * Request Lenses
    restoreSecret_secretId,

    -- * Destructuring the Response
    RestoreSecretResponse (..),
    newRestoreSecretResponse,

    -- * Response Lenses
    restoreSecretResponse_arn,
    restoreSecretResponse_name,
    restoreSecretResponse_httpStatus,
  )
where

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

-- | /See:/ 'newRestoreSecret' smart constructor.
data RestoreSecret = RestoreSecret'
  { -- | Specifies the secret that you want to restore from a previously
    -- scheduled deletion. You can specify either the Amazon Resource Name
    -- (ARN) or the friendly name of the secret.
    --
    -- For an ARN, we recommend that you specify a complete ARN rather than a
    -- partial ARN.
    RestoreSecret -> Text
secretId :: Prelude.Text
  }
  deriving (RestoreSecret -> RestoreSecret -> Bool
(RestoreSecret -> RestoreSecret -> Bool)
-> (RestoreSecret -> RestoreSecret -> Bool) -> Eq RestoreSecret
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RestoreSecret -> RestoreSecret -> Bool
$c/= :: RestoreSecret -> RestoreSecret -> Bool
== :: RestoreSecret -> RestoreSecret -> Bool
$c== :: RestoreSecret -> RestoreSecret -> Bool
Prelude.Eq, ReadPrec [RestoreSecret]
ReadPrec RestoreSecret
Int -> ReadS RestoreSecret
ReadS [RestoreSecret]
(Int -> ReadS RestoreSecret)
-> ReadS [RestoreSecret]
-> ReadPrec RestoreSecret
-> ReadPrec [RestoreSecret]
-> Read RestoreSecret
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RestoreSecret]
$creadListPrec :: ReadPrec [RestoreSecret]
readPrec :: ReadPrec RestoreSecret
$creadPrec :: ReadPrec RestoreSecret
readList :: ReadS [RestoreSecret]
$creadList :: ReadS [RestoreSecret]
readsPrec :: Int -> ReadS RestoreSecret
$creadsPrec :: Int -> ReadS RestoreSecret
Prelude.Read, Int -> RestoreSecret -> ShowS
[RestoreSecret] -> ShowS
RestoreSecret -> String
(Int -> RestoreSecret -> ShowS)
-> (RestoreSecret -> String)
-> ([RestoreSecret] -> ShowS)
-> Show RestoreSecret
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RestoreSecret] -> ShowS
$cshowList :: [RestoreSecret] -> ShowS
show :: RestoreSecret -> String
$cshow :: RestoreSecret -> String
showsPrec :: Int -> RestoreSecret -> ShowS
$cshowsPrec :: Int -> RestoreSecret -> ShowS
Prelude.Show, (forall x. RestoreSecret -> Rep RestoreSecret x)
-> (forall x. Rep RestoreSecret x -> RestoreSecret)
-> Generic RestoreSecret
forall x. Rep RestoreSecret x -> RestoreSecret
forall x. RestoreSecret -> Rep RestoreSecret x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RestoreSecret x -> RestoreSecret
$cfrom :: forall x. RestoreSecret -> Rep RestoreSecret x
Prelude.Generic)

-- |
-- Create a value of 'RestoreSecret' 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:
--
-- 'secretId', 'restoreSecret_secretId' - Specifies the secret that you want to restore from a previously
-- scheduled deletion. You can specify either the Amazon Resource Name
-- (ARN) or the friendly name of the secret.
--
-- For an ARN, we recommend that you specify a complete ARN rather than a
-- partial ARN.
newRestoreSecret ::
  -- | 'secretId'
  Prelude.Text ->
  RestoreSecret
newRestoreSecret :: Text -> RestoreSecret
newRestoreSecret Text
pSecretId_ =
  RestoreSecret' :: Text -> RestoreSecret
RestoreSecret' {$sel:secretId:RestoreSecret' :: Text
secretId = Text
pSecretId_}

-- | Specifies the secret that you want to restore from a previously
-- scheduled deletion. You can specify either the Amazon Resource Name
-- (ARN) or the friendly name of the secret.
--
-- For an ARN, we recommend that you specify a complete ARN rather than a
-- partial ARN.
restoreSecret_secretId :: Lens.Lens' RestoreSecret Prelude.Text
restoreSecret_secretId :: (Text -> f Text) -> RestoreSecret -> f RestoreSecret
restoreSecret_secretId = (RestoreSecret -> Text)
-> (RestoreSecret -> Text -> RestoreSecret)
-> Lens RestoreSecret RestoreSecret Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RestoreSecret' {Text
secretId :: Text
$sel:secretId:RestoreSecret' :: RestoreSecret -> Text
secretId} -> Text
secretId) (\s :: RestoreSecret
s@RestoreSecret' {} Text
a -> RestoreSecret
s {$sel:secretId:RestoreSecret' :: Text
secretId = Text
a} :: RestoreSecret)

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

instance Prelude.NFData RestoreSecret

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

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

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

-- | /See:/ 'newRestoreSecretResponse' smart constructor.
data RestoreSecretResponse = RestoreSecretResponse'
  { -- | The ARN of the secret that was restored.
    RestoreSecretResponse -> Maybe Text
arn :: Prelude.Maybe Prelude.Text,
    -- | The friendly name of the secret that was restored.
    RestoreSecretResponse -> Maybe Text
name :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    RestoreSecretResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (RestoreSecretResponse -> RestoreSecretResponse -> Bool
(RestoreSecretResponse -> RestoreSecretResponse -> Bool)
-> (RestoreSecretResponse -> RestoreSecretResponse -> Bool)
-> Eq RestoreSecretResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RestoreSecretResponse -> RestoreSecretResponse -> Bool
$c/= :: RestoreSecretResponse -> RestoreSecretResponse -> Bool
== :: RestoreSecretResponse -> RestoreSecretResponse -> Bool
$c== :: RestoreSecretResponse -> RestoreSecretResponse -> Bool
Prelude.Eq, ReadPrec [RestoreSecretResponse]
ReadPrec RestoreSecretResponse
Int -> ReadS RestoreSecretResponse
ReadS [RestoreSecretResponse]
(Int -> ReadS RestoreSecretResponse)
-> ReadS [RestoreSecretResponse]
-> ReadPrec RestoreSecretResponse
-> ReadPrec [RestoreSecretResponse]
-> Read RestoreSecretResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RestoreSecretResponse]
$creadListPrec :: ReadPrec [RestoreSecretResponse]
readPrec :: ReadPrec RestoreSecretResponse
$creadPrec :: ReadPrec RestoreSecretResponse
readList :: ReadS [RestoreSecretResponse]
$creadList :: ReadS [RestoreSecretResponse]
readsPrec :: Int -> ReadS RestoreSecretResponse
$creadsPrec :: Int -> ReadS RestoreSecretResponse
Prelude.Read, Int -> RestoreSecretResponse -> ShowS
[RestoreSecretResponse] -> ShowS
RestoreSecretResponse -> String
(Int -> RestoreSecretResponse -> ShowS)
-> (RestoreSecretResponse -> String)
-> ([RestoreSecretResponse] -> ShowS)
-> Show RestoreSecretResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RestoreSecretResponse] -> ShowS
$cshowList :: [RestoreSecretResponse] -> ShowS
show :: RestoreSecretResponse -> String
$cshow :: RestoreSecretResponse -> String
showsPrec :: Int -> RestoreSecretResponse -> ShowS
$cshowsPrec :: Int -> RestoreSecretResponse -> ShowS
Prelude.Show, (forall x. RestoreSecretResponse -> Rep RestoreSecretResponse x)
-> (forall x. Rep RestoreSecretResponse x -> RestoreSecretResponse)
-> Generic RestoreSecretResponse
forall x. Rep RestoreSecretResponse x -> RestoreSecretResponse
forall x. RestoreSecretResponse -> Rep RestoreSecretResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RestoreSecretResponse x -> RestoreSecretResponse
$cfrom :: forall x. RestoreSecretResponse -> Rep RestoreSecretResponse x
Prelude.Generic)

-- |
-- Create a value of 'RestoreSecretResponse' 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', 'restoreSecretResponse_arn' - The ARN of the secret that was restored.
--
-- 'name', 'restoreSecretResponse_name' - The friendly name of the secret that was restored.
--
-- 'httpStatus', 'restoreSecretResponse_httpStatus' - The response's http status code.
newRestoreSecretResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  RestoreSecretResponse
newRestoreSecretResponse :: Int -> RestoreSecretResponse
newRestoreSecretResponse Int
pHttpStatus_ =
  RestoreSecretResponse' :: Maybe Text -> Maybe Text -> Int -> RestoreSecretResponse
RestoreSecretResponse'
    { $sel:arn:RestoreSecretResponse' :: Maybe Text
arn = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:name:RestoreSecretResponse' :: Maybe Text
name = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:RestoreSecretResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The ARN of the secret that was restored.
restoreSecretResponse_arn :: Lens.Lens' RestoreSecretResponse (Prelude.Maybe Prelude.Text)
restoreSecretResponse_arn :: (Maybe Text -> f (Maybe Text))
-> RestoreSecretResponse -> f RestoreSecretResponse
restoreSecretResponse_arn = (RestoreSecretResponse -> Maybe Text)
-> (RestoreSecretResponse -> Maybe Text -> RestoreSecretResponse)
-> Lens
     RestoreSecretResponse
     RestoreSecretResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RestoreSecretResponse' {Maybe Text
arn :: Maybe Text
$sel:arn:RestoreSecretResponse' :: RestoreSecretResponse -> Maybe Text
arn} -> Maybe Text
arn) (\s :: RestoreSecretResponse
s@RestoreSecretResponse' {} Maybe Text
a -> RestoreSecretResponse
s {$sel:arn:RestoreSecretResponse' :: Maybe Text
arn = Maybe Text
a} :: RestoreSecretResponse)

-- | The friendly name of the secret that was restored.
restoreSecretResponse_name :: Lens.Lens' RestoreSecretResponse (Prelude.Maybe Prelude.Text)
restoreSecretResponse_name :: (Maybe Text -> f (Maybe Text))
-> RestoreSecretResponse -> f RestoreSecretResponse
restoreSecretResponse_name = (RestoreSecretResponse -> Maybe Text)
-> (RestoreSecretResponse -> Maybe Text -> RestoreSecretResponse)
-> Lens
     RestoreSecretResponse
     RestoreSecretResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RestoreSecretResponse' {Maybe Text
name :: Maybe Text
$sel:name:RestoreSecretResponse' :: RestoreSecretResponse -> Maybe Text
name} -> Maybe Text
name) (\s :: RestoreSecretResponse
s@RestoreSecretResponse' {} Maybe Text
a -> RestoreSecretResponse
s {$sel:name:RestoreSecretResponse' :: Maybe Text
name = Maybe Text
a} :: RestoreSecretResponse)

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

instance Prelude.NFData RestoreSecretResponse