{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# 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.Types.CORSConfiguration
-- 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)
module Amazonka.S3.Types.CORSConfiguration where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.S3.Internal
import Amazonka.S3.Types.CORSRule

-- | Describes the cross-origin access configuration for objects in an Amazon
-- S3 bucket. For more information, see
-- <https://docs.aws.amazon.com/AmazonS3/latest/dev/cors.html Enabling Cross-Origin Resource Sharing>
-- in the /Amazon S3 User Guide/.
--
-- /See:/ 'newCORSConfiguration' smart constructor.
data CORSConfiguration = CORSConfiguration'
  { -- | A set of origins and methods (cross-origin access that you want to
    -- allow). You can add up to 100 rules to the configuration.
    CORSConfiguration -> [CORSRule]
cORSRules :: [CORSRule]
  }
  deriving (CORSConfiguration -> CORSConfiguration -> Bool
(CORSConfiguration -> CORSConfiguration -> Bool)
-> (CORSConfiguration -> CORSConfiguration -> Bool)
-> Eq CORSConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CORSConfiguration -> CORSConfiguration -> Bool
$c/= :: CORSConfiguration -> CORSConfiguration -> Bool
== :: CORSConfiguration -> CORSConfiguration -> Bool
$c== :: CORSConfiguration -> CORSConfiguration -> Bool
Prelude.Eq, ReadPrec [CORSConfiguration]
ReadPrec CORSConfiguration
Int -> ReadS CORSConfiguration
ReadS [CORSConfiguration]
(Int -> ReadS CORSConfiguration)
-> ReadS [CORSConfiguration]
-> ReadPrec CORSConfiguration
-> ReadPrec [CORSConfiguration]
-> Read CORSConfiguration
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CORSConfiguration]
$creadListPrec :: ReadPrec [CORSConfiguration]
readPrec :: ReadPrec CORSConfiguration
$creadPrec :: ReadPrec CORSConfiguration
readList :: ReadS [CORSConfiguration]
$creadList :: ReadS [CORSConfiguration]
readsPrec :: Int -> ReadS CORSConfiguration
$creadsPrec :: Int -> ReadS CORSConfiguration
Prelude.Read, Int -> CORSConfiguration -> ShowS
[CORSConfiguration] -> ShowS
CORSConfiguration -> String
(Int -> CORSConfiguration -> ShowS)
-> (CORSConfiguration -> String)
-> ([CORSConfiguration] -> ShowS)
-> Show CORSConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CORSConfiguration] -> ShowS
$cshowList :: [CORSConfiguration] -> ShowS
show :: CORSConfiguration -> String
$cshow :: CORSConfiguration -> String
showsPrec :: Int -> CORSConfiguration -> ShowS
$cshowsPrec :: Int -> CORSConfiguration -> ShowS
Prelude.Show, (forall x. CORSConfiguration -> Rep CORSConfiguration x)
-> (forall x. Rep CORSConfiguration x -> CORSConfiguration)
-> Generic CORSConfiguration
forall x. Rep CORSConfiguration x -> CORSConfiguration
forall x. CORSConfiguration -> Rep CORSConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CORSConfiguration x -> CORSConfiguration
$cfrom :: forall x. CORSConfiguration -> Rep CORSConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'CORSConfiguration' 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', 'cORSConfiguration_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.
newCORSConfiguration ::
  CORSConfiguration
newCORSConfiguration :: CORSConfiguration
newCORSConfiguration =
  CORSConfiguration' :: [CORSRule] -> CORSConfiguration
CORSConfiguration' {$sel:cORSRules:CORSConfiguration' :: [CORSRule]
cORSRules = [CORSRule]
forall a. Monoid a => a
Prelude.mempty}

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

instance Prelude.Hashable CORSConfiguration

instance Prelude.NFData CORSConfiguration

instance Core.ToXML CORSConfiguration where
  toXML :: CORSConfiguration -> XML
toXML CORSConfiguration' {[CORSRule]
cORSRules :: [CORSRule]
$sel:cORSRules:CORSConfiguration' :: CORSConfiguration -> [CORSRule]
..} =
    [XML] -> XML
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [Name -> [CORSRule] -> XML
forall a. (IsList a, ToXML (Item a)) => Name -> a -> XML
Core.toXMLList Name
"CORSRule" [CORSRule]
cORSRules]