{-# 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.GetBucketCors
-- 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 cors configuration information set for the bucket.
--
-- To use this operation, you must have permission to perform the
-- s3:GetBucketCORS action. By default, the bucket owner has this
-- permission and can grant it to others.
--
-- For more information about cors, see
-- <https://docs.aws.amazon.com/AmazonS3/latest/dev/cors.html Enabling Cross-Origin Resource Sharing>.
--
-- The following operations are related to @GetBucketCors@:
--
-- -   <https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutBucketCors.html PutBucketCors>
--
-- -   <https://docs.aws.amazon.com/AmazonS3/latest/API/API_DeleteBucketCors.html DeleteBucketCors>
module Amazonka.S3.GetBucketCors
  ( -- * Creating a Request
    GetBucketCors (..),
    newGetBucketCors,

    -- * Request Lenses
    getBucketCors_expectedBucketOwner,
    getBucketCors_bucket,

    -- * Destructuring the Response
    GetBucketCorsResponse (..),
    newGetBucketCorsResponse,

    -- * Response Lenses
    getBucketCorsResponse_cORSRules,
    getBucketCorsResponse_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.S3.Types

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

-- |
-- Create a value of 'GetBucketCors' 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', 'getBucketCors_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', 'getBucketCors_bucket' - The bucket name for which to get the cors configuration.
newGetBucketCors ::
  -- | 'bucket'
  BucketName ->
  GetBucketCors
newGetBucketCors :: BucketName -> GetBucketCors
newGetBucketCors BucketName
pBucket_ =
  GetBucketCors' :: Maybe Text -> BucketName -> GetBucketCors
GetBucketCors'
    { $sel:expectedBucketOwner:GetBucketCors' :: Maybe Text
expectedBucketOwner =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:bucket:GetBucketCors' :: 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.
getBucketCors_expectedBucketOwner :: Lens.Lens' GetBucketCors (Prelude.Maybe Prelude.Text)
getBucketCors_expectedBucketOwner :: (Maybe Text -> f (Maybe Text)) -> GetBucketCors -> f GetBucketCors
getBucketCors_expectedBucketOwner = (GetBucketCors -> Maybe Text)
-> (GetBucketCors -> Maybe Text -> GetBucketCors)
-> Lens GetBucketCors GetBucketCors (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetBucketCors' {Maybe Text
expectedBucketOwner :: Maybe Text
$sel:expectedBucketOwner:GetBucketCors' :: GetBucketCors -> Maybe Text
expectedBucketOwner} -> Maybe Text
expectedBucketOwner) (\s :: GetBucketCors
s@GetBucketCors' {} Maybe Text
a -> GetBucketCors
s {$sel:expectedBucketOwner:GetBucketCors' :: Maybe Text
expectedBucketOwner = Maybe Text
a} :: GetBucketCors)

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

instance Core.AWSRequest GetBucketCors where
  type
    AWSResponse GetBucketCors =
      GetBucketCorsResponse
  request :: GetBucketCors -> Request GetBucketCors
request =
    Request GetBucketCors -> Request GetBucketCors
forall a. Request a -> Request a
Request.s3vhost
      (Request GetBucketCors -> Request GetBucketCors)
-> (GetBucketCors -> Request GetBucketCors)
-> GetBucketCors
-> Request GetBucketCors
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. Service -> GetBucketCors -> Request GetBucketCors
forall a. ToRequest a => Service -> a -> Request a
Request.get Service
defaultService
  response :: Logger
-> Service
-> Proxy GetBucketCors
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetBucketCors)))
response =
    (Int
 -> ResponseHeaders
 -> [Node]
 -> Either String (AWSResponse GetBucketCors))
-> Logger
-> Service
-> Proxy GetBucketCors
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetBucketCors)))
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 ->
          Maybe [CORSRule] -> Int -> GetBucketCorsResponse
GetBucketCorsResponse'
            (Maybe [CORSRule] -> Int -> GetBucketCorsResponse)
-> Either String (Maybe [CORSRule])
-> Either String (Int -> GetBucketCorsResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (([Node] -> Either String [CORSRule])
-> [Node] -> Either String (Maybe [CORSRule])
forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (Text -> [Node] -> Either String [CORSRule]
forall a. FromXML a => Text -> [Node] -> Either String [a]
Core.parseXMLList Text
"CORSRule") [Node]
x)
            Either String (Int -> GetBucketCorsResponse)
-> Either String Int -> Either String GetBucketCorsResponse
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 GetBucketCors

instance Prelude.NFData GetBucketCors

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

-- | /See:/ 'newGetBucketCorsResponse' smart constructor.
data GetBucketCorsResponse = GetBucketCorsResponse'
  { -- | A set of origins and methods (cross-origin access that you want to
    -- allow). You can add up to 100 rules to the configuration.
    GetBucketCorsResponse -> Maybe [CORSRule]
cORSRules :: Prelude.Maybe [CORSRule],
    -- | The response's http status code.
    GetBucketCorsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetBucketCorsResponse -> GetBucketCorsResponse -> Bool
(GetBucketCorsResponse -> GetBucketCorsResponse -> Bool)
-> (GetBucketCorsResponse -> GetBucketCorsResponse -> Bool)
-> Eq GetBucketCorsResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetBucketCorsResponse -> GetBucketCorsResponse -> Bool
$c/= :: GetBucketCorsResponse -> GetBucketCorsResponse -> Bool
== :: GetBucketCorsResponse -> GetBucketCorsResponse -> Bool
$c== :: GetBucketCorsResponse -> GetBucketCorsResponse -> Bool
Prelude.Eq, ReadPrec [GetBucketCorsResponse]
ReadPrec GetBucketCorsResponse
Int -> ReadS GetBucketCorsResponse
ReadS [GetBucketCorsResponse]
(Int -> ReadS GetBucketCorsResponse)
-> ReadS [GetBucketCorsResponse]
-> ReadPrec GetBucketCorsResponse
-> ReadPrec [GetBucketCorsResponse]
-> Read GetBucketCorsResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetBucketCorsResponse]
$creadListPrec :: ReadPrec [GetBucketCorsResponse]
readPrec :: ReadPrec GetBucketCorsResponse
$creadPrec :: ReadPrec GetBucketCorsResponse
readList :: ReadS [GetBucketCorsResponse]
$creadList :: ReadS [GetBucketCorsResponse]
readsPrec :: Int -> ReadS GetBucketCorsResponse
$creadsPrec :: Int -> ReadS GetBucketCorsResponse
Prelude.Read, Int -> GetBucketCorsResponse -> ShowS
[GetBucketCorsResponse] -> ShowS
GetBucketCorsResponse -> String
(Int -> GetBucketCorsResponse -> ShowS)
-> (GetBucketCorsResponse -> String)
-> ([GetBucketCorsResponse] -> ShowS)
-> Show GetBucketCorsResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetBucketCorsResponse] -> ShowS
$cshowList :: [GetBucketCorsResponse] -> ShowS
show :: GetBucketCorsResponse -> String
$cshow :: GetBucketCorsResponse -> String
showsPrec :: Int -> GetBucketCorsResponse -> ShowS
$cshowsPrec :: Int -> GetBucketCorsResponse -> ShowS
Prelude.Show, (forall x. GetBucketCorsResponse -> Rep GetBucketCorsResponse x)
-> (forall x. Rep GetBucketCorsResponse x -> GetBucketCorsResponse)
-> Generic GetBucketCorsResponse
forall x. Rep GetBucketCorsResponse x -> GetBucketCorsResponse
forall x. GetBucketCorsResponse -> Rep GetBucketCorsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetBucketCorsResponse x -> GetBucketCorsResponse
$cfrom :: forall x. GetBucketCorsResponse -> Rep GetBucketCorsResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetBucketCorsResponse' 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:
--
-- 'cORSRules', 'getBucketCorsResponse_cORSRules' - A set of origins and methods (cross-origin access that you want to
-- allow). You can add up to 100 rules to the configuration.
--
-- 'httpStatus', 'getBucketCorsResponse_httpStatus' - The response's http status code.
newGetBucketCorsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetBucketCorsResponse
newGetBucketCorsResponse :: Int -> GetBucketCorsResponse
newGetBucketCorsResponse Int
pHttpStatus_ =
  GetBucketCorsResponse' :: Maybe [CORSRule] -> Int -> GetBucketCorsResponse
GetBucketCorsResponse'
    { $sel:cORSRules:GetBucketCorsResponse' :: Maybe [CORSRule]
cORSRules = Maybe [CORSRule]
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetBucketCorsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A set of origins and methods (cross-origin access that you want to
-- allow). You can add up to 100 rules to the configuration.
getBucketCorsResponse_cORSRules :: Lens.Lens' GetBucketCorsResponse (Prelude.Maybe [CORSRule])
getBucketCorsResponse_cORSRules :: (Maybe [CORSRule] -> f (Maybe [CORSRule]))
-> GetBucketCorsResponse -> f GetBucketCorsResponse
getBucketCorsResponse_cORSRules = (GetBucketCorsResponse -> Maybe [CORSRule])
-> (GetBucketCorsResponse
    -> Maybe [CORSRule] -> GetBucketCorsResponse)
-> Lens
     GetBucketCorsResponse
     GetBucketCorsResponse
     (Maybe [CORSRule])
     (Maybe [CORSRule])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetBucketCorsResponse' {Maybe [CORSRule]
cORSRules :: Maybe [CORSRule]
$sel:cORSRules:GetBucketCorsResponse' :: GetBucketCorsResponse -> Maybe [CORSRule]
cORSRules} -> Maybe [CORSRule]
cORSRules) (\s :: GetBucketCorsResponse
s@GetBucketCorsResponse' {} Maybe [CORSRule]
a -> GetBucketCorsResponse
s {$sel:cORSRules:GetBucketCorsResponse' :: Maybe [CORSRule]
cORSRules = Maybe [CORSRule]
a} :: GetBucketCorsResponse) ((Maybe [CORSRule] -> f (Maybe [CORSRule]))
 -> GetBucketCorsResponse -> f GetBucketCorsResponse)
-> ((Maybe [CORSRule] -> f (Maybe [CORSRule]))
    -> Maybe [CORSRule] -> f (Maybe [CORSRule]))
-> (Maybe [CORSRule] -> f (Maybe [CORSRule]))
-> GetBucketCorsResponse
-> f GetBucketCorsResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [CORSRule] [CORSRule] [CORSRule] [CORSRule]
-> Iso
     (Maybe [CORSRule])
     (Maybe [CORSRule])
     (Maybe [CORSRule])
     (Maybe [CORSRule])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso [CORSRule] [CORSRule] [CORSRule] [CORSRule]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.NFData GetBucketCorsResponse