{-# 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.DeleteResourcePolicy
-- 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 the resource-based permission policy attached to the secret.
--
-- __Minimum permissions__
--
-- To run this command, you must have the following permissions:
--
-- -   secretsmanager:DeleteResourcePolicy
--
-- __Related operations__
--
-- -   To attach a resource policy to a secret, use PutResourcePolicy.
--
-- -   To retrieve the current resource-based policy attached to a secret,
--     use GetResourcePolicy.
--
-- -   To list all of the currently available secrets, use ListSecrets.
module Amazonka.SecretsManager.DeleteResourcePolicy
  ( -- * Creating a Request
    DeleteResourcePolicy (..),
    newDeleteResourcePolicy,

    -- * Request Lenses
    deleteResourcePolicy_secretId,

    -- * Destructuring the Response
    DeleteResourcePolicyResponse (..),
    newDeleteResourcePolicyResponse,

    -- * Response Lenses
    deleteResourcePolicyResponse_arn,
    deleteResourcePolicyResponse_name,
    deleteResourcePolicyResponse_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:/ 'newDeleteResourcePolicy' smart constructor.
data DeleteResourcePolicy = DeleteResourcePolicy'
  { -- | Specifies the secret that you want to delete the attached resource-based
    -- policy for. 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.
    DeleteResourcePolicy -> Text
secretId :: Prelude.Text
  }
  deriving (DeleteResourcePolicy -> DeleteResourcePolicy -> Bool
(DeleteResourcePolicy -> DeleteResourcePolicy -> Bool)
-> (DeleteResourcePolicy -> DeleteResourcePolicy -> Bool)
-> Eq DeleteResourcePolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeleteResourcePolicy -> DeleteResourcePolicy -> Bool
$c/= :: DeleteResourcePolicy -> DeleteResourcePolicy -> Bool
== :: DeleteResourcePolicy -> DeleteResourcePolicy -> Bool
$c== :: DeleteResourcePolicy -> DeleteResourcePolicy -> Bool
Prelude.Eq, ReadPrec [DeleteResourcePolicy]
ReadPrec DeleteResourcePolicy
Int -> ReadS DeleteResourcePolicy
ReadS [DeleteResourcePolicy]
(Int -> ReadS DeleteResourcePolicy)
-> ReadS [DeleteResourcePolicy]
-> ReadPrec DeleteResourcePolicy
-> ReadPrec [DeleteResourcePolicy]
-> Read DeleteResourcePolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeleteResourcePolicy]
$creadListPrec :: ReadPrec [DeleteResourcePolicy]
readPrec :: ReadPrec DeleteResourcePolicy
$creadPrec :: ReadPrec DeleteResourcePolicy
readList :: ReadS [DeleteResourcePolicy]
$creadList :: ReadS [DeleteResourcePolicy]
readsPrec :: Int -> ReadS DeleteResourcePolicy
$creadsPrec :: Int -> ReadS DeleteResourcePolicy
Prelude.Read, Int -> DeleteResourcePolicy -> ShowS
[DeleteResourcePolicy] -> ShowS
DeleteResourcePolicy -> String
(Int -> DeleteResourcePolicy -> ShowS)
-> (DeleteResourcePolicy -> String)
-> ([DeleteResourcePolicy] -> ShowS)
-> Show DeleteResourcePolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeleteResourcePolicy] -> ShowS
$cshowList :: [DeleteResourcePolicy] -> ShowS
show :: DeleteResourcePolicy -> String
$cshow :: DeleteResourcePolicy -> String
showsPrec :: Int -> DeleteResourcePolicy -> ShowS
$cshowsPrec :: Int -> DeleteResourcePolicy -> ShowS
Prelude.Show, (forall x. DeleteResourcePolicy -> Rep DeleteResourcePolicy x)
-> (forall x. Rep DeleteResourcePolicy x -> DeleteResourcePolicy)
-> Generic DeleteResourcePolicy
forall x. Rep DeleteResourcePolicy x -> DeleteResourcePolicy
forall x. DeleteResourcePolicy -> Rep DeleteResourcePolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeleteResourcePolicy x -> DeleteResourcePolicy
$cfrom :: forall x. DeleteResourcePolicy -> Rep DeleteResourcePolicy x
Prelude.Generic)

-- |
-- Create a value of 'DeleteResourcePolicy' 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', 'deleteResourcePolicy_secretId' - Specifies the secret that you want to delete the attached resource-based
-- policy for. 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.
newDeleteResourcePolicy ::
  -- | 'secretId'
  Prelude.Text ->
  DeleteResourcePolicy
newDeleteResourcePolicy :: Text -> DeleteResourcePolicy
newDeleteResourcePolicy Text
pSecretId_ =
  DeleteResourcePolicy' :: Text -> DeleteResourcePolicy
DeleteResourcePolicy' {$sel:secretId:DeleteResourcePolicy' :: Text
secretId = Text
pSecretId_}

-- | Specifies the secret that you want to delete the attached resource-based
-- policy for. 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.
deleteResourcePolicy_secretId :: Lens.Lens' DeleteResourcePolicy Prelude.Text
deleteResourcePolicy_secretId :: (Text -> f Text) -> DeleteResourcePolicy -> f DeleteResourcePolicy
deleteResourcePolicy_secretId = (DeleteResourcePolicy -> Text)
-> (DeleteResourcePolicy -> Text -> DeleteResourcePolicy)
-> Lens DeleteResourcePolicy DeleteResourcePolicy Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteResourcePolicy' {Text
secretId :: Text
$sel:secretId:DeleteResourcePolicy' :: DeleteResourcePolicy -> Text
secretId} -> Text
secretId) (\s :: DeleteResourcePolicy
s@DeleteResourcePolicy' {} Text
a -> DeleteResourcePolicy
s {$sel:secretId:DeleteResourcePolicy' :: Text
secretId = Text
a} :: DeleteResourcePolicy)

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

instance Prelude.NFData DeleteResourcePolicy

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

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

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

-- |
-- Create a value of 'DeleteResourcePolicyResponse' 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', 'deleteResourcePolicyResponse_arn' - The ARN of the secret that the resource-based policy was deleted for.
--
-- 'name', 'deleteResourcePolicyResponse_name' - The friendly name of the secret that the resource-based policy was
-- deleted for.
--
-- 'httpStatus', 'deleteResourcePolicyResponse_httpStatus' - The response's http status code.
newDeleteResourcePolicyResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DeleteResourcePolicyResponse
newDeleteResourcePolicyResponse :: Int -> DeleteResourcePolicyResponse
newDeleteResourcePolicyResponse Int
pHttpStatus_ =
  DeleteResourcePolicyResponse' :: Maybe Text -> Maybe Text -> Int -> DeleteResourcePolicyResponse
DeleteResourcePolicyResponse'
    { $sel:arn:DeleteResourcePolicyResponse' :: Maybe Text
arn =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:name:DeleteResourcePolicyResponse' :: Maybe Text
name = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DeleteResourcePolicyResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The ARN of the secret that the resource-based policy was deleted for.
deleteResourcePolicyResponse_arn :: Lens.Lens' DeleteResourcePolicyResponse (Prelude.Maybe Prelude.Text)
deleteResourcePolicyResponse_arn :: (Maybe Text -> f (Maybe Text))
-> DeleteResourcePolicyResponse -> f DeleteResourcePolicyResponse
deleteResourcePolicyResponse_arn = (DeleteResourcePolicyResponse -> Maybe Text)
-> (DeleteResourcePolicyResponse
    -> Maybe Text -> DeleteResourcePolicyResponse)
-> Lens
     DeleteResourcePolicyResponse
     DeleteResourcePolicyResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteResourcePolicyResponse' {Maybe Text
arn :: Maybe Text
$sel:arn:DeleteResourcePolicyResponse' :: DeleteResourcePolicyResponse -> Maybe Text
arn} -> Maybe Text
arn) (\s :: DeleteResourcePolicyResponse
s@DeleteResourcePolicyResponse' {} Maybe Text
a -> DeleteResourcePolicyResponse
s {$sel:arn:DeleteResourcePolicyResponse' :: Maybe Text
arn = Maybe Text
a} :: DeleteResourcePolicyResponse)

-- | The friendly name of the secret that the resource-based policy was
-- deleted for.
deleteResourcePolicyResponse_name :: Lens.Lens' DeleteResourcePolicyResponse (Prelude.Maybe Prelude.Text)
deleteResourcePolicyResponse_name :: (Maybe Text -> f (Maybe Text))
-> DeleteResourcePolicyResponse -> f DeleteResourcePolicyResponse
deleteResourcePolicyResponse_name = (DeleteResourcePolicyResponse -> Maybe Text)
-> (DeleteResourcePolicyResponse
    -> Maybe Text -> DeleteResourcePolicyResponse)
-> Lens
     DeleteResourcePolicyResponse
     DeleteResourcePolicyResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteResourcePolicyResponse' {Maybe Text
name :: Maybe Text
$sel:name:DeleteResourcePolicyResponse' :: DeleteResourcePolicyResponse -> Maybe Text
name} -> Maybe Text
name) (\s :: DeleteResourcePolicyResponse
s@DeleteResourcePolicyResponse' {} Maybe Text
a -> DeleteResourcePolicyResponse
s {$sel:name:DeleteResourcePolicyResponse' :: Maybe Text
name = Maybe Text
a} :: DeleteResourcePolicyResponse)

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

instance Prelude.NFData DeleteResourcePolicyResponse