{-# 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.AccessAnalyzer.Types.S3BucketConfiguration
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.AccessAnalyzer.Types.S3BucketConfiguration where

import Amazonka.AccessAnalyzer.Types.S3AccessPointConfiguration
import Amazonka.AccessAnalyzer.Types.S3BucketAclGrantConfiguration
import Amazonka.AccessAnalyzer.Types.S3PublicAccessBlockConfiguration
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

-- | Proposed access control configuration for an Amazon S3 bucket. You can
-- propose a configuration for a new Amazon S3 bucket or an existing Amazon
-- S3 bucket that you own by specifying the Amazon S3 bucket policy, bucket
-- ACLs, bucket BPA settings, Amazon S3 access points, and multi-region
-- access points attached to the bucket. If the configuration is for an
-- existing Amazon S3 bucket and you do not specify the Amazon S3 bucket
-- policy, the access preview uses the existing policy attached to the
-- bucket. If the access preview is for a new resource and you do not
-- specify the Amazon S3 bucket policy, the access preview assumes a bucket
-- without a policy. To propose deletion of an existing bucket policy, you
-- can specify an empty string. For more information about bucket policy
-- limits, see
-- <https://docs.aws.amazon.com/AmazonS3/latest/dev/example-bucket-policies.html Bucket Policy Examples>.
--
-- /See:/ 'newS3BucketConfiguration' smart constructor.
data S3BucketConfiguration = S3BucketConfiguration'
  { -- | The configuration of Amazon S3 access points or multi-region access
    -- points for the bucket. You can propose up to 10 new access points per
    -- bucket.
    S3BucketConfiguration
-> Maybe (HashMap Text S3AccessPointConfiguration)
accessPoints :: Prelude.Maybe (Prelude.HashMap Prelude.Text S3AccessPointConfiguration),
    -- | The proposed list of ACL grants for the Amazon S3 bucket. You can
    -- propose up to 100 ACL grants per bucket. If the proposed grant
    -- configuration is for an existing bucket, the access preview uses the
    -- proposed list of grant configurations in place of the existing grants.
    -- Otherwise, the access preview uses the existing grants for the bucket.
    S3BucketConfiguration -> Maybe [S3BucketAclGrantConfiguration]
bucketAclGrants :: Prelude.Maybe [S3BucketAclGrantConfiguration],
    -- | The proposed bucket policy for the Amazon S3 bucket.
    S3BucketConfiguration -> Maybe Text
bucketPolicy :: Prelude.Maybe Prelude.Text,
    -- | The proposed block public access configuration for the Amazon S3 bucket.
    S3BucketConfiguration -> Maybe S3PublicAccessBlockConfiguration
bucketPublicAccessBlock :: Prelude.Maybe S3PublicAccessBlockConfiguration
  }
  deriving (S3BucketConfiguration -> S3BucketConfiguration -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: S3BucketConfiguration -> S3BucketConfiguration -> Bool
$c/= :: S3BucketConfiguration -> S3BucketConfiguration -> Bool
== :: S3BucketConfiguration -> S3BucketConfiguration -> Bool
$c== :: S3BucketConfiguration -> S3BucketConfiguration -> Bool
Prelude.Eq, ReadPrec [S3BucketConfiguration]
ReadPrec S3BucketConfiguration
Int -> ReadS S3BucketConfiguration
ReadS [S3BucketConfiguration]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [S3BucketConfiguration]
$creadListPrec :: ReadPrec [S3BucketConfiguration]
readPrec :: ReadPrec S3BucketConfiguration
$creadPrec :: ReadPrec S3BucketConfiguration
readList :: ReadS [S3BucketConfiguration]
$creadList :: ReadS [S3BucketConfiguration]
readsPrec :: Int -> ReadS S3BucketConfiguration
$creadsPrec :: Int -> ReadS S3BucketConfiguration
Prelude.Read, Int -> S3BucketConfiguration -> ShowS
[S3BucketConfiguration] -> ShowS
S3BucketConfiguration -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [S3BucketConfiguration] -> ShowS
$cshowList :: [S3BucketConfiguration] -> ShowS
show :: S3BucketConfiguration -> String
$cshow :: S3BucketConfiguration -> String
showsPrec :: Int -> S3BucketConfiguration -> ShowS
$cshowsPrec :: Int -> S3BucketConfiguration -> ShowS
Prelude.Show, forall x. Rep S3BucketConfiguration x -> S3BucketConfiguration
forall x. S3BucketConfiguration -> Rep S3BucketConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep S3BucketConfiguration x -> S3BucketConfiguration
$cfrom :: forall x. S3BucketConfiguration -> Rep S3BucketConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'S3BucketConfiguration' 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:
--
-- 'accessPoints', 's3BucketConfiguration_accessPoints' - The configuration of Amazon S3 access points or multi-region access
-- points for the bucket. You can propose up to 10 new access points per
-- bucket.
--
-- 'bucketAclGrants', 's3BucketConfiguration_bucketAclGrants' - The proposed list of ACL grants for the Amazon S3 bucket. You can
-- propose up to 100 ACL grants per bucket. If the proposed grant
-- configuration is for an existing bucket, the access preview uses the
-- proposed list of grant configurations in place of the existing grants.
-- Otherwise, the access preview uses the existing grants for the bucket.
--
-- 'bucketPolicy', 's3BucketConfiguration_bucketPolicy' - The proposed bucket policy for the Amazon S3 bucket.
--
-- 'bucketPublicAccessBlock', 's3BucketConfiguration_bucketPublicAccessBlock' - The proposed block public access configuration for the Amazon S3 bucket.
newS3BucketConfiguration ::
  S3BucketConfiguration
newS3BucketConfiguration :: S3BucketConfiguration
newS3BucketConfiguration =
  S3BucketConfiguration'
    { $sel:accessPoints:S3BucketConfiguration' :: Maybe (HashMap Text S3AccessPointConfiguration)
accessPoints =
        forall a. Maybe a
Prelude.Nothing,
      $sel:bucketAclGrants:S3BucketConfiguration' :: Maybe [S3BucketAclGrantConfiguration]
bucketAclGrants = forall a. Maybe a
Prelude.Nothing,
      $sel:bucketPolicy:S3BucketConfiguration' :: Maybe Text
bucketPolicy = forall a. Maybe a
Prelude.Nothing,
      $sel:bucketPublicAccessBlock:S3BucketConfiguration' :: Maybe S3PublicAccessBlockConfiguration
bucketPublicAccessBlock = forall a. Maybe a
Prelude.Nothing
    }

-- | The configuration of Amazon S3 access points or multi-region access
-- points for the bucket. You can propose up to 10 new access points per
-- bucket.
s3BucketConfiguration_accessPoints :: Lens.Lens' S3BucketConfiguration (Prelude.Maybe (Prelude.HashMap Prelude.Text S3AccessPointConfiguration))
s3BucketConfiguration_accessPoints :: Lens'
  S3BucketConfiguration
  (Maybe (HashMap Text S3AccessPointConfiguration))
s3BucketConfiguration_accessPoints = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\S3BucketConfiguration' {Maybe (HashMap Text S3AccessPointConfiguration)
accessPoints :: Maybe (HashMap Text S3AccessPointConfiguration)
$sel:accessPoints:S3BucketConfiguration' :: S3BucketConfiguration
-> Maybe (HashMap Text S3AccessPointConfiguration)
accessPoints} -> Maybe (HashMap Text S3AccessPointConfiguration)
accessPoints) (\s :: S3BucketConfiguration
s@S3BucketConfiguration' {} Maybe (HashMap Text S3AccessPointConfiguration)
a -> S3BucketConfiguration
s {$sel:accessPoints:S3BucketConfiguration' :: Maybe (HashMap Text S3AccessPointConfiguration)
accessPoints = Maybe (HashMap Text S3AccessPointConfiguration)
a} :: S3BucketConfiguration) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The proposed list of ACL grants for the Amazon S3 bucket. You can
-- propose up to 100 ACL grants per bucket. If the proposed grant
-- configuration is for an existing bucket, the access preview uses the
-- proposed list of grant configurations in place of the existing grants.
-- Otherwise, the access preview uses the existing grants for the bucket.
s3BucketConfiguration_bucketAclGrants :: Lens.Lens' S3BucketConfiguration (Prelude.Maybe [S3BucketAclGrantConfiguration])
s3BucketConfiguration_bucketAclGrants :: Lens' S3BucketConfiguration (Maybe [S3BucketAclGrantConfiguration])
s3BucketConfiguration_bucketAclGrants = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\S3BucketConfiguration' {Maybe [S3BucketAclGrantConfiguration]
bucketAclGrants :: Maybe [S3BucketAclGrantConfiguration]
$sel:bucketAclGrants:S3BucketConfiguration' :: S3BucketConfiguration -> Maybe [S3BucketAclGrantConfiguration]
bucketAclGrants} -> Maybe [S3BucketAclGrantConfiguration]
bucketAclGrants) (\s :: S3BucketConfiguration
s@S3BucketConfiguration' {} Maybe [S3BucketAclGrantConfiguration]
a -> S3BucketConfiguration
s {$sel:bucketAclGrants:S3BucketConfiguration' :: Maybe [S3BucketAclGrantConfiguration]
bucketAclGrants = Maybe [S3BucketAclGrantConfiguration]
a} :: S3BucketConfiguration) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The proposed bucket policy for the Amazon S3 bucket.
s3BucketConfiguration_bucketPolicy :: Lens.Lens' S3BucketConfiguration (Prelude.Maybe Prelude.Text)
s3BucketConfiguration_bucketPolicy :: Lens' S3BucketConfiguration (Maybe Text)
s3BucketConfiguration_bucketPolicy = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\S3BucketConfiguration' {Maybe Text
bucketPolicy :: Maybe Text
$sel:bucketPolicy:S3BucketConfiguration' :: S3BucketConfiguration -> Maybe Text
bucketPolicy} -> Maybe Text
bucketPolicy) (\s :: S3BucketConfiguration
s@S3BucketConfiguration' {} Maybe Text
a -> S3BucketConfiguration
s {$sel:bucketPolicy:S3BucketConfiguration' :: Maybe Text
bucketPolicy = Maybe Text
a} :: S3BucketConfiguration)

-- | The proposed block public access configuration for the Amazon S3 bucket.
s3BucketConfiguration_bucketPublicAccessBlock :: Lens.Lens' S3BucketConfiguration (Prelude.Maybe S3PublicAccessBlockConfiguration)
s3BucketConfiguration_bucketPublicAccessBlock :: Lens'
  S3BucketConfiguration (Maybe S3PublicAccessBlockConfiguration)
s3BucketConfiguration_bucketPublicAccessBlock = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\S3BucketConfiguration' {Maybe S3PublicAccessBlockConfiguration
bucketPublicAccessBlock :: Maybe S3PublicAccessBlockConfiguration
$sel:bucketPublicAccessBlock:S3BucketConfiguration' :: S3BucketConfiguration -> Maybe S3PublicAccessBlockConfiguration
bucketPublicAccessBlock} -> Maybe S3PublicAccessBlockConfiguration
bucketPublicAccessBlock) (\s :: S3BucketConfiguration
s@S3BucketConfiguration' {} Maybe S3PublicAccessBlockConfiguration
a -> S3BucketConfiguration
s {$sel:bucketPublicAccessBlock:S3BucketConfiguration' :: Maybe S3PublicAccessBlockConfiguration
bucketPublicAccessBlock = Maybe S3PublicAccessBlockConfiguration
a} :: S3BucketConfiguration)

instance Data.FromJSON S3BucketConfiguration where
  parseJSON :: Value -> Parser S3BucketConfiguration
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"S3BucketConfiguration"
      ( \Object
x ->
          Maybe (HashMap Text S3AccessPointConfiguration)
-> Maybe [S3BucketAclGrantConfiguration]
-> Maybe Text
-> Maybe S3PublicAccessBlockConfiguration
-> S3BucketConfiguration
S3BucketConfiguration'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"accessPoints" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( Object
x
                            forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"bucketAclGrants"
                            forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty
                        )
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"bucketPolicy")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"bucketPublicAccessBlock")
      )

instance Prelude.Hashable S3BucketConfiguration where
  hashWithSalt :: Int -> S3BucketConfiguration -> Int
hashWithSalt Int
_salt S3BucketConfiguration' {Maybe [S3BucketAclGrantConfiguration]
Maybe Text
Maybe (HashMap Text S3AccessPointConfiguration)
Maybe S3PublicAccessBlockConfiguration
bucketPublicAccessBlock :: Maybe S3PublicAccessBlockConfiguration
bucketPolicy :: Maybe Text
bucketAclGrants :: Maybe [S3BucketAclGrantConfiguration]
accessPoints :: Maybe (HashMap Text S3AccessPointConfiguration)
$sel:bucketPublicAccessBlock:S3BucketConfiguration' :: S3BucketConfiguration -> Maybe S3PublicAccessBlockConfiguration
$sel:bucketPolicy:S3BucketConfiguration' :: S3BucketConfiguration -> Maybe Text
$sel:bucketAclGrants:S3BucketConfiguration' :: S3BucketConfiguration -> Maybe [S3BucketAclGrantConfiguration]
$sel:accessPoints:S3BucketConfiguration' :: S3BucketConfiguration
-> Maybe (HashMap Text S3AccessPointConfiguration)
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text S3AccessPointConfiguration)
accessPoints
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [S3BucketAclGrantConfiguration]
bucketAclGrants
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
bucketPolicy
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe S3PublicAccessBlockConfiguration
bucketPublicAccessBlock

instance Prelude.NFData S3BucketConfiguration where
  rnf :: S3BucketConfiguration -> ()
rnf S3BucketConfiguration' {Maybe [S3BucketAclGrantConfiguration]
Maybe Text
Maybe (HashMap Text S3AccessPointConfiguration)
Maybe S3PublicAccessBlockConfiguration
bucketPublicAccessBlock :: Maybe S3PublicAccessBlockConfiguration
bucketPolicy :: Maybe Text
bucketAclGrants :: Maybe [S3BucketAclGrantConfiguration]
accessPoints :: Maybe (HashMap Text S3AccessPointConfiguration)
$sel:bucketPublicAccessBlock:S3BucketConfiguration' :: S3BucketConfiguration -> Maybe S3PublicAccessBlockConfiguration
$sel:bucketPolicy:S3BucketConfiguration' :: S3BucketConfiguration -> Maybe Text
$sel:bucketAclGrants:S3BucketConfiguration' :: S3BucketConfiguration -> Maybe [S3BucketAclGrantConfiguration]
$sel:accessPoints:S3BucketConfiguration' :: S3BucketConfiguration
-> Maybe (HashMap Text S3AccessPointConfiguration)
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text S3AccessPointConfiguration)
accessPoints
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [S3BucketAclGrantConfiguration]
bucketAclGrants
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
bucketPolicy
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe S3PublicAccessBlockConfiguration
bucketPublicAccessBlock

instance Data.ToJSON S3BucketConfiguration where
  toJSON :: S3BucketConfiguration -> Value
toJSON S3BucketConfiguration' {Maybe [S3BucketAclGrantConfiguration]
Maybe Text
Maybe (HashMap Text S3AccessPointConfiguration)
Maybe S3PublicAccessBlockConfiguration
bucketPublicAccessBlock :: Maybe S3PublicAccessBlockConfiguration
bucketPolicy :: Maybe Text
bucketAclGrants :: Maybe [S3BucketAclGrantConfiguration]
accessPoints :: Maybe (HashMap Text S3AccessPointConfiguration)
$sel:bucketPublicAccessBlock:S3BucketConfiguration' :: S3BucketConfiguration -> Maybe S3PublicAccessBlockConfiguration
$sel:bucketPolicy:S3BucketConfiguration' :: S3BucketConfiguration -> Maybe Text
$sel:bucketAclGrants:S3BucketConfiguration' :: S3BucketConfiguration -> Maybe [S3BucketAclGrantConfiguration]
$sel:accessPoints:S3BucketConfiguration' :: S3BucketConfiguration
-> Maybe (HashMap Text S3AccessPointConfiguration)
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"accessPoints" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text S3AccessPointConfiguration)
accessPoints,
            (Key
"bucketAclGrants" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [S3BucketAclGrantConfiguration]
bucketAclGrants,
            (Key
"bucketPolicy" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
bucketPolicy,
            (Key
"bucketPublicAccessBlock" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe S3PublicAccessBlockConfiguration
bucketPublicAccessBlock
          ]
      )