{-# 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.S3.DeleteBucketPolicy
-- 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)
--
-- This implementation of the DELETE action uses the policy subresource to
-- delete the policy of a specified bucket. If you are using an identity
-- other than the root user of the Amazon Web Services account that owns
-- the bucket, the calling identity must have the @DeleteBucketPolicy@
-- permissions on the specified bucket and belong to the bucket owner\'s
-- account to use this operation.
--
-- If you don\'t have @DeleteBucketPolicy@ permissions, Amazon S3 returns a
-- @403 Access Denied@ error. If you have the correct permissions, but
-- you\'re not using an identity that belongs to the bucket owner\'s
-- account, Amazon S3 returns a @405 Method Not Allowed@ error.
--
-- As a security precaution, the root user of the Amazon Web Services
-- account that owns a bucket can always use this operation, even if the
-- policy explicitly denies the root user the ability to perform this
-- action.
--
-- For more information about bucket policies, see
-- <https://docs.aws.amazon.com/AmazonS3/latest/dev/using-iam-policies.html Using Bucket Policies and UserPolicies>.
--
-- The following operations are related to @DeleteBucketPolicy@
--
-- -   <https://docs.aws.amazon.com/AmazonS3/latest/API/API_CreateBucket.html CreateBucket>
--
-- -   <https://docs.aws.amazon.com/AmazonS3/latest/API/API_DeleteObject.html DeleteObject>
module Amazonka.S3.DeleteBucketPolicy
  ( -- * Creating a Request
    DeleteBucketPolicy (..),
    newDeleteBucketPolicy,

    -- * Request Lenses
    deleteBucketPolicy_expectedBucketOwner,
    deleteBucketPolicy_bucket,

    -- * Destructuring the Response
    DeleteBucketPolicyResponse (..),
    newDeleteBucketPolicyResponse,
  )
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.S3.Types

-- | /See:/ 'newDeleteBucketPolicy' smart constructor.
data DeleteBucketPolicy = DeleteBucketPolicy'
  { -- | The account ID of the expected bucket owner. If the bucket is owned by a
    -- different account, the request will fail with an HTTP
    -- @403 (Access Denied)@ error.
    DeleteBucketPolicy -> Maybe Text
expectedBucketOwner :: Prelude.Maybe Prelude.Text,
    -- | The bucket name.
    DeleteBucketPolicy -> BucketName
bucket :: BucketName
  }
  deriving (DeleteBucketPolicy -> DeleteBucketPolicy -> Bool
(DeleteBucketPolicy -> DeleteBucketPolicy -> Bool)
-> (DeleteBucketPolicy -> DeleteBucketPolicy -> Bool)
-> Eq DeleteBucketPolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeleteBucketPolicy -> DeleteBucketPolicy -> Bool
$c/= :: DeleteBucketPolicy -> DeleteBucketPolicy -> Bool
== :: DeleteBucketPolicy -> DeleteBucketPolicy -> Bool
$c== :: DeleteBucketPolicy -> DeleteBucketPolicy -> Bool
Prelude.Eq, ReadPrec [DeleteBucketPolicy]
ReadPrec DeleteBucketPolicy
Int -> ReadS DeleteBucketPolicy
ReadS [DeleteBucketPolicy]
(Int -> ReadS DeleteBucketPolicy)
-> ReadS [DeleteBucketPolicy]
-> ReadPrec DeleteBucketPolicy
-> ReadPrec [DeleteBucketPolicy]
-> Read DeleteBucketPolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeleteBucketPolicy]
$creadListPrec :: ReadPrec [DeleteBucketPolicy]
readPrec :: ReadPrec DeleteBucketPolicy
$creadPrec :: ReadPrec DeleteBucketPolicy
readList :: ReadS [DeleteBucketPolicy]
$creadList :: ReadS [DeleteBucketPolicy]
readsPrec :: Int -> ReadS DeleteBucketPolicy
$creadsPrec :: Int -> ReadS DeleteBucketPolicy
Prelude.Read, Int -> DeleteBucketPolicy -> ShowS
[DeleteBucketPolicy] -> ShowS
DeleteBucketPolicy -> String
(Int -> DeleteBucketPolicy -> ShowS)
-> (DeleteBucketPolicy -> String)
-> ([DeleteBucketPolicy] -> ShowS)
-> Show DeleteBucketPolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeleteBucketPolicy] -> ShowS
$cshowList :: [DeleteBucketPolicy] -> ShowS
show :: DeleteBucketPolicy -> String
$cshow :: DeleteBucketPolicy -> String
showsPrec :: Int -> DeleteBucketPolicy -> ShowS
$cshowsPrec :: Int -> DeleteBucketPolicy -> ShowS
Prelude.Show, (forall x. DeleteBucketPolicy -> Rep DeleteBucketPolicy x)
-> (forall x. Rep DeleteBucketPolicy x -> DeleteBucketPolicy)
-> Generic DeleteBucketPolicy
forall x. Rep DeleteBucketPolicy x -> DeleteBucketPolicy
forall x. DeleteBucketPolicy -> Rep DeleteBucketPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeleteBucketPolicy x -> DeleteBucketPolicy
$cfrom :: forall x. DeleteBucketPolicy -> Rep DeleteBucketPolicy x
Prelude.Generic)

-- |
-- Create a value of 'DeleteBucketPolicy' 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:
--
-- 'expectedBucketOwner', 'deleteBucketPolicy_expectedBucketOwner' - The account ID of the expected bucket owner. If the bucket is owned by a
-- different account, the request will fail with an HTTP
-- @403 (Access Denied)@ error.
--
-- 'bucket', 'deleteBucketPolicy_bucket' - The bucket name.
newDeleteBucketPolicy ::
  -- | 'bucket'
  BucketName ->
  DeleteBucketPolicy
newDeleteBucketPolicy :: BucketName -> DeleteBucketPolicy
newDeleteBucketPolicy BucketName
pBucket_ =
  DeleteBucketPolicy' :: Maybe Text -> BucketName -> DeleteBucketPolicy
DeleteBucketPolicy'
    { $sel:expectedBucketOwner:DeleteBucketPolicy' :: Maybe Text
expectedBucketOwner =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:bucket:DeleteBucketPolicy' :: BucketName
bucket = BucketName
pBucket_
    }

-- | The account ID of the expected bucket owner. If the bucket is owned by a
-- different account, the request will fail with an HTTP
-- @403 (Access Denied)@ error.
deleteBucketPolicy_expectedBucketOwner :: Lens.Lens' DeleteBucketPolicy (Prelude.Maybe Prelude.Text)
deleteBucketPolicy_expectedBucketOwner :: (Maybe Text -> f (Maybe Text))
-> DeleteBucketPolicy -> f DeleteBucketPolicy
deleteBucketPolicy_expectedBucketOwner = (DeleteBucketPolicy -> Maybe Text)
-> (DeleteBucketPolicy -> Maybe Text -> DeleteBucketPolicy)
-> Lens
     DeleteBucketPolicy DeleteBucketPolicy (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteBucketPolicy' {Maybe Text
expectedBucketOwner :: Maybe Text
$sel:expectedBucketOwner:DeleteBucketPolicy' :: DeleteBucketPolicy -> Maybe Text
expectedBucketOwner} -> Maybe Text
expectedBucketOwner) (\s :: DeleteBucketPolicy
s@DeleteBucketPolicy' {} Maybe Text
a -> DeleteBucketPolicy
s {$sel:expectedBucketOwner:DeleteBucketPolicy' :: Maybe Text
expectedBucketOwner = Maybe Text
a} :: DeleteBucketPolicy)

-- | The bucket name.
deleteBucketPolicy_bucket :: Lens.Lens' DeleteBucketPolicy BucketName
deleteBucketPolicy_bucket :: (BucketName -> f BucketName)
-> DeleteBucketPolicy -> f DeleteBucketPolicy
deleteBucketPolicy_bucket = (DeleteBucketPolicy -> BucketName)
-> (DeleteBucketPolicy -> BucketName -> DeleteBucketPolicy)
-> Lens DeleteBucketPolicy DeleteBucketPolicy BucketName BucketName
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteBucketPolicy' {BucketName
bucket :: BucketName
$sel:bucket:DeleteBucketPolicy' :: DeleteBucketPolicy -> BucketName
bucket} -> BucketName
bucket) (\s :: DeleteBucketPolicy
s@DeleteBucketPolicy' {} BucketName
a -> DeleteBucketPolicy
s {$sel:bucket:DeleteBucketPolicy' :: BucketName
bucket = BucketName
a} :: DeleteBucketPolicy)

instance Core.AWSRequest DeleteBucketPolicy where
  type
    AWSResponse DeleteBucketPolicy =
      DeleteBucketPolicyResponse
  request :: DeleteBucketPolicy -> Request DeleteBucketPolicy
request =
    Request DeleteBucketPolicy -> Request DeleteBucketPolicy
forall a. Request a -> Request a
Request.s3vhost
      (Request DeleteBucketPolicy -> Request DeleteBucketPolicy)
-> (DeleteBucketPolicy -> Request DeleteBucketPolicy)
-> DeleteBucketPolicy
-> Request DeleteBucketPolicy
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. Service -> DeleteBucketPolicy -> Request DeleteBucketPolicy
forall a. ToRequest a => Service -> a -> Request a
Request.delete Service
defaultService
  response :: Logger
-> Service
-> Proxy DeleteBucketPolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse DeleteBucketPolicy)))
response =
    AWSResponse DeleteBucketPolicy
-> Logger
-> Service
-> Proxy DeleteBucketPolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse DeleteBucketPolicy)))
forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull AWSResponse DeleteBucketPolicy
DeleteBucketPolicyResponse
DeleteBucketPolicyResponse'

instance Prelude.Hashable DeleteBucketPolicy

instance Prelude.NFData DeleteBucketPolicy

instance Core.ToHeaders DeleteBucketPolicy where
  toHeaders :: DeleteBucketPolicy -> [Header]
toHeaders DeleteBucketPolicy' {Maybe Text
BucketName
bucket :: BucketName
expectedBucketOwner :: Maybe Text
$sel:bucket:DeleteBucketPolicy' :: DeleteBucketPolicy -> BucketName
$sel:expectedBucketOwner:DeleteBucketPolicy' :: DeleteBucketPolicy -> Maybe Text
..} =
    [[Header]] -> [Header]
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ HeaderName
"x-amz-expected-bucket-owner"
          HeaderName -> Maybe Text -> [Header]
forall a. ToHeader a => HeaderName -> a -> [Header]
Core.=# Maybe Text
expectedBucketOwner
      ]

instance Core.ToPath DeleteBucketPolicy where
  toPath :: DeleteBucketPolicy -> ByteString
toPath DeleteBucketPolicy' {Maybe Text
BucketName
bucket :: BucketName
expectedBucketOwner :: Maybe Text
$sel:bucket:DeleteBucketPolicy' :: DeleteBucketPolicy -> BucketName
$sel:expectedBucketOwner:DeleteBucketPolicy' :: DeleteBucketPolicy -> Maybe Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat [ByteString
"/", BucketName -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS BucketName
bucket]

instance Core.ToQuery DeleteBucketPolicy where
  toQuery :: DeleteBucketPolicy -> QueryString
toQuery = QueryString -> DeleteBucketPolicy -> QueryString
forall a b. a -> b -> a
Prelude.const ([QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat [QueryString
"policy"])

-- | /See:/ 'newDeleteBucketPolicyResponse' smart constructor.
data DeleteBucketPolicyResponse = DeleteBucketPolicyResponse'
  {
  }
  deriving (DeleteBucketPolicyResponse -> DeleteBucketPolicyResponse -> Bool
(DeleteBucketPolicyResponse -> DeleteBucketPolicyResponse -> Bool)
-> (DeleteBucketPolicyResponse
    -> DeleteBucketPolicyResponse -> Bool)
-> Eq DeleteBucketPolicyResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeleteBucketPolicyResponse -> DeleteBucketPolicyResponse -> Bool
$c/= :: DeleteBucketPolicyResponse -> DeleteBucketPolicyResponse -> Bool
== :: DeleteBucketPolicyResponse -> DeleteBucketPolicyResponse -> Bool
$c== :: DeleteBucketPolicyResponse -> DeleteBucketPolicyResponse -> Bool
Prelude.Eq, ReadPrec [DeleteBucketPolicyResponse]
ReadPrec DeleteBucketPolicyResponse
Int -> ReadS DeleteBucketPolicyResponse
ReadS [DeleteBucketPolicyResponse]
(Int -> ReadS DeleteBucketPolicyResponse)
-> ReadS [DeleteBucketPolicyResponse]
-> ReadPrec DeleteBucketPolicyResponse
-> ReadPrec [DeleteBucketPolicyResponse]
-> Read DeleteBucketPolicyResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeleteBucketPolicyResponse]
$creadListPrec :: ReadPrec [DeleteBucketPolicyResponse]
readPrec :: ReadPrec DeleteBucketPolicyResponse
$creadPrec :: ReadPrec DeleteBucketPolicyResponse
readList :: ReadS [DeleteBucketPolicyResponse]
$creadList :: ReadS [DeleteBucketPolicyResponse]
readsPrec :: Int -> ReadS DeleteBucketPolicyResponse
$creadsPrec :: Int -> ReadS DeleteBucketPolicyResponse
Prelude.Read, Int -> DeleteBucketPolicyResponse -> ShowS
[DeleteBucketPolicyResponse] -> ShowS
DeleteBucketPolicyResponse -> String
(Int -> DeleteBucketPolicyResponse -> ShowS)
-> (DeleteBucketPolicyResponse -> String)
-> ([DeleteBucketPolicyResponse] -> ShowS)
-> Show DeleteBucketPolicyResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeleteBucketPolicyResponse] -> ShowS
$cshowList :: [DeleteBucketPolicyResponse] -> ShowS
show :: DeleteBucketPolicyResponse -> String
$cshow :: DeleteBucketPolicyResponse -> String
showsPrec :: Int -> DeleteBucketPolicyResponse -> ShowS
$cshowsPrec :: Int -> DeleteBucketPolicyResponse -> ShowS
Prelude.Show, (forall x.
 DeleteBucketPolicyResponse -> Rep DeleteBucketPolicyResponse x)
-> (forall x.
    Rep DeleteBucketPolicyResponse x -> DeleteBucketPolicyResponse)
-> Generic DeleteBucketPolicyResponse
forall x.
Rep DeleteBucketPolicyResponse x -> DeleteBucketPolicyResponse
forall x.
DeleteBucketPolicyResponse -> Rep DeleteBucketPolicyResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep DeleteBucketPolicyResponse x -> DeleteBucketPolicyResponse
$cfrom :: forall x.
DeleteBucketPolicyResponse -> Rep DeleteBucketPolicyResponse x
Prelude.Generic)

-- |
-- Create a value of 'DeleteBucketPolicyResponse' 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.
newDeleteBucketPolicyResponse ::
  DeleteBucketPolicyResponse
newDeleteBucketPolicyResponse :: DeleteBucketPolicyResponse
newDeleteBucketPolicyResponse =
  DeleteBucketPolicyResponse
DeleteBucketPolicyResponse'

instance Prelude.NFData DeleteBucketPolicyResponse