{-# 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.CloudFront.Types.S3OriginConfig
-- 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.CloudFront.Types.S3OriginConfig where

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

-- | A complex type that contains information about the Amazon S3 origin. If
-- the origin is a custom origin or an S3 bucket that is configured as a
-- website endpoint, use the @CustomOriginConfig@ element instead.
--
-- /See:/ 'newS3OriginConfig' smart constructor.
data S3OriginConfig = S3OriginConfig'
  { -- | The CloudFront origin access identity to associate with the origin. Use
    -- an origin access identity to configure the origin so that viewers can
    -- /only/ access objects in an Amazon S3 bucket through CloudFront. The
    -- format of the value is:
    --
    -- origin-access-identity\/cloudfront\//ID-of-origin-access-identity/
    --
    -- where @ ID-of-origin-access-identity @ is the value that CloudFront
    -- returned in the @ID@ element when you created the origin access
    -- identity.
    --
    -- If you want viewers to be able to access objects using either the
    -- CloudFront URL or the Amazon S3 URL, specify an empty
    -- @OriginAccessIdentity@ element.
    --
    -- To delete the origin access identity from an existing distribution,
    -- update the distribution configuration and include an empty
    -- @OriginAccessIdentity@ element.
    --
    -- To replace the origin access identity, update the distribution
    -- configuration and specify the new origin access identity.
    --
    -- For more information about the origin access identity, see
    -- <https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/PrivateContent.html Serving Private Content through CloudFront>
    -- in the /Amazon CloudFront Developer Guide/.
    S3OriginConfig -> Text
originAccessIdentity :: Prelude.Text
  }
  deriving (S3OriginConfig -> S3OriginConfig -> Bool
(S3OriginConfig -> S3OriginConfig -> Bool)
-> (S3OriginConfig -> S3OriginConfig -> Bool) -> Eq S3OriginConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: S3OriginConfig -> S3OriginConfig -> Bool
$c/= :: S3OriginConfig -> S3OriginConfig -> Bool
== :: S3OriginConfig -> S3OriginConfig -> Bool
$c== :: S3OriginConfig -> S3OriginConfig -> Bool
Prelude.Eq, ReadPrec [S3OriginConfig]
ReadPrec S3OriginConfig
Int -> ReadS S3OriginConfig
ReadS [S3OriginConfig]
(Int -> ReadS S3OriginConfig)
-> ReadS [S3OriginConfig]
-> ReadPrec S3OriginConfig
-> ReadPrec [S3OriginConfig]
-> Read S3OriginConfig
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [S3OriginConfig]
$creadListPrec :: ReadPrec [S3OriginConfig]
readPrec :: ReadPrec S3OriginConfig
$creadPrec :: ReadPrec S3OriginConfig
readList :: ReadS [S3OriginConfig]
$creadList :: ReadS [S3OriginConfig]
readsPrec :: Int -> ReadS S3OriginConfig
$creadsPrec :: Int -> ReadS S3OriginConfig
Prelude.Read, Int -> S3OriginConfig -> ShowS
[S3OriginConfig] -> ShowS
S3OriginConfig -> String
(Int -> S3OriginConfig -> ShowS)
-> (S3OriginConfig -> String)
-> ([S3OriginConfig] -> ShowS)
-> Show S3OriginConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [S3OriginConfig] -> ShowS
$cshowList :: [S3OriginConfig] -> ShowS
show :: S3OriginConfig -> String
$cshow :: S3OriginConfig -> String
showsPrec :: Int -> S3OriginConfig -> ShowS
$cshowsPrec :: Int -> S3OriginConfig -> ShowS
Prelude.Show, (forall x. S3OriginConfig -> Rep S3OriginConfig x)
-> (forall x. Rep S3OriginConfig x -> S3OriginConfig)
-> Generic S3OriginConfig
forall x. Rep S3OriginConfig x -> S3OriginConfig
forall x. S3OriginConfig -> Rep S3OriginConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep S3OriginConfig x -> S3OriginConfig
$cfrom :: forall x. S3OriginConfig -> Rep S3OriginConfig x
Prelude.Generic)

-- |
-- Create a value of 'S3OriginConfig' 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:
--
-- 'originAccessIdentity', 's3OriginConfig_originAccessIdentity' - The CloudFront origin access identity to associate with the origin. Use
-- an origin access identity to configure the origin so that viewers can
-- /only/ access objects in an Amazon S3 bucket through CloudFront. The
-- format of the value is:
--
-- origin-access-identity\/cloudfront\//ID-of-origin-access-identity/
--
-- where @ ID-of-origin-access-identity @ is the value that CloudFront
-- returned in the @ID@ element when you created the origin access
-- identity.
--
-- If you want viewers to be able to access objects using either the
-- CloudFront URL or the Amazon S3 URL, specify an empty
-- @OriginAccessIdentity@ element.
--
-- To delete the origin access identity from an existing distribution,
-- update the distribution configuration and include an empty
-- @OriginAccessIdentity@ element.
--
-- To replace the origin access identity, update the distribution
-- configuration and specify the new origin access identity.
--
-- For more information about the origin access identity, see
-- <https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/PrivateContent.html Serving Private Content through CloudFront>
-- in the /Amazon CloudFront Developer Guide/.
newS3OriginConfig ::
  -- | 'originAccessIdentity'
  Prelude.Text ->
  S3OriginConfig
newS3OriginConfig :: Text -> S3OriginConfig
newS3OriginConfig Text
pOriginAccessIdentity_ =
  S3OriginConfig' :: Text -> S3OriginConfig
S3OriginConfig'
    { $sel:originAccessIdentity:S3OriginConfig' :: Text
originAccessIdentity =
        Text
pOriginAccessIdentity_
    }

-- | The CloudFront origin access identity to associate with the origin. Use
-- an origin access identity to configure the origin so that viewers can
-- /only/ access objects in an Amazon S3 bucket through CloudFront. The
-- format of the value is:
--
-- origin-access-identity\/cloudfront\//ID-of-origin-access-identity/
--
-- where @ ID-of-origin-access-identity @ is the value that CloudFront
-- returned in the @ID@ element when you created the origin access
-- identity.
--
-- If you want viewers to be able to access objects using either the
-- CloudFront URL or the Amazon S3 URL, specify an empty
-- @OriginAccessIdentity@ element.
--
-- To delete the origin access identity from an existing distribution,
-- update the distribution configuration and include an empty
-- @OriginAccessIdentity@ element.
--
-- To replace the origin access identity, update the distribution
-- configuration and specify the new origin access identity.
--
-- For more information about the origin access identity, see
-- <https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/PrivateContent.html Serving Private Content through CloudFront>
-- in the /Amazon CloudFront Developer Guide/.
s3OriginConfig_originAccessIdentity :: Lens.Lens' S3OriginConfig Prelude.Text
s3OriginConfig_originAccessIdentity :: (Text -> f Text) -> S3OriginConfig -> f S3OriginConfig
s3OriginConfig_originAccessIdentity = (S3OriginConfig -> Text)
-> (S3OriginConfig -> Text -> S3OriginConfig)
-> Lens S3OriginConfig S3OriginConfig Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\S3OriginConfig' {Text
originAccessIdentity :: Text
$sel:originAccessIdentity:S3OriginConfig' :: S3OriginConfig -> Text
originAccessIdentity} -> Text
originAccessIdentity) (\s :: S3OriginConfig
s@S3OriginConfig' {} Text
a -> S3OriginConfig
s {$sel:originAccessIdentity:S3OriginConfig' :: Text
originAccessIdentity = Text
a} :: S3OriginConfig)

instance Core.FromXML S3OriginConfig where
  parseXML :: [Node] -> Either String S3OriginConfig
parseXML [Node]
x =
    Text -> S3OriginConfig
S3OriginConfig'
      (Text -> S3OriginConfig)
-> Either String Text -> Either String S3OriginConfig
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String Text
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"OriginAccessIdentity")

instance Prelude.Hashable S3OriginConfig

instance Prelude.NFData S3OriginConfig

instance Core.ToXML S3OriginConfig where
  toXML :: S3OriginConfig -> XML
toXML S3OriginConfig' {Text
originAccessIdentity :: Text
$sel:originAccessIdentity:S3OriginConfig' :: S3OriginConfig -> Text
..} =
    [XML] -> XML
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [Name
"OriginAccessIdentity" Name -> Text -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Text
originAccessIdentity]