{-# 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.S3.Types.ReplicationConfiguration
-- 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.S3.Types.ReplicationConfiguration where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.S3.Internal
import Amazonka.S3.Types.ReplicationRule

-- | A container for replication rules. You can add up to 1,000 rules. The
-- maximum size of a replication configuration is 2 MB.
--
-- /See:/ 'newReplicationConfiguration' smart constructor.
data ReplicationConfiguration = ReplicationConfiguration'
  { -- | The Amazon Resource Name (ARN) of the Identity and Access Management
    -- (IAM) role that Amazon S3 assumes when replicating objects. For more
    -- information, see
    -- <https://docs.aws.amazon.com/AmazonS3/latest/dev/replication-how-setup.html How to Set Up Replication>
    -- in the /Amazon S3 User Guide/.
    ReplicationConfiguration -> Text
role' :: Prelude.Text,
    -- | A container for one or more replication rules. A replication
    -- configuration must have at least one rule and can contain a maximum of
    -- 1,000 rules.
    ReplicationConfiguration -> [ReplicationRule]
rules :: [ReplicationRule]
  }
  deriving (ReplicationConfiguration -> ReplicationConfiguration -> Bool
(ReplicationConfiguration -> ReplicationConfiguration -> Bool)
-> (ReplicationConfiguration -> ReplicationConfiguration -> Bool)
-> Eq ReplicationConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ReplicationConfiguration -> ReplicationConfiguration -> Bool
$c/= :: ReplicationConfiguration -> ReplicationConfiguration -> Bool
== :: ReplicationConfiguration -> ReplicationConfiguration -> Bool
$c== :: ReplicationConfiguration -> ReplicationConfiguration -> Bool
Prelude.Eq, ReadPrec [ReplicationConfiguration]
ReadPrec ReplicationConfiguration
Int -> ReadS ReplicationConfiguration
ReadS [ReplicationConfiguration]
(Int -> ReadS ReplicationConfiguration)
-> ReadS [ReplicationConfiguration]
-> ReadPrec ReplicationConfiguration
-> ReadPrec [ReplicationConfiguration]
-> Read ReplicationConfiguration
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ReplicationConfiguration]
$creadListPrec :: ReadPrec [ReplicationConfiguration]
readPrec :: ReadPrec ReplicationConfiguration
$creadPrec :: ReadPrec ReplicationConfiguration
readList :: ReadS [ReplicationConfiguration]
$creadList :: ReadS [ReplicationConfiguration]
readsPrec :: Int -> ReadS ReplicationConfiguration
$creadsPrec :: Int -> ReadS ReplicationConfiguration
Prelude.Read, Int -> ReplicationConfiguration -> ShowS
[ReplicationConfiguration] -> ShowS
ReplicationConfiguration -> String
(Int -> ReplicationConfiguration -> ShowS)
-> (ReplicationConfiguration -> String)
-> ([ReplicationConfiguration] -> ShowS)
-> Show ReplicationConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ReplicationConfiguration] -> ShowS
$cshowList :: [ReplicationConfiguration] -> ShowS
show :: ReplicationConfiguration -> String
$cshow :: ReplicationConfiguration -> String
showsPrec :: Int -> ReplicationConfiguration -> ShowS
$cshowsPrec :: Int -> ReplicationConfiguration -> ShowS
Prelude.Show, (forall x.
 ReplicationConfiguration -> Rep ReplicationConfiguration x)
-> (forall x.
    Rep ReplicationConfiguration x -> ReplicationConfiguration)
-> Generic ReplicationConfiguration
forall x.
Rep ReplicationConfiguration x -> ReplicationConfiguration
forall x.
ReplicationConfiguration -> Rep ReplicationConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ReplicationConfiguration x -> ReplicationConfiguration
$cfrom :: forall x.
ReplicationConfiguration -> Rep ReplicationConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'ReplicationConfiguration' 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:
--
-- 'role'', 'replicationConfiguration_role' - The Amazon Resource Name (ARN) of the Identity and Access Management
-- (IAM) role that Amazon S3 assumes when replicating objects. For more
-- information, see
-- <https://docs.aws.amazon.com/AmazonS3/latest/dev/replication-how-setup.html How to Set Up Replication>
-- in the /Amazon S3 User Guide/.
--
-- 'rules', 'replicationConfiguration_rules' - A container for one or more replication rules. A replication
-- configuration must have at least one rule and can contain a maximum of
-- 1,000 rules.
newReplicationConfiguration ::
  -- | 'role''
  Prelude.Text ->
  ReplicationConfiguration
newReplicationConfiguration :: Text -> ReplicationConfiguration
newReplicationConfiguration Text
pRole_ =
  ReplicationConfiguration' :: Text -> [ReplicationRule] -> ReplicationConfiguration
ReplicationConfiguration'
    { $sel:role':ReplicationConfiguration' :: Text
role' = Text
pRole_,
      $sel:rules:ReplicationConfiguration' :: [ReplicationRule]
rules = [ReplicationRule]
forall a. Monoid a => a
Prelude.mempty
    }

-- | The Amazon Resource Name (ARN) of the Identity and Access Management
-- (IAM) role that Amazon S3 assumes when replicating objects. For more
-- information, see
-- <https://docs.aws.amazon.com/AmazonS3/latest/dev/replication-how-setup.html How to Set Up Replication>
-- in the /Amazon S3 User Guide/.
replicationConfiguration_role :: Lens.Lens' ReplicationConfiguration Prelude.Text
replicationConfiguration_role :: (Text -> f Text)
-> ReplicationConfiguration -> f ReplicationConfiguration
replicationConfiguration_role = (ReplicationConfiguration -> Text)
-> (ReplicationConfiguration -> Text -> ReplicationConfiguration)
-> Lens ReplicationConfiguration ReplicationConfiguration Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ReplicationConfiguration' {Text
role' :: Text
$sel:role':ReplicationConfiguration' :: ReplicationConfiguration -> Text
role'} -> Text
role') (\s :: ReplicationConfiguration
s@ReplicationConfiguration' {} Text
a -> ReplicationConfiguration
s {$sel:role':ReplicationConfiguration' :: Text
role' = Text
a} :: ReplicationConfiguration)

-- | A container for one or more replication rules. A replication
-- configuration must have at least one rule and can contain a maximum of
-- 1,000 rules.
replicationConfiguration_rules :: Lens.Lens' ReplicationConfiguration [ReplicationRule]
replicationConfiguration_rules :: ([ReplicationRule] -> f [ReplicationRule])
-> ReplicationConfiguration -> f ReplicationConfiguration
replicationConfiguration_rules = (ReplicationConfiguration -> [ReplicationRule])
-> (ReplicationConfiguration
    -> [ReplicationRule] -> ReplicationConfiguration)
-> Lens
     ReplicationConfiguration
     ReplicationConfiguration
     [ReplicationRule]
     [ReplicationRule]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ReplicationConfiguration' {[ReplicationRule]
rules :: [ReplicationRule]
$sel:rules:ReplicationConfiguration' :: ReplicationConfiguration -> [ReplicationRule]
rules} -> [ReplicationRule]
rules) (\s :: ReplicationConfiguration
s@ReplicationConfiguration' {} [ReplicationRule]
a -> ReplicationConfiguration
s {$sel:rules:ReplicationConfiguration' :: [ReplicationRule]
rules = [ReplicationRule]
a} :: ReplicationConfiguration) (([ReplicationRule] -> f [ReplicationRule])
 -> ReplicationConfiguration -> f ReplicationConfiguration)
-> (([ReplicationRule] -> f [ReplicationRule])
    -> [ReplicationRule] -> f [ReplicationRule])
-> ([ReplicationRule] -> f [ReplicationRule])
-> ReplicationConfiguration
-> f ReplicationConfiguration
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([ReplicationRule] -> f [ReplicationRule])
-> [ReplicationRule] -> f [ReplicationRule]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.Hashable ReplicationConfiguration

instance Prelude.NFData ReplicationConfiguration

instance Core.ToXML ReplicationConfiguration where
  toXML :: ReplicationConfiguration -> XML
toXML ReplicationConfiguration' {[ReplicationRule]
Text
rules :: [ReplicationRule]
role' :: Text
$sel:rules:ReplicationConfiguration' :: ReplicationConfiguration -> [ReplicationRule]
$sel:role':ReplicationConfiguration' :: ReplicationConfiguration -> Text
..} =
    [XML] -> XML
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [Name
"Role" Name -> Text -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Text
role', Name -> [ReplicationRule] -> XML
forall a. (IsList a, ToXML (Item a)) => Name -> a -> XML
Core.toXMLList Name
"Rule" [ReplicationRule]
rules]