{-# 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.GuardDuty.Types.BucketPolicy
-- 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.GuardDuty.Types.BucketPolicy where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Contains information on the current bucket policies for the S3 bucket.
--
-- /See:/ 'newBucketPolicy' smart constructor.
data BucketPolicy = BucketPolicy'
  { -- | A value that indicates whether public write access for the bucket is
    -- enabled through a bucket policy.
    BucketPolicy -> Maybe Bool
allowsPublicWriteAccess :: Prelude.Maybe Prelude.Bool,
    -- | A value that indicates whether public read access for the bucket is
    -- enabled through a bucket policy.
    BucketPolicy -> Maybe Bool
allowsPublicReadAccess :: Prelude.Maybe Prelude.Bool
  }
  deriving (BucketPolicy -> BucketPolicy -> Bool
(BucketPolicy -> BucketPolicy -> Bool)
-> (BucketPolicy -> BucketPolicy -> Bool) -> Eq BucketPolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BucketPolicy -> BucketPolicy -> Bool
$c/= :: BucketPolicy -> BucketPolicy -> Bool
== :: BucketPolicy -> BucketPolicy -> Bool
$c== :: BucketPolicy -> BucketPolicy -> Bool
Prelude.Eq, ReadPrec [BucketPolicy]
ReadPrec BucketPolicy
Int -> ReadS BucketPolicy
ReadS [BucketPolicy]
(Int -> ReadS BucketPolicy)
-> ReadS [BucketPolicy]
-> ReadPrec BucketPolicy
-> ReadPrec [BucketPolicy]
-> Read BucketPolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BucketPolicy]
$creadListPrec :: ReadPrec [BucketPolicy]
readPrec :: ReadPrec BucketPolicy
$creadPrec :: ReadPrec BucketPolicy
readList :: ReadS [BucketPolicy]
$creadList :: ReadS [BucketPolicy]
readsPrec :: Int -> ReadS BucketPolicy
$creadsPrec :: Int -> ReadS BucketPolicy
Prelude.Read, Int -> BucketPolicy -> ShowS
[BucketPolicy] -> ShowS
BucketPolicy -> String
(Int -> BucketPolicy -> ShowS)
-> (BucketPolicy -> String)
-> ([BucketPolicy] -> ShowS)
-> Show BucketPolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BucketPolicy] -> ShowS
$cshowList :: [BucketPolicy] -> ShowS
show :: BucketPolicy -> String
$cshow :: BucketPolicy -> String
showsPrec :: Int -> BucketPolicy -> ShowS
$cshowsPrec :: Int -> BucketPolicy -> ShowS
Prelude.Show, (forall x. BucketPolicy -> Rep BucketPolicy x)
-> (forall x. Rep BucketPolicy x -> BucketPolicy)
-> Generic BucketPolicy
forall x. Rep BucketPolicy x -> BucketPolicy
forall x. BucketPolicy -> Rep BucketPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BucketPolicy x -> BucketPolicy
$cfrom :: forall x. BucketPolicy -> Rep BucketPolicy x
Prelude.Generic)

-- |
-- Create a value of 'BucketPolicy' 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:
--
-- 'allowsPublicWriteAccess', 'bucketPolicy_allowsPublicWriteAccess' - A value that indicates whether public write access for the bucket is
-- enabled through a bucket policy.
--
-- 'allowsPublicReadAccess', 'bucketPolicy_allowsPublicReadAccess' - A value that indicates whether public read access for the bucket is
-- enabled through a bucket policy.
newBucketPolicy ::
  BucketPolicy
newBucketPolicy :: BucketPolicy
newBucketPolicy =
  BucketPolicy' :: Maybe Bool -> Maybe Bool -> BucketPolicy
BucketPolicy'
    { $sel:allowsPublicWriteAccess:BucketPolicy' :: Maybe Bool
allowsPublicWriteAccess =
        Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:allowsPublicReadAccess:BucketPolicy' :: Maybe Bool
allowsPublicReadAccess = Maybe Bool
forall a. Maybe a
Prelude.Nothing
    }

-- | A value that indicates whether public write access for the bucket is
-- enabled through a bucket policy.
bucketPolicy_allowsPublicWriteAccess :: Lens.Lens' BucketPolicy (Prelude.Maybe Prelude.Bool)
bucketPolicy_allowsPublicWriteAccess :: (Maybe Bool -> f (Maybe Bool)) -> BucketPolicy -> f BucketPolicy
bucketPolicy_allowsPublicWriteAccess = (BucketPolicy -> Maybe Bool)
-> (BucketPolicy -> Maybe Bool -> BucketPolicy)
-> Lens BucketPolicy BucketPolicy (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BucketPolicy' {Maybe Bool
allowsPublicWriteAccess :: Maybe Bool
$sel:allowsPublicWriteAccess:BucketPolicy' :: BucketPolicy -> Maybe Bool
allowsPublicWriteAccess} -> Maybe Bool
allowsPublicWriteAccess) (\s :: BucketPolicy
s@BucketPolicy' {} Maybe Bool
a -> BucketPolicy
s {$sel:allowsPublicWriteAccess:BucketPolicy' :: Maybe Bool
allowsPublicWriteAccess = Maybe Bool
a} :: BucketPolicy)

-- | A value that indicates whether public read access for the bucket is
-- enabled through a bucket policy.
bucketPolicy_allowsPublicReadAccess :: Lens.Lens' BucketPolicy (Prelude.Maybe Prelude.Bool)
bucketPolicy_allowsPublicReadAccess :: (Maybe Bool -> f (Maybe Bool)) -> BucketPolicy -> f BucketPolicy
bucketPolicy_allowsPublicReadAccess = (BucketPolicy -> Maybe Bool)
-> (BucketPolicy -> Maybe Bool -> BucketPolicy)
-> Lens BucketPolicy BucketPolicy (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BucketPolicy' {Maybe Bool
allowsPublicReadAccess :: Maybe Bool
$sel:allowsPublicReadAccess:BucketPolicy' :: BucketPolicy -> Maybe Bool
allowsPublicReadAccess} -> Maybe Bool
allowsPublicReadAccess) (\s :: BucketPolicy
s@BucketPolicy' {} Maybe Bool
a -> BucketPolicy
s {$sel:allowsPublicReadAccess:BucketPolicy' :: Maybe Bool
allowsPublicReadAccess = Maybe Bool
a} :: BucketPolicy)

instance Core.FromJSON BucketPolicy where
  parseJSON :: Value -> Parser BucketPolicy
parseJSON =
    String
-> (Object -> Parser BucketPolicy) -> Value -> Parser BucketPolicy
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"BucketPolicy"
      ( \Object
x ->
          Maybe Bool -> Maybe Bool -> BucketPolicy
BucketPolicy'
            (Maybe Bool -> Maybe Bool -> BucketPolicy)
-> Parser (Maybe Bool) -> Parser (Maybe Bool -> BucketPolicy)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"allowsPublicWriteAccess")
            Parser (Maybe Bool -> BucketPolicy)
-> Parser (Maybe Bool) -> Parser BucketPolicy
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"allowsPublicReadAccess")
      )

instance Prelude.Hashable BucketPolicy

instance Prelude.NFData BucketPolicy