{-# 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.PutBucketOwnershipControls
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Creates or modifies @OwnershipControls@ for an Amazon S3 bucket. To use
-- this operation, you must have the @s3:PutBucketOwnershipControls@
-- permission. For more information about Amazon S3 permissions, see
-- <https://docs.aws.amazon.com/AmazonS3/latest/user-guide/using-with-s3-actions.html Specifying permissions in a policy>.
--
-- For information about Amazon S3 Object Ownership, see
-- <https://docs.aws.amazon.com/AmazonS3/latest/user-guide/about-object-ownership.html Using object ownership>.
--
-- The following operations are related to @PutBucketOwnershipControls@:
--
-- -   GetBucketOwnershipControls
--
-- -   DeleteBucketOwnershipControls
module Amazonka.S3.PutBucketOwnershipControls
  ( -- * Creating a Request
    PutBucketOwnershipControls (..),
    newPutBucketOwnershipControls,

    -- * Request Lenses
    putBucketOwnershipControls_contentMD5,
    putBucketOwnershipControls_expectedBucketOwner,
    putBucketOwnershipControls_bucket,
    putBucketOwnershipControls_ownershipControls,

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

-- | /See:/ 'newPutBucketOwnershipControls' smart constructor.
data PutBucketOwnershipControls = PutBucketOwnershipControls'
  { -- | The MD5 hash of the @OwnershipControls@ request body.
    --
    -- For requests made using the Amazon Web Services Command Line Interface
    -- (CLI) or Amazon Web Services SDKs, this field is calculated
    -- automatically.
    PutBucketOwnershipControls -> Maybe Text
contentMD5 :: Prelude.Maybe Prelude.Text,
    -- | The account ID of the expected bucket owner. If the bucket is owned by a
    -- different account, the request fails with the HTTP status code
    -- @403 Forbidden@ (access denied).
    PutBucketOwnershipControls -> Maybe Text
expectedBucketOwner :: Prelude.Maybe Prelude.Text,
    -- | The name of the Amazon S3 bucket whose @OwnershipControls@ you want to
    -- set.
    PutBucketOwnershipControls -> BucketName
bucket :: BucketName,
    -- | The @OwnershipControls@ (BucketOwnerEnforced, BucketOwnerPreferred, or
    -- ObjectWriter) that you want to apply to this Amazon S3 bucket.
    PutBucketOwnershipControls -> OwnershipControls
ownershipControls :: OwnershipControls
  }
  deriving (PutBucketOwnershipControls -> PutBucketOwnershipControls -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutBucketOwnershipControls -> PutBucketOwnershipControls -> Bool
$c/= :: PutBucketOwnershipControls -> PutBucketOwnershipControls -> Bool
== :: PutBucketOwnershipControls -> PutBucketOwnershipControls -> Bool
$c== :: PutBucketOwnershipControls -> PutBucketOwnershipControls -> Bool
Prelude.Eq, ReadPrec [PutBucketOwnershipControls]
ReadPrec PutBucketOwnershipControls
Int -> ReadS PutBucketOwnershipControls
ReadS [PutBucketOwnershipControls]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutBucketOwnershipControls]
$creadListPrec :: ReadPrec [PutBucketOwnershipControls]
readPrec :: ReadPrec PutBucketOwnershipControls
$creadPrec :: ReadPrec PutBucketOwnershipControls
readList :: ReadS [PutBucketOwnershipControls]
$creadList :: ReadS [PutBucketOwnershipControls]
readsPrec :: Int -> ReadS PutBucketOwnershipControls
$creadsPrec :: Int -> ReadS PutBucketOwnershipControls
Prelude.Read, Int -> PutBucketOwnershipControls -> ShowS
[PutBucketOwnershipControls] -> ShowS
PutBucketOwnershipControls -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutBucketOwnershipControls] -> ShowS
$cshowList :: [PutBucketOwnershipControls] -> ShowS
show :: PutBucketOwnershipControls -> String
$cshow :: PutBucketOwnershipControls -> String
showsPrec :: Int -> PutBucketOwnershipControls -> ShowS
$cshowsPrec :: Int -> PutBucketOwnershipControls -> ShowS
Prelude.Show, forall x.
Rep PutBucketOwnershipControls x -> PutBucketOwnershipControls
forall x.
PutBucketOwnershipControls -> Rep PutBucketOwnershipControls x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep PutBucketOwnershipControls x -> PutBucketOwnershipControls
$cfrom :: forall x.
PutBucketOwnershipControls -> Rep PutBucketOwnershipControls x
Prelude.Generic)

-- |
-- Create a value of 'PutBucketOwnershipControls' 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:
--
-- 'contentMD5', 'putBucketOwnershipControls_contentMD5' - The MD5 hash of the @OwnershipControls@ request body.
--
-- For requests made using the Amazon Web Services Command Line Interface
-- (CLI) or Amazon Web Services SDKs, this field is calculated
-- automatically.
--
-- 'expectedBucketOwner', 'putBucketOwnershipControls_expectedBucketOwner' - The account ID of the expected bucket owner. If the bucket is owned by a
-- different account, the request fails with the HTTP status code
-- @403 Forbidden@ (access denied).
--
-- 'bucket', 'putBucketOwnershipControls_bucket' - The name of the Amazon S3 bucket whose @OwnershipControls@ you want to
-- set.
--
-- 'ownershipControls', 'putBucketOwnershipControls_ownershipControls' - The @OwnershipControls@ (BucketOwnerEnforced, BucketOwnerPreferred, or
-- ObjectWriter) that you want to apply to this Amazon S3 bucket.
newPutBucketOwnershipControls ::
  -- | 'bucket'
  BucketName ->
  -- | 'ownershipControls'
  OwnershipControls ->
  PutBucketOwnershipControls
newPutBucketOwnershipControls :: BucketName -> OwnershipControls -> PutBucketOwnershipControls
newPutBucketOwnershipControls
  BucketName
pBucket_
  OwnershipControls
pOwnershipControls_ =
    PutBucketOwnershipControls'
      { $sel:contentMD5:PutBucketOwnershipControls' :: Maybe Text
contentMD5 =
          forall a. Maybe a
Prelude.Nothing,
        $sel:expectedBucketOwner:PutBucketOwnershipControls' :: Maybe Text
expectedBucketOwner = forall a. Maybe a
Prelude.Nothing,
        $sel:bucket:PutBucketOwnershipControls' :: BucketName
bucket = BucketName
pBucket_,
        $sel:ownershipControls:PutBucketOwnershipControls' :: OwnershipControls
ownershipControls = OwnershipControls
pOwnershipControls_
      }

-- | The MD5 hash of the @OwnershipControls@ request body.
--
-- For requests made using the Amazon Web Services Command Line Interface
-- (CLI) or Amazon Web Services SDKs, this field is calculated
-- automatically.
putBucketOwnershipControls_contentMD5 :: Lens.Lens' PutBucketOwnershipControls (Prelude.Maybe Prelude.Text)
putBucketOwnershipControls_contentMD5 :: Lens' PutBucketOwnershipControls (Maybe Text)
putBucketOwnershipControls_contentMD5 = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutBucketOwnershipControls' {Maybe Text
contentMD5 :: Maybe Text
$sel:contentMD5:PutBucketOwnershipControls' :: PutBucketOwnershipControls -> Maybe Text
contentMD5} -> Maybe Text
contentMD5) (\s :: PutBucketOwnershipControls
s@PutBucketOwnershipControls' {} Maybe Text
a -> PutBucketOwnershipControls
s {$sel:contentMD5:PutBucketOwnershipControls' :: Maybe Text
contentMD5 = Maybe Text
a} :: PutBucketOwnershipControls)

-- | The account ID of the expected bucket owner. If the bucket is owned by a
-- different account, the request fails with the HTTP status code
-- @403 Forbidden@ (access denied).
putBucketOwnershipControls_expectedBucketOwner :: Lens.Lens' PutBucketOwnershipControls (Prelude.Maybe Prelude.Text)
putBucketOwnershipControls_expectedBucketOwner :: Lens' PutBucketOwnershipControls (Maybe Text)
putBucketOwnershipControls_expectedBucketOwner = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutBucketOwnershipControls' {Maybe Text
expectedBucketOwner :: Maybe Text
$sel:expectedBucketOwner:PutBucketOwnershipControls' :: PutBucketOwnershipControls -> Maybe Text
expectedBucketOwner} -> Maybe Text
expectedBucketOwner) (\s :: PutBucketOwnershipControls
s@PutBucketOwnershipControls' {} Maybe Text
a -> PutBucketOwnershipControls
s {$sel:expectedBucketOwner:PutBucketOwnershipControls' :: Maybe Text
expectedBucketOwner = Maybe Text
a} :: PutBucketOwnershipControls)

-- | The name of the Amazon S3 bucket whose @OwnershipControls@ you want to
-- set.
putBucketOwnershipControls_bucket :: Lens.Lens' PutBucketOwnershipControls BucketName
putBucketOwnershipControls_bucket :: Lens' PutBucketOwnershipControls BucketName
putBucketOwnershipControls_bucket = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutBucketOwnershipControls' {BucketName
bucket :: BucketName
$sel:bucket:PutBucketOwnershipControls' :: PutBucketOwnershipControls -> BucketName
bucket} -> BucketName
bucket) (\s :: PutBucketOwnershipControls
s@PutBucketOwnershipControls' {} BucketName
a -> PutBucketOwnershipControls
s {$sel:bucket:PutBucketOwnershipControls' :: BucketName
bucket = BucketName
a} :: PutBucketOwnershipControls)

-- | The @OwnershipControls@ (BucketOwnerEnforced, BucketOwnerPreferred, or
-- ObjectWriter) that you want to apply to this Amazon S3 bucket.
putBucketOwnershipControls_ownershipControls :: Lens.Lens' PutBucketOwnershipControls OwnershipControls
putBucketOwnershipControls_ownershipControls :: Lens' PutBucketOwnershipControls OwnershipControls
putBucketOwnershipControls_ownershipControls = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutBucketOwnershipControls' {OwnershipControls
ownershipControls :: OwnershipControls
$sel:ownershipControls:PutBucketOwnershipControls' :: PutBucketOwnershipControls -> OwnershipControls
ownershipControls} -> OwnershipControls
ownershipControls) (\s :: PutBucketOwnershipControls
s@PutBucketOwnershipControls' {} OwnershipControls
a -> PutBucketOwnershipControls
s {$sel:ownershipControls:PutBucketOwnershipControls' :: OwnershipControls
ownershipControls = OwnershipControls
a} :: PutBucketOwnershipControls)

instance Core.AWSRequest PutBucketOwnershipControls where
  type
    AWSResponse PutBucketOwnershipControls =
      PutBucketOwnershipControlsResponse
  request :: (Service -> Service)
-> PutBucketOwnershipControls -> Request PutBucketOwnershipControls
request Service -> Service
overrides =
    forall a. Request a -> Request a
Request.s3vhost
      forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a. (ToRequest a, ToElement a) => Service -> a -> Request a
Request.putXML (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy PutBucketOwnershipControls
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse PutBucketOwnershipControls)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull
      PutBucketOwnershipControlsResponse
PutBucketOwnershipControlsResponse'

instance Prelude.Hashable PutBucketOwnershipControls where
  hashWithSalt :: Int -> PutBucketOwnershipControls -> Int
hashWithSalt Int
_salt PutBucketOwnershipControls' {Maybe Text
BucketName
OwnershipControls
ownershipControls :: OwnershipControls
bucket :: BucketName
expectedBucketOwner :: Maybe Text
contentMD5 :: Maybe Text
$sel:ownershipControls:PutBucketOwnershipControls' :: PutBucketOwnershipControls -> OwnershipControls
$sel:bucket:PutBucketOwnershipControls' :: PutBucketOwnershipControls -> BucketName
$sel:expectedBucketOwner:PutBucketOwnershipControls' :: PutBucketOwnershipControls -> Maybe Text
$sel:contentMD5:PutBucketOwnershipControls' :: PutBucketOwnershipControls -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
contentMD5
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
expectedBucketOwner
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` BucketName
bucket
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` OwnershipControls
ownershipControls

instance Prelude.NFData PutBucketOwnershipControls where
  rnf :: PutBucketOwnershipControls -> ()
rnf PutBucketOwnershipControls' {Maybe Text
BucketName
OwnershipControls
ownershipControls :: OwnershipControls
bucket :: BucketName
expectedBucketOwner :: Maybe Text
contentMD5 :: Maybe Text
$sel:ownershipControls:PutBucketOwnershipControls' :: PutBucketOwnershipControls -> OwnershipControls
$sel:bucket:PutBucketOwnershipControls' :: PutBucketOwnershipControls -> BucketName
$sel:expectedBucketOwner:PutBucketOwnershipControls' :: PutBucketOwnershipControls -> Maybe Text
$sel:contentMD5:PutBucketOwnershipControls' :: PutBucketOwnershipControls -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
contentMD5
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
expectedBucketOwner
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf BucketName
bucket
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf OwnershipControls
ownershipControls

instance Data.ToElement PutBucketOwnershipControls where
  toElement :: PutBucketOwnershipControls -> Element
toElement PutBucketOwnershipControls' {Maybe Text
BucketName
OwnershipControls
ownershipControls :: OwnershipControls
bucket :: BucketName
expectedBucketOwner :: Maybe Text
contentMD5 :: Maybe Text
$sel:ownershipControls:PutBucketOwnershipControls' :: PutBucketOwnershipControls -> OwnershipControls
$sel:bucket:PutBucketOwnershipControls' :: PutBucketOwnershipControls -> BucketName
$sel:expectedBucketOwner:PutBucketOwnershipControls' :: PutBucketOwnershipControls -> Maybe Text
$sel:contentMD5:PutBucketOwnershipControls' :: PutBucketOwnershipControls -> Maybe Text
..} =
    forall a. ToXML a => Name -> a -> Element
Data.mkElement
      Name
"{http://s3.amazonaws.com/doc/2006-03-01/}OwnershipControls"
      OwnershipControls
ownershipControls

instance Data.ToHeaders PutBucketOwnershipControls where
  toHeaders :: PutBucketOwnershipControls -> [Header]
toHeaders PutBucketOwnershipControls' {Maybe Text
BucketName
OwnershipControls
ownershipControls :: OwnershipControls
bucket :: BucketName
expectedBucketOwner :: Maybe Text
contentMD5 :: Maybe Text
$sel:ownershipControls:PutBucketOwnershipControls' :: PutBucketOwnershipControls -> OwnershipControls
$sel:bucket:PutBucketOwnershipControls' :: PutBucketOwnershipControls -> BucketName
$sel:expectedBucketOwner:PutBucketOwnershipControls' :: PutBucketOwnershipControls -> Maybe Text
$sel:contentMD5:PutBucketOwnershipControls' :: PutBucketOwnershipControls -> Maybe Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ HeaderName
"Content-MD5" forall a. ToHeader a => HeaderName -> a -> [Header]
Data.=# Maybe Text
contentMD5,
        HeaderName
"x-amz-expected-bucket-owner"
          forall a. ToHeader a => HeaderName -> a -> [Header]
Data.=# Maybe Text
expectedBucketOwner
      ]

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

instance Data.ToQuery PutBucketOwnershipControls where
  toQuery :: PutBucketOwnershipControls -> QueryString
toQuery =
    forall a b. a -> b -> a
Prelude.const
      (forall a. Monoid a => [a] -> a
Prelude.mconcat [QueryString
"ownershipControls"])

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

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

instance
  Prelude.NFData
    PutBucketOwnershipControlsResponse
  where
  rnf :: PutBucketOwnershipControlsResponse -> ()
rnf PutBucketOwnershipControlsResponse
_ = ()