{-# 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.Lightsail.Types.AccessRules
-- 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.Lightsail.Types.AccessRules where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.Lightsail.Types.AccessType
import qualified Amazonka.Prelude as Prelude

-- | Describes the anonymous access permissions for an Amazon Lightsail
-- bucket and its objects.
--
-- For more information about bucket access permissions, see
-- <https://lightsail.aws.amazon.com/ls/docs/en_us/articles/amazon-lightsail-understanding-bucket-permissions Understanding bucket permissions in Amazon Lightsail>
-- in the
--
-- /Amazon Lightsail Developer Guide/.
--
-- /See:/ 'newAccessRules' smart constructor.
data AccessRules = AccessRules'
  { -- | A Boolean value that indicates whether the access control list (ACL)
    -- permissions that are applied to individual objects override the
    -- @getObject@ option that is currently specified.
    --
    -- When this is true, you can use the
    -- <https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutObjectAcl.html PutObjectAcl>
    -- Amazon S3 API action to set individual objects to public (read-only)
    -- using the @public-read@ ACL, or to private using the @private@ ACL.
    AccessRules -> Maybe Bool
allowPublicOverrides :: Prelude.Maybe Prelude.Bool,
    -- | Specifies the anonymous access to all objects in a bucket.
    --
    -- The following options can be specified:
    --
    -- -   @public@ - Sets all objects in the bucket to public (read-only),
    --     making them readable by anyone in the world.
    --
    --     If the @getObject@ value is set to @public@, then all objects in the
    --     bucket default to public regardless of the @allowPublicOverrides@
    --     value.
    --
    -- -   @private@ - Sets all objects in the bucket to private, making them
    --     readable only by you or anyone you give access to.
    --
    --     If the @getObject@ value is set to @private@, and the
    --     @allowPublicOverrides@ value is set to @true@, then all objects in
    --     the bucket default to private unless they are configured with a
    --     @public-read@ ACL. Individual objects with a @public-read@ ACL are
    --     readable by anyone in the world.
    AccessRules -> Maybe AccessType
getObject :: Prelude.Maybe AccessType
  }
  deriving (AccessRules -> AccessRules -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AccessRules -> AccessRules -> Bool
$c/= :: AccessRules -> AccessRules -> Bool
== :: AccessRules -> AccessRules -> Bool
$c== :: AccessRules -> AccessRules -> Bool
Prelude.Eq, ReadPrec [AccessRules]
ReadPrec AccessRules
Int -> ReadS AccessRules
ReadS [AccessRules]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AccessRules]
$creadListPrec :: ReadPrec [AccessRules]
readPrec :: ReadPrec AccessRules
$creadPrec :: ReadPrec AccessRules
readList :: ReadS [AccessRules]
$creadList :: ReadS [AccessRules]
readsPrec :: Int -> ReadS AccessRules
$creadsPrec :: Int -> ReadS AccessRules
Prelude.Read, Int -> AccessRules -> ShowS
[AccessRules] -> ShowS
AccessRules -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AccessRules] -> ShowS
$cshowList :: [AccessRules] -> ShowS
show :: AccessRules -> String
$cshow :: AccessRules -> String
showsPrec :: Int -> AccessRules -> ShowS
$cshowsPrec :: Int -> AccessRules -> ShowS
Prelude.Show, forall x. Rep AccessRules x -> AccessRules
forall x. AccessRules -> Rep AccessRules x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AccessRules x -> AccessRules
$cfrom :: forall x. AccessRules -> Rep AccessRules x
Prelude.Generic)

-- |
-- Create a value of 'AccessRules' 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:
--
-- 'allowPublicOverrides', 'accessRules_allowPublicOverrides' - A Boolean value that indicates whether the access control list (ACL)
-- permissions that are applied to individual objects override the
-- @getObject@ option that is currently specified.
--
-- When this is true, you can use the
-- <https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutObjectAcl.html PutObjectAcl>
-- Amazon S3 API action to set individual objects to public (read-only)
-- using the @public-read@ ACL, or to private using the @private@ ACL.
--
-- 'getObject', 'accessRules_getObject' - Specifies the anonymous access to all objects in a bucket.
--
-- The following options can be specified:
--
-- -   @public@ - Sets all objects in the bucket to public (read-only),
--     making them readable by anyone in the world.
--
--     If the @getObject@ value is set to @public@, then all objects in the
--     bucket default to public regardless of the @allowPublicOverrides@
--     value.
--
-- -   @private@ - Sets all objects in the bucket to private, making them
--     readable only by you or anyone you give access to.
--
--     If the @getObject@ value is set to @private@, and the
--     @allowPublicOverrides@ value is set to @true@, then all objects in
--     the bucket default to private unless they are configured with a
--     @public-read@ ACL. Individual objects with a @public-read@ ACL are
--     readable by anyone in the world.
newAccessRules ::
  AccessRules
newAccessRules :: AccessRules
newAccessRules =
  AccessRules'
    { $sel:allowPublicOverrides:AccessRules' :: Maybe Bool
allowPublicOverrides =
        forall a. Maybe a
Prelude.Nothing,
      $sel:getObject:AccessRules' :: Maybe AccessType
getObject = forall a. Maybe a
Prelude.Nothing
    }

-- | A Boolean value that indicates whether the access control list (ACL)
-- permissions that are applied to individual objects override the
-- @getObject@ option that is currently specified.
--
-- When this is true, you can use the
-- <https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutObjectAcl.html PutObjectAcl>
-- Amazon S3 API action to set individual objects to public (read-only)
-- using the @public-read@ ACL, or to private using the @private@ ACL.
accessRules_allowPublicOverrides :: Lens.Lens' AccessRules (Prelude.Maybe Prelude.Bool)
accessRules_allowPublicOverrides :: Lens' AccessRules (Maybe Bool)
accessRules_allowPublicOverrides = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AccessRules' {Maybe Bool
allowPublicOverrides :: Maybe Bool
$sel:allowPublicOverrides:AccessRules' :: AccessRules -> Maybe Bool
allowPublicOverrides} -> Maybe Bool
allowPublicOverrides) (\s :: AccessRules
s@AccessRules' {} Maybe Bool
a -> AccessRules
s {$sel:allowPublicOverrides:AccessRules' :: Maybe Bool
allowPublicOverrides = Maybe Bool
a} :: AccessRules)

-- | Specifies the anonymous access to all objects in a bucket.
--
-- The following options can be specified:
--
-- -   @public@ - Sets all objects in the bucket to public (read-only),
--     making them readable by anyone in the world.
--
--     If the @getObject@ value is set to @public@, then all objects in the
--     bucket default to public regardless of the @allowPublicOverrides@
--     value.
--
-- -   @private@ - Sets all objects in the bucket to private, making them
--     readable only by you or anyone you give access to.
--
--     If the @getObject@ value is set to @private@, and the
--     @allowPublicOverrides@ value is set to @true@, then all objects in
--     the bucket default to private unless they are configured with a
--     @public-read@ ACL. Individual objects with a @public-read@ ACL are
--     readable by anyone in the world.
accessRules_getObject :: Lens.Lens' AccessRules (Prelude.Maybe AccessType)
accessRules_getObject :: Lens' AccessRules (Maybe AccessType)
accessRules_getObject = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AccessRules' {Maybe AccessType
getObject :: Maybe AccessType
$sel:getObject:AccessRules' :: AccessRules -> Maybe AccessType
getObject} -> Maybe AccessType
getObject) (\s :: AccessRules
s@AccessRules' {} Maybe AccessType
a -> AccessRules
s {$sel:getObject:AccessRules' :: Maybe AccessType
getObject = Maybe AccessType
a} :: AccessRules)

instance Data.FromJSON AccessRules where
  parseJSON :: Value -> Parser AccessRules
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"AccessRules"
      ( \Object
x ->
          Maybe Bool -> Maybe AccessType -> AccessRules
AccessRules'
            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
"allowPublicOverrides")
            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
"getObject")
      )

instance Prelude.Hashable AccessRules where
  hashWithSalt :: Int -> AccessRules -> Int
hashWithSalt Int
_salt AccessRules' {Maybe Bool
Maybe AccessType
getObject :: Maybe AccessType
allowPublicOverrides :: Maybe Bool
$sel:getObject:AccessRules' :: AccessRules -> Maybe AccessType
$sel:allowPublicOverrides:AccessRules' :: AccessRules -> Maybe Bool
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
allowPublicOverrides
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe AccessType
getObject

instance Prelude.NFData AccessRules where
  rnf :: AccessRules -> ()
rnf AccessRules' {Maybe Bool
Maybe AccessType
getObject :: Maybe AccessType
allowPublicOverrides :: Maybe Bool
$sel:getObject:AccessRules' :: AccessRules -> Maybe AccessType
$sel:allowPublicOverrides:AccessRules' :: AccessRules -> Maybe Bool
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
allowPublicOverrides
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe AccessType
getObject

instance Data.ToJSON AccessRules where
  toJSON :: AccessRules -> Value
toJSON AccessRules' {Maybe Bool
Maybe AccessType
getObject :: Maybe AccessType
allowPublicOverrides :: Maybe Bool
$sel:getObject:AccessRules' :: AccessRules -> Maybe AccessType
$sel:allowPublicOverrides:AccessRules' :: AccessRules -> Maybe Bool
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"allowPublicOverrides" 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 Bool
allowPublicOverrides,
            (Key
"getObject" 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 AccessType
getObject
          ]
      )