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

    -- * Request Lenses
    getBucketOwnershipControls_expectedBucketOwner,
    getBucketOwnershipControls_bucket,

    -- * Destructuring the Response
    GetBucketOwnershipControlsResponse (..),
    newGetBucketOwnershipControlsResponse,

    -- * Response Lenses
    getBucketOwnershipControlsResponse_ownershipControls,
    getBucketOwnershipControlsResponse_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.S3.Types

-- | /See:/ 'newGetBucketOwnershipControls' smart constructor.
data GetBucketOwnershipControls = GetBucketOwnershipControls'
  { -- | 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).
    GetBucketOwnershipControls -> Maybe Text
expectedBucketOwner :: Prelude.Maybe Prelude.Text,
    -- | The name of the Amazon S3 bucket whose @OwnershipControls@ you want to
    -- retrieve.
    GetBucketOwnershipControls -> BucketName
bucket :: BucketName
  }
  deriving (GetBucketOwnershipControls -> GetBucketOwnershipControls -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetBucketOwnershipControls -> GetBucketOwnershipControls -> Bool
$c/= :: GetBucketOwnershipControls -> GetBucketOwnershipControls -> Bool
== :: GetBucketOwnershipControls -> GetBucketOwnershipControls -> Bool
$c== :: GetBucketOwnershipControls -> GetBucketOwnershipControls -> Bool
Prelude.Eq, ReadPrec [GetBucketOwnershipControls]
ReadPrec GetBucketOwnershipControls
Int -> ReadS GetBucketOwnershipControls
ReadS [GetBucketOwnershipControls]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetBucketOwnershipControls]
$creadListPrec :: ReadPrec [GetBucketOwnershipControls]
readPrec :: ReadPrec GetBucketOwnershipControls
$creadPrec :: ReadPrec GetBucketOwnershipControls
readList :: ReadS [GetBucketOwnershipControls]
$creadList :: ReadS [GetBucketOwnershipControls]
readsPrec :: Int -> ReadS GetBucketOwnershipControls
$creadsPrec :: Int -> ReadS GetBucketOwnershipControls
Prelude.Read, Int -> GetBucketOwnershipControls -> ShowS
[GetBucketOwnershipControls] -> ShowS
GetBucketOwnershipControls -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetBucketOwnershipControls] -> ShowS
$cshowList :: [GetBucketOwnershipControls] -> ShowS
show :: GetBucketOwnershipControls -> String
$cshow :: GetBucketOwnershipControls -> String
showsPrec :: Int -> GetBucketOwnershipControls -> ShowS
$cshowsPrec :: Int -> GetBucketOwnershipControls -> ShowS
Prelude.Show, forall x.
Rep GetBucketOwnershipControls x -> GetBucketOwnershipControls
forall x.
GetBucketOwnershipControls -> Rep GetBucketOwnershipControls x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetBucketOwnershipControls x -> GetBucketOwnershipControls
$cfrom :: forall x.
GetBucketOwnershipControls -> Rep GetBucketOwnershipControls x
Prelude.Generic)

-- |
-- Create a value of 'GetBucketOwnershipControls' 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', 'getBucketOwnershipControls_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', 'getBucketOwnershipControls_bucket' - The name of the Amazon S3 bucket whose @OwnershipControls@ you want to
-- retrieve.
newGetBucketOwnershipControls ::
  -- | 'bucket'
  BucketName ->
  GetBucketOwnershipControls
newGetBucketOwnershipControls :: BucketName -> GetBucketOwnershipControls
newGetBucketOwnershipControls BucketName
pBucket_ =
  GetBucketOwnershipControls'
    { $sel:expectedBucketOwner:GetBucketOwnershipControls' :: Maybe Text
expectedBucketOwner =
        forall a. Maybe a
Prelude.Nothing,
      $sel:bucket:GetBucketOwnershipControls' :: BucketName
bucket = BucketName
pBucket_
    }

-- | 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).
getBucketOwnershipControls_expectedBucketOwner :: Lens.Lens' GetBucketOwnershipControls (Prelude.Maybe Prelude.Text)
getBucketOwnershipControls_expectedBucketOwner :: Lens' GetBucketOwnershipControls (Maybe Text)
getBucketOwnershipControls_expectedBucketOwner = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetBucketOwnershipControls' {Maybe Text
expectedBucketOwner :: Maybe Text
$sel:expectedBucketOwner:GetBucketOwnershipControls' :: GetBucketOwnershipControls -> Maybe Text
expectedBucketOwner} -> Maybe Text
expectedBucketOwner) (\s :: GetBucketOwnershipControls
s@GetBucketOwnershipControls' {} Maybe Text
a -> GetBucketOwnershipControls
s {$sel:expectedBucketOwner:GetBucketOwnershipControls' :: Maybe Text
expectedBucketOwner = Maybe Text
a} :: GetBucketOwnershipControls)

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

instance Core.AWSRequest GetBucketOwnershipControls where
  type
    AWSResponse GetBucketOwnershipControls =
      GetBucketOwnershipControlsResponse
  request :: (Service -> Service)
-> GetBucketOwnershipControls -> Request GetBucketOwnershipControls
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 => Service -> a -> Request a
Request.get (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy GetBucketOwnershipControls
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetBucketOwnershipControls)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> [Node] -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveXML
      ( \Int
s ResponseHeaders
h [Node]
x ->
          Maybe OwnershipControls
-> Int -> GetBucketOwnershipControlsResponse
GetBucketOwnershipControlsResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (forall a. FromXML a => [Node] -> Either String a
Data.parseXML [Node]
x)
            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 GetBucketOwnershipControls where
  hashWithSalt :: Int -> GetBucketOwnershipControls -> Int
hashWithSalt Int
_salt GetBucketOwnershipControls' {Maybe Text
BucketName
bucket :: BucketName
expectedBucketOwner :: Maybe Text
$sel:bucket:GetBucketOwnershipControls' :: GetBucketOwnershipControls -> BucketName
$sel:expectedBucketOwner:GetBucketOwnershipControls' :: GetBucketOwnershipControls -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
expectedBucketOwner
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` BucketName
bucket

instance Prelude.NFData GetBucketOwnershipControls where
  rnf :: GetBucketOwnershipControls -> ()
rnf GetBucketOwnershipControls' {Maybe Text
BucketName
bucket :: BucketName
expectedBucketOwner :: Maybe Text
$sel:bucket:GetBucketOwnershipControls' :: GetBucketOwnershipControls -> BucketName
$sel:expectedBucketOwner:GetBucketOwnershipControls' :: GetBucketOwnershipControls -> Maybe Text
..} =
    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

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

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

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

-- | /See:/ 'newGetBucketOwnershipControlsResponse' smart constructor.
data GetBucketOwnershipControlsResponse = GetBucketOwnershipControlsResponse'
  { -- | The @OwnershipControls@ (BucketOwnerEnforced, BucketOwnerPreferred, or
    -- ObjectWriter) currently in effect for this Amazon S3 bucket.
    GetBucketOwnershipControlsResponse -> Maybe OwnershipControls
ownershipControls :: Prelude.Maybe OwnershipControls,
    -- | The response's http status code.
    GetBucketOwnershipControlsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetBucketOwnershipControlsResponse
-> GetBucketOwnershipControlsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetBucketOwnershipControlsResponse
-> GetBucketOwnershipControlsResponse -> Bool
$c/= :: GetBucketOwnershipControlsResponse
-> GetBucketOwnershipControlsResponse -> Bool
== :: GetBucketOwnershipControlsResponse
-> GetBucketOwnershipControlsResponse -> Bool
$c== :: GetBucketOwnershipControlsResponse
-> GetBucketOwnershipControlsResponse -> Bool
Prelude.Eq, ReadPrec [GetBucketOwnershipControlsResponse]
ReadPrec GetBucketOwnershipControlsResponse
Int -> ReadS GetBucketOwnershipControlsResponse
ReadS [GetBucketOwnershipControlsResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetBucketOwnershipControlsResponse]
$creadListPrec :: ReadPrec [GetBucketOwnershipControlsResponse]
readPrec :: ReadPrec GetBucketOwnershipControlsResponse
$creadPrec :: ReadPrec GetBucketOwnershipControlsResponse
readList :: ReadS [GetBucketOwnershipControlsResponse]
$creadList :: ReadS [GetBucketOwnershipControlsResponse]
readsPrec :: Int -> ReadS GetBucketOwnershipControlsResponse
$creadsPrec :: Int -> ReadS GetBucketOwnershipControlsResponse
Prelude.Read, Int -> GetBucketOwnershipControlsResponse -> ShowS
[GetBucketOwnershipControlsResponse] -> ShowS
GetBucketOwnershipControlsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetBucketOwnershipControlsResponse] -> ShowS
$cshowList :: [GetBucketOwnershipControlsResponse] -> ShowS
show :: GetBucketOwnershipControlsResponse -> String
$cshow :: GetBucketOwnershipControlsResponse -> String
showsPrec :: Int -> GetBucketOwnershipControlsResponse -> ShowS
$cshowsPrec :: Int -> GetBucketOwnershipControlsResponse -> ShowS
Prelude.Show, forall x.
Rep GetBucketOwnershipControlsResponse x
-> GetBucketOwnershipControlsResponse
forall x.
GetBucketOwnershipControlsResponse
-> Rep GetBucketOwnershipControlsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetBucketOwnershipControlsResponse x
-> GetBucketOwnershipControlsResponse
$cfrom :: forall x.
GetBucketOwnershipControlsResponse
-> Rep GetBucketOwnershipControlsResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetBucketOwnershipControlsResponse' 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:
--
-- 'ownershipControls', 'getBucketOwnershipControlsResponse_ownershipControls' - The @OwnershipControls@ (BucketOwnerEnforced, BucketOwnerPreferred, or
-- ObjectWriter) currently in effect for this Amazon S3 bucket.
--
-- 'httpStatus', 'getBucketOwnershipControlsResponse_httpStatus' - The response's http status code.
newGetBucketOwnershipControlsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetBucketOwnershipControlsResponse
newGetBucketOwnershipControlsResponse :: Int -> GetBucketOwnershipControlsResponse
newGetBucketOwnershipControlsResponse Int
pHttpStatus_ =
  GetBucketOwnershipControlsResponse'
    { $sel:ownershipControls:GetBucketOwnershipControlsResponse' :: Maybe OwnershipControls
ownershipControls =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetBucketOwnershipControlsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The @OwnershipControls@ (BucketOwnerEnforced, BucketOwnerPreferred, or
-- ObjectWriter) currently in effect for this Amazon S3 bucket.
getBucketOwnershipControlsResponse_ownershipControls :: Lens.Lens' GetBucketOwnershipControlsResponse (Prelude.Maybe OwnershipControls)
getBucketOwnershipControlsResponse_ownershipControls :: Lens' GetBucketOwnershipControlsResponse (Maybe OwnershipControls)
getBucketOwnershipControlsResponse_ownershipControls = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetBucketOwnershipControlsResponse' {Maybe OwnershipControls
ownershipControls :: Maybe OwnershipControls
$sel:ownershipControls:GetBucketOwnershipControlsResponse' :: GetBucketOwnershipControlsResponse -> Maybe OwnershipControls
ownershipControls} -> Maybe OwnershipControls
ownershipControls) (\s :: GetBucketOwnershipControlsResponse
s@GetBucketOwnershipControlsResponse' {} Maybe OwnershipControls
a -> GetBucketOwnershipControlsResponse
s {$sel:ownershipControls:GetBucketOwnershipControlsResponse' :: Maybe OwnershipControls
ownershipControls = Maybe OwnershipControls
a} :: GetBucketOwnershipControlsResponse)

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

instance
  Prelude.NFData
    GetBucketOwnershipControlsResponse
  where
  rnf :: GetBucketOwnershipControlsResponse -> ()
rnf GetBucketOwnershipControlsResponse' {Int
Maybe OwnershipControls
httpStatus :: Int
ownershipControls :: Maybe OwnershipControls
$sel:httpStatus:GetBucketOwnershipControlsResponse' :: GetBucketOwnershipControlsResponse -> Int
$sel:ownershipControls:GetBucketOwnershipControlsResponse' :: GetBucketOwnershipControlsResponse -> Maybe OwnershipControls
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe OwnershipControls
ownershipControls
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus