{-# 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.SES.Types.S3Action
-- 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.SES.Types.S3Action where

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

-- | When included in a receipt rule, this action saves the received message
-- to an Amazon Simple Storage Service (Amazon S3) bucket and, optionally,
-- publishes a notification to Amazon Simple Notification Service (Amazon
-- SNS).
--
-- To enable Amazon SES to write emails to your Amazon S3 bucket, use an
-- AWS KMS key to encrypt your emails, or publish to an Amazon SNS topic of
-- another account, Amazon SES must have permission to access those
-- resources. For information about giving permissions, see the
-- <https://docs.aws.amazon.com/ses/latest/DeveloperGuide/receiving-email-permissions.html Amazon SES Developer Guide>.
--
-- When you save your emails to an Amazon S3 bucket, the maximum email size
-- (including headers) is 30 MB. Emails larger than that will bounce.
--
-- For information about specifying Amazon S3 actions in receipt rules, see
-- the
-- <https://docs.aws.amazon.com/ses/latest/DeveloperGuide/receiving-email-action-s3.html Amazon SES Developer Guide>.
--
-- /See:/ 'newS3Action' smart constructor.
data S3Action = S3Action'
  { -- | The customer master key that Amazon SES should use to encrypt your
    -- emails before saving them to the Amazon S3 bucket. You can use the
    -- default master key or a custom master key you created in AWS KMS as
    -- follows:
    --
    -- -   To use the default master key, provide an ARN in the form of
    --     @arn:aws:kms:REGION:ACCOUNT-ID-WITHOUT-HYPHENS:alias\/aws\/ses@. For
    --     example, if your AWS account ID is 123456789012 and you want to use
    --     the default master key in the US West (Oregon) region, the ARN of
    --     the default master key would be
    --     @arn:aws:kms:us-west-2:123456789012:alias\/aws\/ses@. If you use the
    --     default master key, you don\'t need to perform any extra steps to
    --     give Amazon SES permission to use the key.
    --
    -- -   To use a custom master key you created in AWS KMS, provide the ARN
    --     of the master key and ensure that you add a statement to your key\'s
    --     policy to give Amazon SES permission to use it. For more information
    --     about giving permissions, see the
    --     <https://docs.aws.amazon.com/ses/latest/DeveloperGuide/receiving-email-permissions.html Amazon SES Developer Guide>.
    --
    -- For more information about key policies, see the
    -- <https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html AWS KMS Developer Guide>.
    -- If you do not specify a master key, Amazon SES will not encrypt your
    -- emails.
    --
    -- Your mail is encrypted by Amazon SES using the Amazon S3 encryption
    -- client before the mail is submitted to Amazon S3 for storage. It is not
    -- encrypted using Amazon S3 server-side encryption. This means that you
    -- must use the Amazon S3 encryption client to decrypt the email after
    -- retrieving it from Amazon S3, as the service has no access to use your
    -- AWS KMS keys for decryption. This encryption client is currently
    -- available with the
    -- <http://aws.amazon.com/sdk-for-java/ AWS SDK for Java> and
    -- <http://aws.amazon.com/sdk-for-ruby/ AWS SDK for Ruby> only. For more
    -- information about client-side encryption using AWS KMS master keys, see
    -- the
    -- <https://docs.aws.amazon.com/AmazonS3/latest/dev/UsingClientSideEncryption.html Amazon S3 Developer Guide>.
    S3Action -> Maybe Text
kmsKeyArn :: Prelude.Maybe Prelude.Text,
    -- | The ARN of the Amazon SNS topic to notify when the message is saved to
    -- the Amazon S3 bucket. An example of an Amazon SNS topic ARN is
    -- @arn:aws:sns:us-west-2:123456789012:MyTopic@. For more information about
    -- Amazon SNS topics, see the
    -- <https://docs.aws.amazon.com/sns/latest/dg/CreateTopic.html Amazon SNS Developer Guide>.
    S3Action -> Maybe Text
topicArn :: Prelude.Maybe Prelude.Text,
    -- | The key prefix of the Amazon S3 bucket. The key prefix is similar to a
    -- directory name that enables you to store similar data under the same
    -- directory in a bucket.
    S3Action -> Maybe Text
objectKeyPrefix :: Prelude.Maybe Prelude.Text,
    -- | The name of the Amazon S3 bucket that incoming email will be saved to.
    S3Action -> Text
bucketName :: Prelude.Text
  }
  deriving (S3Action -> S3Action -> Bool
(S3Action -> S3Action -> Bool)
-> (S3Action -> S3Action -> Bool) -> Eq S3Action
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: S3Action -> S3Action -> Bool
$c/= :: S3Action -> S3Action -> Bool
== :: S3Action -> S3Action -> Bool
$c== :: S3Action -> S3Action -> Bool
Prelude.Eq, ReadPrec [S3Action]
ReadPrec S3Action
Int -> ReadS S3Action
ReadS [S3Action]
(Int -> ReadS S3Action)
-> ReadS [S3Action]
-> ReadPrec S3Action
-> ReadPrec [S3Action]
-> Read S3Action
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [S3Action]
$creadListPrec :: ReadPrec [S3Action]
readPrec :: ReadPrec S3Action
$creadPrec :: ReadPrec S3Action
readList :: ReadS [S3Action]
$creadList :: ReadS [S3Action]
readsPrec :: Int -> ReadS S3Action
$creadsPrec :: Int -> ReadS S3Action
Prelude.Read, Int -> S3Action -> ShowS
[S3Action] -> ShowS
S3Action -> String
(Int -> S3Action -> ShowS)
-> (S3Action -> String) -> ([S3Action] -> ShowS) -> Show S3Action
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [S3Action] -> ShowS
$cshowList :: [S3Action] -> ShowS
show :: S3Action -> String
$cshow :: S3Action -> String
showsPrec :: Int -> S3Action -> ShowS
$cshowsPrec :: Int -> S3Action -> ShowS
Prelude.Show, (forall x. S3Action -> Rep S3Action x)
-> (forall x. Rep S3Action x -> S3Action) -> Generic S3Action
forall x. Rep S3Action x -> S3Action
forall x. S3Action -> Rep S3Action x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep S3Action x -> S3Action
$cfrom :: forall x. S3Action -> Rep S3Action x
Prelude.Generic)

-- |
-- Create a value of 'S3Action' 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:
--
-- 'kmsKeyArn', 's3Action_kmsKeyArn' - The customer master key that Amazon SES should use to encrypt your
-- emails before saving them to the Amazon S3 bucket. You can use the
-- default master key or a custom master key you created in AWS KMS as
-- follows:
--
-- -   To use the default master key, provide an ARN in the form of
--     @arn:aws:kms:REGION:ACCOUNT-ID-WITHOUT-HYPHENS:alias\/aws\/ses@. For
--     example, if your AWS account ID is 123456789012 and you want to use
--     the default master key in the US West (Oregon) region, the ARN of
--     the default master key would be
--     @arn:aws:kms:us-west-2:123456789012:alias\/aws\/ses@. If you use the
--     default master key, you don\'t need to perform any extra steps to
--     give Amazon SES permission to use the key.
--
-- -   To use a custom master key you created in AWS KMS, provide the ARN
--     of the master key and ensure that you add a statement to your key\'s
--     policy to give Amazon SES permission to use it. For more information
--     about giving permissions, see the
--     <https://docs.aws.amazon.com/ses/latest/DeveloperGuide/receiving-email-permissions.html Amazon SES Developer Guide>.
--
-- For more information about key policies, see the
-- <https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html AWS KMS Developer Guide>.
-- If you do not specify a master key, Amazon SES will not encrypt your
-- emails.
--
-- Your mail is encrypted by Amazon SES using the Amazon S3 encryption
-- client before the mail is submitted to Amazon S3 for storage. It is not
-- encrypted using Amazon S3 server-side encryption. This means that you
-- must use the Amazon S3 encryption client to decrypt the email after
-- retrieving it from Amazon S3, as the service has no access to use your
-- AWS KMS keys for decryption. This encryption client is currently
-- available with the
-- <http://aws.amazon.com/sdk-for-java/ AWS SDK for Java> and
-- <http://aws.amazon.com/sdk-for-ruby/ AWS SDK for Ruby> only. For more
-- information about client-side encryption using AWS KMS master keys, see
-- the
-- <https://docs.aws.amazon.com/AmazonS3/latest/dev/UsingClientSideEncryption.html Amazon S3 Developer Guide>.
--
-- 'topicArn', 's3Action_topicArn' - The ARN of the Amazon SNS topic to notify when the message is saved to
-- the Amazon S3 bucket. An example of an Amazon SNS topic ARN is
-- @arn:aws:sns:us-west-2:123456789012:MyTopic@. For more information about
-- Amazon SNS topics, see the
-- <https://docs.aws.amazon.com/sns/latest/dg/CreateTopic.html Amazon SNS Developer Guide>.
--
-- 'objectKeyPrefix', 's3Action_objectKeyPrefix' - The key prefix of the Amazon S3 bucket. The key prefix is similar to a
-- directory name that enables you to store similar data under the same
-- directory in a bucket.
--
-- 'bucketName', 's3Action_bucketName' - The name of the Amazon S3 bucket that incoming email will be saved to.
newS3Action ::
  -- | 'bucketName'
  Prelude.Text ->
  S3Action
newS3Action :: Text -> S3Action
newS3Action Text
pBucketName_ =
  S3Action' :: Maybe Text -> Maybe Text -> Maybe Text -> Text -> S3Action
S3Action'
    { $sel:kmsKeyArn:S3Action' :: Maybe Text
kmsKeyArn = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:topicArn:S3Action' :: Maybe Text
topicArn = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:objectKeyPrefix:S3Action' :: Maybe Text
objectKeyPrefix = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:bucketName:S3Action' :: Text
bucketName = Text
pBucketName_
    }

-- | The customer master key that Amazon SES should use to encrypt your
-- emails before saving them to the Amazon S3 bucket. You can use the
-- default master key or a custom master key you created in AWS KMS as
-- follows:
--
-- -   To use the default master key, provide an ARN in the form of
--     @arn:aws:kms:REGION:ACCOUNT-ID-WITHOUT-HYPHENS:alias\/aws\/ses@. For
--     example, if your AWS account ID is 123456789012 and you want to use
--     the default master key in the US West (Oregon) region, the ARN of
--     the default master key would be
--     @arn:aws:kms:us-west-2:123456789012:alias\/aws\/ses@. If you use the
--     default master key, you don\'t need to perform any extra steps to
--     give Amazon SES permission to use the key.
--
-- -   To use a custom master key you created in AWS KMS, provide the ARN
--     of the master key and ensure that you add a statement to your key\'s
--     policy to give Amazon SES permission to use it. For more information
--     about giving permissions, see the
--     <https://docs.aws.amazon.com/ses/latest/DeveloperGuide/receiving-email-permissions.html Amazon SES Developer Guide>.
--
-- For more information about key policies, see the
-- <https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html AWS KMS Developer Guide>.
-- If you do not specify a master key, Amazon SES will not encrypt your
-- emails.
--
-- Your mail is encrypted by Amazon SES using the Amazon S3 encryption
-- client before the mail is submitted to Amazon S3 for storage. It is not
-- encrypted using Amazon S3 server-side encryption. This means that you
-- must use the Amazon S3 encryption client to decrypt the email after
-- retrieving it from Amazon S3, as the service has no access to use your
-- AWS KMS keys for decryption. This encryption client is currently
-- available with the
-- <http://aws.amazon.com/sdk-for-java/ AWS SDK for Java> and
-- <http://aws.amazon.com/sdk-for-ruby/ AWS SDK for Ruby> only. For more
-- information about client-side encryption using AWS KMS master keys, see
-- the
-- <https://docs.aws.amazon.com/AmazonS3/latest/dev/UsingClientSideEncryption.html Amazon S3 Developer Guide>.
s3Action_kmsKeyArn :: Lens.Lens' S3Action (Prelude.Maybe Prelude.Text)
s3Action_kmsKeyArn :: (Maybe Text -> f (Maybe Text)) -> S3Action -> f S3Action
s3Action_kmsKeyArn = (S3Action -> Maybe Text)
-> (S3Action -> Maybe Text -> S3Action)
-> Lens S3Action S3Action (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\S3Action' {Maybe Text
kmsKeyArn :: Maybe Text
$sel:kmsKeyArn:S3Action' :: S3Action -> Maybe Text
kmsKeyArn} -> Maybe Text
kmsKeyArn) (\s :: S3Action
s@S3Action' {} Maybe Text
a -> S3Action
s {$sel:kmsKeyArn:S3Action' :: Maybe Text
kmsKeyArn = Maybe Text
a} :: S3Action)

-- | The ARN of the Amazon SNS topic to notify when the message is saved to
-- the Amazon S3 bucket. An example of an Amazon SNS topic ARN is
-- @arn:aws:sns:us-west-2:123456789012:MyTopic@. For more information about
-- Amazon SNS topics, see the
-- <https://docs.aws.amazon.com/sns/latest/dg/CreateTopic.html Amazon SNS Developer Guide>.
s3Action_topicArn :: Lens.Lens' S3Action (Prelude.Maybe Prelude.Text)
s3Action_topicArn :: (Maybe Text -> f (Maybe Text)) -> S3Action -> f S3Action
s3Action_topicArn = (S3Action -> Maybe Text)
-> (S3Action -> Maybe Text -> S3Action)
-> Lens S3Action S3Action (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\S3Action' {Maybe Text
topicArn :: Maybe Text
$sel:topicArn:S3Action' :: S3Action -> Maybe Text
topicArn} -> Maybe Text
topicArn) (\s :: S3Action
s@S3Action' {} Maybe Text
a -> S3Action
s {$sel:topicArn:S3Action' :: Maybe Text
topicArn = Maybe Text
a} :: S3Action)

-- | The key prefix of the Amazon S3 bucket. The key prefix is similar to a
-- directory name that enables you to store similar data under the same
-- directory in a bucket.
s3Action_objectKeyPrefix :: Lens.Lens' S3Action (Prelude.Maybe Prelude.Text)
s3Action_objectKeyPrefix :: (Maybe Text -> f (Maybe Text)) -> S3Action -> f S3Action
s3Action_objectKeyPrefix = (S3Action -> Maybe Text)
-> (S3Action -> Maybe Text -> S3Action)
-> Lens S3Action S3Action (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\S3Action' {Maybe Text
objectKeyPrefix :: Maybe Text
$sel:objectKeyPrefix:S3Action' :: S3Action -> Maybe Text
objectKeyPrefix} -> Maybe Text
objectKeyPrefix) (\s :: S3Action
s@S3Action' {} Maybe Text
a -> S3Action
s {$sel:objectKeyPrefix:S3Action' :: Maybe Text
objectKeyPrefix = Maybe Text
a} :: S3Action)

-- | The name of the Amazon S3 bucket that incoming email will be saved to.
s3Action_bucketName :: Lens.Lens' S3Action Prelude.Text
s3Action_bucketName :: (Text -> f Text) -> S3Action -> f S3Action
s3Action_bucketName = (S3Action -> Text)
-> (S3Action -> Text -> S3Action)
-> Lens S3Action S3Action Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\S3Action' {Text
bucketName :: Text
$sel:bucketName:S3Action' :: S3Action -> Text
bucketName} -> Text
bucketName) (\s :: S3Action
s@S3Action' {} Text
a -> S3Action
s {$sel:bucketName:S3Action' :: Text
bucketName = Text
a} :: S3Action)

instance Core.FromXML S3Action where
  parseXML :: [Node] -> Either String S3Action
parseXML [Node]
x =
    Maybe Text -> Maybe Text -> Maybe Text -> Text -> S3Action
S3Action'
      (Maybe Text -> Maybe Text -> Maybe Text -> Text -> S3Action)
-> Either String (Maybe Text)
-> Either String (Maybe Text -> Maybe Text -> Text -> S3Action)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"KmsKeyArn")
      Either String (Maybe Text -> Maybe Text -> Text -> S3Action)
-> Either String (Maybe Text)
-> Either String (Maybe Text -> Text -> S3Action)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"TopicArn")
      Either String (Maybe Text -> Text -> S3Action)
-> Either String (Maybe Text) -> Either String (Text -> S3Action)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"ObjectKeyPrefix")
      Either String (Text -> S3Action)
-> Either String Text -> Either String S3Action
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
"BucketName")

instance Prelude.Hashable S3Action

instance Prelude.NFData S3Action

instance Core.ToQuery S3Action where
  toQuery :: S3Action -> QueryString
toQuery S3Action' {Maybe Text
Text
bucketName :: Text
objectKeyPrefix :: Maybe Text
topicArn :: Maybe Text
kmsKeyArn :: Maybe Text
$sel:bucketName:S3Action' :: S3Action -> Text
$sel:objectKeyPrefix:S3Action' :: S3Action -> Maybe Text
$sel:topicArn:S3Action' :: S3Action -> Maybe Text
$sel:kmsKeyArn:S3Action' :: S3Action -> Maybe Text
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"KmsKeyArn" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
kmsKeyArn,
        ByteString
"TopicArn" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
topicArn,
        ByteString
"ObjectKeyPrefix" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
objectKeyPrefix,
        ByteString
"BucketName" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
bucketName
      ]