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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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'
  { -- | 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,
    -- | 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
  }
  deriving (AccessRules -> AccessRules -> Bool
(AccessRules -> AccessRules -> Bool)
-> (AccessRules -> AccessRules -> Bool) -> Eq AccessRules
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]
(Int -> ReadS AccessRules)
-> ReadS [AccessRules]
-> ReadPrec AccessRules
-> ReadPrec [AccessRules]
-> Read 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
(Int -> AccessRules -> ShowS)
-> (AccessRules -> String)
-> ([AccessRules] -> ShowS)
-> Show AccessRules
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. AccessRules -> Rep AccessRules x)
-> (forall x. Rep AccessRules x -> AccessRules)
-> Generic AccessRules
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:
--
-- '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.
--
-- '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.
newAccessRules ::
  AccessRules
newAccessRules :: AccessRules
newAccessRules =
  AccessRules' :: Maybe AccessType -> Maybe Bool -> AccessRules
AccessRules'
    { $sel:getObject:AccessRules' :: Maybe AccessType
getObject = Maybe AccessType
forall a. Maybe a
Prelude.Nothing,
      $sel:allowPublicOverrides:AccessRules' :: Maybe Bool
allowPublicOverrides = Maybe Bool
forall a. Maybe a
Prelude.Nothing
    }

-- | 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 :: (Maybe AccessType -> f (Maybe AccessType))
-> AccessRules -> f AccessRules
accessRules_getObject = (AccessRules -> Maybe AccessType)
-> (AccessRules -> Maybe AccessType -> AccessRules)
-> Lens
     AccessRules AccessRules (Maybe AccessType) (Maybe AccessType)
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)

-- | 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 :: (Maybe Bool -> f (Maybe Bool)) -> AccessRules -> f AccessRules
accessRules_allowPublicOverrides = (AccessRules -> Maybe Bool)
-> (AccessRules -> Maybe Bool -> AccessRules)
-> Lens AccessRules AccessRules (Maybe Bool) (Maybe Bool)
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)

instance Core.FromJSON AccessRules where
  parseJSON :: Value -> Parser AccessRules
parseJSON =
    String
-> (Object -> Parser AccessRules) -> Value -> Parser AccessRules
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"AccessRules"
      ( \Object
x ->
          Maybe AccessType -> Maybe Bool -> AccessRules
AccessRules'
            (Maybe AccessType -> Maybe Bool -> AccessRules)
-> Parser (Maybe AccessType) -> Parser (Maybe Bool -> AccessRules)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe AccessType)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"getObject")
            Parser (Maybe Bool -> AccessRules)
-> Parser (Maybe Bool) -> Parser AccessRules
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
"allowPublicOverrides")
      )

instance Prelude.Hashable AccessRules

instance Prelude.NFData AccessRules

instance Core.ToJSON AccessRules where
  toJSON :: AccessRules -> Value
toJSON AccessRules' {Maybe Bool
Maybe AccessType
allowPublicOverrides :: Maybe Bool
getObject :: Maybe AccessType
$sel:allowPublicOverrides:AccessRules' :: AccessRules -> Maybe Bool
$sel:getObject:AccessRules' :: AccessRules -> Maybe AccessType
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"getObject" Text -> AccessType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (AccessType -> Pair) -> Maybe AccessType -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe AccessType
getObject,
            (Text
"allowPublicOverrides" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Bool -> Pair) -> Maybe Bool -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
allowPublicOverrides
          ]
      )