{-# 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.S3Origin
-- 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.S3Origin 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 bucket from
-- which you want CloudFront to get your media files for distribution.
--
-- /See:/ 'newS3Origin' smart constructor.
data S3Origin = S3Origin'
  { -- | The DNS name of the Amazon S3 origin.
    S3Origin -> Text
domainName :: Prelude.Text,
    -- | The CloudFront origin access identity to associate with the
    -- distribution. Use an origin access identity to configure the
    -- distribution so that end users can only access objects in an Amazon S3
    -- bucket through CloudFront.
    --
    -- If you want end users 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, see
    -- <https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-restricting-access-to-s3.html Using an Origin Access Identity to Restrict Access to Your Amazon S3 Content>
    -- in the /Amazon CloudFront Developer Guide/.
    S3Origin -> Text
originAccessIdentity :: Prelude.Text
  }
  deriving (S3Origin -> S3Origin -> Bool
(S3Origin -> S3Origin -> Bool)
-> (S3Origin -> S3Origin -> Bool) -> Eq S3Origin
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: S3Origin -> S3Origin -> Bool
$c/= :: S3Origin -> S3Origin -> Bool
== :: S3Origin -> S3Origin -> Bool
$c== :: S3Origin -> S3Origin -> Bool
Prelude.Eq, ReadPrec [S3Origin]
ReadPrec S3Origin
Int -> ReadS S3Origin
ReadS [S3Origin]
(Int -> ReadS S3Origin)
-> ReadS [S3Origin]
-> ReadPrec S3Origin
-> ReadPrec [S3Origin]
-> Read S3Origin
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [S3Origin]
$creadListPrec :: ReadPrec [S3Origin]
readPrec :: ReadPrec S3Origin
$creadPrec :: ReadPrec S3Origin
readList :: ReadS [S3Origin]
$creadList :: ReadS [S3Origin]
readsPrec :: Int -> ReadS S3Origin
$creadsPrec :: Int -> ReadS S3Origin
Prelude.Read, Int -> S3Origin -> ShowS
[S3Origin] -> ShowS
S3Origin -> String
(Int -> S3Origin -> ShowS)
-> (S3Origin -> String) -> ([S3Origin] -> ShowS) -> Show S3Origin
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [S3Origin] -> ShowS
$cshowList :: [S3Origin] -> ShowS
show :: S3Origin -> String
$cshow :: S3Origin -> String
showsPrec :: Int -> S3Origin -> ShowS
$cshowsPrec :: Int -> S3Origin -> ShowS
Prelude.Show, (forall x. S3Origin -> Rep S3Origin x)
-> (forall x. Rep S3Origin x -> S3Origin) -> Generic S3Origin
forall x. Rep S3Origin x -> S3Origin
forall x. S3Origin -> Rep S3Origin x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep S3Origin x -> S3Origin
$cfrom :: forall x. S3Origin -> Rep S3Origin x
Prelude.Generic)

-- |
-- Create a value of 'S3Origin' 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:
--
-- 'domainName', 's3Origin_domainName' - The DNS name of the Amazon S3 origin.
--
-- 'originAccessIdentity', 's3Origin_originAccessIdentity' - The CloudFront origin access identity to associate with the
-- distribution. Use an origin access identity to configure the
-- distribution so that end users can only access objects in an Amazon S3
-- bucket through CloudFront.
--
-- If you want end users 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, see
-- <https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-restricting-access-to-s3.html Using an Origin Access Identity to Restrict Access to Your Amazon S3 Content>
-- in the /Amazon CloudFront Developer Guide/.
newS3Origin ::
  -- | 'domainName'
  Prelude.Text ->
  -- | 'originAccessIdentity'
  Prelude.Text ->
  S3Origin
newS3Origin :: Text -> Text -> S3Origin
newS3Origin Text
pDomainName_ Text
pOriginAccessIdentity_ =
  S3Origin' :: Text -> Text -> S3Origin
S3Origin'
    { $sel:domainName:S3Origin' :: Text
domainName = Text
pDomainName_,
      $sel:originAccessIdentity:S3Origin' :: Text
originAccessIdentity = Text
pOriginAccessIdentity_
    }

-- | The DNS name of the Amazon S3 origin.
s3Origin_domainName :: Lens.Lens' S3Origin Prelude.Text
s3Origin_domainName :: (Text -> f Text) -> S3Origin -> f S3Origin
s3Origin_domainName = (S3Origin -> Text)
-> (S3Origin -> Text -> S3Origin)
-> Lens S3Origin S3Origin Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\S3Origin' {Text
domainName :: Text
$sel:domainName:S3Origin' :: S3Origin -> Text
domainName} -> Text
domainName) (\s :: S3Origin
s@S3Origin' {} Text
a -> S3Origin
s {$sel:domainName:S3Origin' :: Text
domainName = Text
a} :: S3Origin)

-- | The CloudFront origin access identity to associate with the
-- distribution. Use an origin access identity to configure the
-- distribution so that end users can only access objects in an Amazon S3
-- bucket through CloudFront.
--
-- If you want end users 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, see
-- <https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-restricting-access-to-s3.html Using an Origin Access Identity to Restrict Access to Your Amazon S3 Content>
-- in the /Amazon CloudFront Developer Guide/.
s3Origin_originAccessIdentity :: Lens.Lens' S3Origin Prelude.Text
s3Origin_originAccessIdentity :: (Text -> f Text) -> S3Origin -> f S3Origin
s3Origin_originAccessIdentity = (S3Origin -> Text)
-> (S3Origin -> Text -> S3Origin)
-> Lens S3Origin S3Origin Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\S3Origin' {Text
originAccessIdentity :: Text
$sel:originAccessIdentity:S3Origin' :: S3Origin -> Text
originAccessIdentity} -> Text
originAccessIdentity) (\s :: S3Origin
s@S3Origin' {} Text
a -> S3Origin
s {$sel:originAccessIdentity:S3Origin' :: Text
originAccessIdentity = Text
a} :: S3Origin)

instance Core.FromXML S3Origin where
  parseXML :: [Node] -> Either String S3Origin
parseXML [Node]
x =
    Text -> Text -> S3Origin
S3Origin'
      (Text -> Text -> S3Origin)
-> Either String Text -> Either String (Text -> S3Origin)
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
"DomainName")
      Either String (Text -> S3Origin)
-> Either String Text -> Either String S3Origin
forall (f :: * -> *) a b. Applicative f => 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 S3Origin

instance Prelude.NFData S3Origin

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