{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Cancels the scheduled deletion of a secret by removing the @DeletedDate@
-- time stamp. You can access a secret again after it has been restored.
--
-- Secrets Manager generates a CloudTrail log entry when you call this
-- action. Do not include sensitive information in request parameters
-- because it might be logged. For more information, see
-- <https://docs.aws.amazon.com/secretsmanager/latest/userguide/retrieve-ct-entries.html Logging Secrets Manager events with CloudTrail>.
--
-- __Required permissions:__ @secretsmanager:RestoreSecret@. For more
-- information, see
-- <https://docs.aws.amazon.com/secretsmanager/latest/userguide/reference_iam-permissions.html#reference_iam-permissions_actions IAM policy actions for Secrets Manager>
-- and
-- <https://docs.aws.amazon.com/secretsmanager/latest/userguide/auth-and-access.html Authentication and access control in Secrets Manager>.
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.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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'
  { -- | The ARN or name of the secret to restore.
    --
    -- For an ARN, we recommend that you specify a complete ARN rather than a
    -- partial ARN. See
    -- <https://docs.aws.amazon.com/secretsmanager/latest/userguide/troubleshoot.html#ARN_secretnamehyphen Finding a secret from a partial ARN>.
    RestoreSecret -> Text
secretId :: Prelude.Text
  }
  deriving (RestoreSecret -> RestoreSecret -> Bool
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]
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
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. 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' - The ARN or name of the secret to restore.
--
-- For an ARN, we recommend that you specify a complete ARN rather than a
-- partial ARN. See
-- <https://docs.aws.amazon.com/secretsmanager/latest/userguide/troubleshoot.html#ARN_secretnamehyphen Finding a secret from a partial ARN>.
newRestoreSecret ::
  -- | 'secretId'
  Prelude.Text ->
  RestoreSecret
newRestoreSecret :: Text -> RestoreSecret
newRestoreSecret Text
pSecretId_ =
  RestoreSecret' {$sel:secretId:RestoreSecret' :: Text
secretId = Text
pSecretId_}

-- | The ARN or name of the secret to restore.
--
-- For an ARN, we recommend that you specify a complete ARN rather than a
-- partial ARN. See
-- <https://docs.aws.amazon.com/secretsmanager/latest/userguide/troubleshoot.html#ARN_secretnamehyphen Finding a secret from a partial ARN>.
restoreSecret_secretId :: Lens.Lens' RestoreSecret Prelude.Text
restoreSecret_secretId :: Lens' RestoreSecret Text
restoreSecret_secretId = 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 :: (Service -> Service) -> RestoreSecret -> Request RestoreSecret
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 RestoreSecret
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse RestoreSecret)))
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 Text -> Maybe Text -> Int -> RestoreSecretResponse
RestoreSecretResponse'
            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
"ARN")
            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
"Name")
            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 RestoreSecret where
  hashWithSalt :: Int -> RestoreSecret -> Int
hashWithSalt Int
_salt RestoreSecret' {Text
secretId :: Text
$sel:secretId:RestoreSecret' :: RestoreSecret -> Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
secretId

instance Prelude.NFData RestoreSecret where
  rnf :: RestoreSecret -> ()
rnf RestoreSecret' {Text
secretId :: Text
$sel:secretId:RestoreSecret' :: RestoreSecret -> Text
..} = forall a. NFData a => a -> ()
Prelude.rnf Text
secretId

instance Data.ToHeaders RestoreSecret where
  toHeaders :: RestoreSecret -> 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
"secretsmanager.RestoreSecret" ::
                          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 RestoreSecret where
  toJSON :: RestoreSecret -> Value
toJSON RestoreSecret' {Text
secretId :: Text
$sel:secretId:RestoreSecret' :: RestoreSecret -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [forall a. a -> Maybe a
Prelude.Just (Key
"SecretId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
secretId)]
      )

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

instance Data.ToQuery RestoreSecret where
  toQuery :: RestoreSecret -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const 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 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
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]
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
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. 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 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'
    { $sel:arn:RestoreSecretResponse' :: Maybe Text
arn = forall a. Maybe a
Prelude.Nothing,
      $sel:name:RestoreSecretResponse' :: Maybe Text
name = 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 :: Lens' RestoreSecretResponse (Maybe Text)
restoreSecretResponse_arn = 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 name of the secret that was restored.
restoreSecretResponse_name :: Lens.Lens' RestoreSecretResponse (Prelude.Maybe Prelude.Text)
restoreSecretResponse_name :: Lens' RestoreSecretResponse (Maybe Text)
restoreSecretResponse_name = 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 :: Lens' RestoreSecretResponse Int
restoreSecretResponse_httpStatus = 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 where
  rnf :: RestoreSecretResponse -> ()
rnf RestoreSecretResponse' {Int
Maybe Text
httpStatus :: Int
name :: Maybe Text
arn :: Maybe Text
$sel:httpStatus:RestoreSecretResponse' :: RestoreSecretResponse -> Int
$sel:name:RestoreSecretResponse' :: RestoreSecretResponse -> Maybe Text
$sel:arn:RestoreSecretResponse' :: RestoreSecretResponse -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
arn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus