{-# 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.GetBucketLocation
-- 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)
--
-- Returns the Region the bucket resides in. You set the bucket\'s Region
-- using the @LocationConstraint@ request parameter in a @CreateBucket@
-- request. For more information, see
-- <https://docs.aws.amazon.com/AmazonS3/latest/API/API_CreateBucket.html CreateBucket>.
--
-- To use this implementation of the operation, you must be the bucket
-- owner.
--
-- To use this API against an access point, provide the alias of the access
-- point in place of the bucket name.
--
-- The following operations are related to @GetBucketLocation@:
--
-- -   <https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObject.html GetObject>
--
-- -   <https://docs.aws.amazon.com/AmazonS3/latest/API/API_CreateBucket.html CreateBucket>
module Amazonka.S3.GetBucketLocation
  ( -- * Creating a Request
    GetBucketLocation (..),
    newGetBucketLocation,

    -- * Request Lenses
    getBucketLocation_expectedBucketOwner,
    getBucketLocation_bucket,

    -- * Destructuring the Response
    GetBucketLocationResponse (..),
    newGetBucketLocationResponse,

    -- * Response Lenses
    getBucketLocationResponse_httpStatus,
    getBucketLocationResponse_locationConstraint,
  )
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:/ 'newGetBucketLocation' smart constructor.
data GetBucketLocation = GetBucketLocation'
  { -- | 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.
    GetBucketLocation -> Maybe Text
expectedBucketOwner :: Prelude.Maybe Prelude.Text,
    -- | The name of the bucket for which to get the location.
    GetBucketLocation -> BucketName
bucket :: BucketName
  }
  deriving (GetBucketLocation -> GetBucketLocation -> Bool
(GetBucketLocation -> GetBucketLocation -> Bool)
-> (GetBucketLocation -> GetBucketLocation -> Bool)
-> Eq GetBucketLocation
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetBucketLocation -> GetBucketLocation -> Bool
$c/= :: GetBucketLocation -> GetBucketLocation -> Bool
== :: GetBucketLocation -> GetBucketLocation -> Bool
$c== :: GetBucketLocation -> GetBucketLocation -> Bool
Prelude.Eq, ReadPrec [GetBucketLocation]
ReadPrec GetBucketLocation
Int -> ReadS GetBucketLocation
ReadS [GetBucketLocation]
(Int -> ReadS GetBucketLocation)
-> ReadS [GetBucketLocation]
-> ReadPrec GetBucketLocation
-> ReadPrec [GetBucketLocation]
-> Read GetBucketLocation
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetBucketLocation]
$creadListPrec :: ReadPrec [GetBucketLocation]
readPrec :: ReadPrec GetBucketLocation
$creadPrec :: ReadPrec GetBucketLocation
readList :: ReadS [GetBucketLocation]
$creadList :: ReadS [GetBucketLocation]
readsPrec :: Int -> ReadS GetBucketLocation
$creadsPrec :: Int -> ReadS GetBucketLocation
Prelude.Read, Int -> GetBucketLocation -> ShowS
[GetBucketLocation] -> ShowS
GetBucketLocation -> String
(Int -> GetBucketLocation -> ShowS)
-> (GetBucketLocation -> String)
-> ([GetBucketLocation] -> ShowS)
-> Show GetBucketLocation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetBucketLocation] -> ShowS
$cshowList :: [GetBucketLocation] -> ShowS
show :: GetBucketLocation -> String
$cshow :: GetBucketLocation -> String
showsPrec :: Int -> GetBucketLocation -> ShowS
$cshowsPrec :: Int -> GetBucketLocation -> ShowS
Prelude.Show, (forall x. GetBucketLocation -> Rep GetBucketLocation x)
-> (forall x. Rep GetBucketLocation x -> GetBucketLocation)
-> Generic GetBucketLocation
forall x. Rep GetBucketLocation x -> GetBucketLocation
forall x. GetBucketLocation -> Rep GetBucketLocation x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetBucketLocation x -> GetBucketLocation
$cfrom :: forall x. GetBucketLocation -> Rep GetBucketLocation x
Prelude.Generic)

-- |
-- Create a value of 'GetBucketLocation' 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', 'getBucketLocation_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', 'getBucketLocation_bucket' - The name of the bucket for which to get the location.
newGetBucketLocation ::
  -- | 'bucket'
  BucketName ->
  GetBucketLocation
newGetBucketLocation :: BucketName -> GetBucketLocation
newGetBucketLocation BucketName
pBucket_ =
  GetBucketLocation' :: Maybe Text -> BucketName -> GetBucketLocation
GetBucketLocation'
    { $sel:expectedBucketOwner:GetBucketLocation' :: Maybe Text
expectedBucketOwner =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:bucket:GetBucketLocation' :: 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.
getBucketLocation_expectedBucketOwner :: Lens.Lens' GetBucketLocation (Prelude.Maybe Prelude.Text)
getBucketLocation_expectedBucketOwner :: (Maybe Text -> f (Maybe Text))
-> GetBucketLocation -> f GetBucketLocation
getBucketLocation_expectedBucketOwner = (GetBucketLocation -> Maybe Text)
-> (GetBucketLocation -> Maybe Text -> GetBucketLocation)
-> Lens
     GetBucketLocation GetBucketLocation (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetBucketLocation' {Maybe Text
expectedBucketOwner :: Maybe Text
$sel:expectedBucketOwner:GetBucketLocation' :: GetBucketLocation -> Maybe Text
expectedBucketOwner} -> Maybe Text
expectedBucketOwner) (\s :: GetBucketLocation
s@GetBucketLocation' {} Maybe Text
a -> GetBucketLocation
s {$sel:expectedBucketOwner:GetBucketLocation' :: Maybe Text
expectedBucketOwner = Maybe Text
a} :: GetBucketLocation)

-- | The name of the bucket for which to get the location.
getBucketLocation_bucket :: Lens.Lens' GetBucketLocation BucketName
getBucketLocation_bucket :: (BucketName -> f BucketName)
-> GetBucketLocation -> f GetBucketLocation
getBucketLocation_bucket = (GetBucketLocation -> BucketName)
-> (GetBucketLocation -> BucketName -> GetBucketLocation)
-> Lens GetBucketLocation GetBucketLocation BucketName BucketName
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetBucketLocation' {BucketName
bucket :: BucketName
$sel:bucket:GetBucketLocation' :: GetBucketLocation -> BucketName
bucket} -> BucketName
bucket) (\s :: GetBucketLocation
s@GetBucketLocation' {} BucketName
a -> GetBucketLocation
s {$sel:bucket:GetBucketLocation' :: BucketName
bucket = BucketName
a} :: GetBucketLocation)

instance Core.AWSRequest GetBucketLocation where
  type
    AWSResponse GetBucketLocation =
      GetBucketLocationResponse
  request :: GetBucketLocation -> Request GetBucketLocation
request = Service -> GetBucketLocation -> Request GetBucketLocation
forall a. ToRequest a => Service -> a -> Request a
Request.get Service
defaultService
  response :: Logger
-> Service
-> Proxy GetBucketLocation
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetBucketLocation)))
response =
    (Int
 -> ResponseHeaders
 -> [Node]
 -> Either String (AWSResponse GetBucketLocation))
-> Logger
-> Service
-> Proxy GetBucketLocation
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetBucketLocation)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> [Node] -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveXML
      ( \Int
s ResponseHeaders
h [Node]
x ->
          Int -> LocationConstraint -> GetBucketLocationResponse
GetBucketLocationResponse'
            (Int -> LocationConstraint -> GetBucketLocationResponse)
-> Either String Int
-> Either String (LocationConstraint -> GetBucketLocationResponse)
forall (f :: * -> *) a b. Functor 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))
            Either String (LocationConstraint -> GetBucketLocationResponse)
-> Either String LocationConstraint
-> Either String GetBucketLocationResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node] -> Either String LocationConstraint
forall a. FromXML a => [Node] -> Either String a
Core.parseXML [Node]
x)
      )

instance Prelude.Hashable GetBucketLocation

instance Prelude.NFData GetBucketLocation

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

instance Core.ToPath GetBucketLocation where
  toPath :: GetBucketLocation -> ByteString
toPath GetBucketLocation' {Maybe Text
BucketName
bucket :: BucketName
expectedBucketOwner :: Maybe Text
$sel:bucket:GetBucketLocation' :: GetBucketLocation -> BucketName
$sel:expectedBucketOwner:GetBucketLocation' :: GetBucketLocation -> 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 GetBucketLocation where
  toQuery :: GetBucketLocation -> QueryString
toQuery =
    QueryString -> GetBucketLocation -> QueryString
forall a b. a -> b -> a
Prelude.const ([QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat [QueryString
"location"])

-- | /See:/ 'newGetBucketLocationResponse' smart constructor.
data GetBucketLocationResponse = GetBucketLocationResponse'
  { -- | The response's http status code.
    GetBucketLocationResponse -> Int
httpStatus :: Prelude.Int,
    -- | Specifies the Region where the bucket resides. For a list of all the
    -- Amazon S3 supported location constraints by Region, see
    -- <https://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region Regions and Endpoints>.
    -- Buckets in Region @us-east-1@ have a LocationConstraint of @null@.
    GetBucketLocationResponse -> LocationConstraint
locationConstraint :: LocationConstraint
  }
  deriving (GetBucketLocationResponse -> GetBucketLocationResponse -> Bool
(GetBucketLocationResponse -> GetBucketLocationResponse -> Bool)
-> (GetBucketLocationResponse -> GetBucketLocationResponse -> Bool)
-> Eq GetBucketLocationResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetBucketLocationResponse -> GetBucketLocationResponse -> Bool
$c/= :: GetBucketLocationResponse -> GetBucketLocationResponse -> Bool
== :: GetBucketLocationResponse -> GetBucketLocationResponse -> Bool
$c== :: GetBucketLocationResponse -> GetBucketLocationResponse -> Bool
Prelude.Eq, ReadPrec [GetBucketLocationResponse]
ReadPrec GetBucketLocationResponse
Int -> ReadS GetBucketLocationResponse
ReadS [GetBucketLocationResponse]
(Int -> ReadS GetBucketLocationResponse)
-> ReadS [GetBucketLocationResponse]
-> ReadPrec GetBucketLocationResponse
-> ReadPrec [GetBucketLocationResponse]
-> Read GetBucketLocationResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetBucketLocationResponse]
$creadListPrec :: ReadPrec [GetBucketLocationResponse]
readPrec :: ReadPrec GetBucketLocationResponse
$creadPrec :: ReadPrec GetBucketLocationResponse
readList :: ReadS [GetBucketLocationResponse]
$creadList :: ReadS [GetBucketLocationResponse]
readsPrec :: Int -> ReadS GetBucketLocationResponse
$creadsPrec :: Int -> ReadS GetBucketLocationResponse
Prelude.Read, Int -> GetBucketLocationResponse -> ShowS
[GetBucketLocationResponse] -> ShowS
GetBucketLocationResponse -> String
(Int -> GetBucketLocationResponse -> ShowS)
-> (GetBucketLocationResponse -> String)
-> ([GetBucketLocationResponse] -> ShowS)
-> Show GetBucketLocationResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetBucketLocationResponse] -> ShowS
$cshowList :: [GetBucketLocationResponse] -> ShowS
show :: GetBucketLocationResponse -> String
$cshow :: GetBucketLocationResponse -> String
showsPrec :: Int -> GetBucketLocationResponse -> ShowS
$cshowsPrec :: Int -> GetBucketLocationResponse -> ShowS
Prelude.Show, (forall x.
 GetBucketLocationResponse -> Rep GetBucketLocationResponse x)
-> (forall x.
    Rep GetBucketLocationResponse x -> GetBucketLocationResponse)
-> Generic GetBucketLocationResponse
forall x.
Rep GetBucketLocationResponse x -> GetBucketLocationResponse
forall x.
GetBucketLocationResponse -> Rep GetBucketLocationResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetBucketLocationResponse x -> GetBucketLocationResponse
$cfrom :: forall x.
GetBucketLocationResponse -> Rep GetBucketLocationResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetBucketLocationResponse' 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:
--
-- 'httpStatus', 'getBucketLocationResponse_httpStatus' - The response's http status code.
--
-- 'locationConstraint', 'getBucketLocationResponse_locationConstraint' - Specifies the Region where the bucket resides. For a list of all the
-- Amazon S3 supported location constraints by Region, see
-- <https://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region Regions and Endpoints>.
-- Buckets in Region @us-east-1@ have a LocationConstraint of @null@.
newGetBucketLocationResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'locationConstraint'
  LocationConstraint ->
  GetBucketLocationResponse
newGetBucketLocationResponse :: Int -> LocationConstraint -> GetBucketLocationResponse
newGetBucketLocationResponse
  Int
pHttpStatus_
  LocationConstraint
pLocationConstraint_ =
    GetBucketLocationResponse' :: Int -> LocationConstraint -> GetBucketLocationResponse
GetBucketLocationResponse'
      { $sel:httpStatus:GetBucketLocationResponse' :: Int
httpStatus =
          Int
pHttpStatus_,
        $sel:locationConstraint:GetBucketLocationResponse' :: LocationConstraint
locationConstraint = LocationConstraint
pLocationConstraint_
      }

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

-- | Specifies the Region where the bucket resides. For a list of all the
-- Amazon S3 supported location constraints by Region, see
-- <https://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region Regions and Endpoints>.
-- Buckets in Region @us-east-1@ have a LocationConstraint of @null@.
getBucketLocationResponse_locationConstraint :: Lens.Lens' GetBucketLocationResponse LocationConstraint
getBucketLocationResponse_locationConstraint :: (LocationConstraint -> f LocationConstraint)
-> GetBucketLocationResponse -> f GetBucketLocationResponse
getBucketLocationResponse_locationConstraint = (GetBucketLocationResponse -> LocationConstraint)
-> (GetBucketLocationResponse
    -> LocationConstraint -> GetBucketLocationResponse)
-> Lens
     GetBucketLocationResponse
     GetBucketLocationResponse
     LocationConstraint
     LocationConstraint
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetBucketLocationResponse' {LocationConstraint
locationConstraint :: LocationConstraint
$sel:locationConstraint:GetBucketLocationResponse' :: GetBucketLocationResponse -> LocationConstraint
locationConstraint} -> LocationConstraint
locationConstraint) (\s :: GetBucketLocationResponse
s@GetBucketLocationResponse' {} LocationConstraint
a -> GetBucketLocationResponse
s {$sel:locationConstraint:GetBucketLocationResponse' :: LocationConstraint
locationConstraint = LocationConstraint
a} :: GetBucketLocationResponse)

instance Prelude.NFData GetBucketLocationResponse