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

import qualified Amazonka.Core as Core
import Amazonka.IoT.Types.CannedAccessControlList
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Describes an action to write data to an Amazon S3 bucket.
--
-- /See:/ 'newS3Action' smart constructor.
data S3Action = S3Action'
  { -- | The Amazon S3 canned ACL that controls access to the object identified
    -- by the object key. For more information, see
    -- <https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl S3 canned ACLs>.
    S3Action -> Maybe CannedAccessControlList
cannedAcl :: Prelude.Maybe CannedAccessControlList,
    -- | The ARN of the IAM role that grants access.
    S3Action -> Text
roleArn :: Prelude.Text,
    -- | The Amazon S3 bucket.
    S3Action -> Text
bucketName :: Prelude.Text,
    -- | The object key. For more information, see
    -- <https://docs.aws.amazon.com/AmazonS3/latest/dev/list_amazons3.html Actions, resources, and condition keys for Amazon S3>.
    S3Action -> Text
key :: 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:
--
-- 'cannedAcl', 's3Action_cannedAcl' - The Amazon S3 canned ACL that controls access to the object identified
-- by the object key. For more information, see
-- <https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl S3 canned ACLs>.
--
-- 'roleArn', 's3Action_roleArn' - The ARN of the IAM role that grants access.
--
-- 'bucketName', 's3Action_bucketName' - The Amazon S3 bucket.
--
-- 'key', 's3Action_key' - The object key. For more information, see
-- <https://docs.aws.amazon.com/AmazonS3/latest/dev/list_amazons3.html Actions, resources, and condition keys for Amazon S3>.
newS3Action ::
  -- | 'roleArn'
  Prelude.Text ->
  -- | 'bucketName'
  Prelude.Text ->
  -- | 'key'
  Prelude.Text ->
  S3Action
newS3Action :: Text -> Text -> Text -> S3Action
newS3Action Text
pRoleArn_ Text
pBucketName_ Text
pKey_ =
  S3Action' :: Maybe CannedAccessControlList -> Text -> Text -> Text -> S3Action
S3Action'
    { $sel:cannedAcl:S3Action' :: Maybe CannedAccessControlList
cannedAcl = Maybe CannedAccessControlList
forall a. Maybe a
Prelude.Nothing,
      $sel:roleArn:S3Action' :: Text
roleArn = Text
pRoleArn_,
      $sel:bucketName:S3Action' :: Text
bucketName = Text
pBucketName_,
      $sel:key:S3Action' :: Text
key = Text
pKey_
    }

-- | The Amazon S3 canned ACL that controls access to the object identified
-- by the object key. For more information, see
-- <https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl S3 canned ACLs>.
s3Action_cannedAcl :: Lens.Lens' S3Action (Prelude.Maybe CannedAccessControlList)
s3Action_cannedAcl :: (Maybe CannedAccessControlList
 -> f (Maybe CannedAccessControlList))
-> S3Action -> f S3Action
s3Action_cannedAcl = (S3Action -> Maybe CannedAccessControlList)
-> (S3Action -> Maybe CannedAccessControlList -> S3Action)
-> Lens
     S3Action
     S3Action
     (Maybe CannedAccessControlList)
     (Maybe CannedAccessControlList)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\S3Action' {Maybe CannedAccessControlList
cannedAcl :: Maybe CannedAccessControlList
$sel:cannedAcl:S3Action' :: S3Action -> Maybe CannedAccessControlList
cannedAcl} -> Maybe CannedAccessControlList
cannedAcl) (\s :: S3Action
s@S3Action' {} Maybe CannedAccessControlList
a -> S3Action
s {$sel:cannedAcl:S3Action' :: Maybe CannedAccessControlList
cannedAcl = Maybe CannedAccessControlList
a} :: S3Action)

-- | The ARN of the IAM role that grants access.
s3Action_roleArn :: Lens.Lens' S3Action Prelude.Text
s3Action_roleArn :: (Text -> f Text) -> S3Action -> f S3Action
s3Action_roleArn = (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
roleArn :: Text
$sel:roleArn:S3Action' :: S3Action -> Text
roleArn} -> Text
roleArn) (\s :: S3Action
s@S3Action' {} Text
a -> S3Action
s {$sel:roleArn:S3Action' :: Text
roleArn = Text
a} :: S3Action)

-- | The Amazon S3 bucket.
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)

-- | The object key. For more information, see
-- <https://docs.aws.amazon.com/AmazonS3/latest/dev/list_amazons3.html Actions, resources, and condition keys for Amazon S3>.
s3Action_key :: Lens.Lens' S3Action Prelude.Text
s3Action_key :: (Text -> f Text) -> S3Action -> f S3Action
s3Action_key = (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
key :: Text
$sel:key:S3Action' :: S3Action -> Text
key} -> Text
key) (\s :: S3Action
s@S3Action' {} Text
a -> S3Action
s {$sel:key:S3Action' :: Text
key = Text
a} :: S3Action)

instance Core.FromJSON S3Action where
  parseJSON :: Value -> Parser S3Action
parseJSON =
    String -> (Object -> Parser S3Action) -> Value -> Parser S3Action
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"S3Action"
      ( \Object
x ->
          Maybe CannedAccessControlList -> Text -> Text -> Text -> S3Action
S3Action'
            (Maybe CannedAccessControlList -> Text -> Text -> Text -> S3Action)
-> Parser (Maybe CannedAccessControlList)
-> Parser (Text -> Text -> Text -> S3Action)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe CannedAccessControlList)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"cannedAcl")
            Parser (Text -> Text -> Text -> S3Action)
-> Parser Text -> Parser (Text -> Text -> S3Action)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"roleArn")
            Parser (Text -> Text -> S3Action)
-> Parser Text -> Parser (Text -> S3Action)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"bucketName")
            Parser (Text -> S3Action) -> Parser Text -> Parser S3Action
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"key")
      )

instance Prelude.Hashable S3Action

instance Prelude.NFData S3Action

instance Core.ToJSON S3Action where
  toJSON :: S3Action -> Value
toJSON S3Action' {Maybe CannedAccessControlList
Text
key :: Text
bucketName :: Text
roleArn :: Text
cannedAcl :: Maybe CannedAccessControlList
$sel:key:S3Action' :: S3Action -> Text
$sel:bucketName:S3Action' :: S3Action -> Text
$sel:roleArn:S3Action' :: S3Action -> Text
$sel:cannedAcl:S3Action' :: S3Action -> Maybe CannedAccessControlList
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"cannedAcl" Text -> CannedAccessControlList -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (CannedAccessControlList -> Pair)
-> Maybe CannedAccessControlList -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe CannedAccessControlList
cannedAcl,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"roleArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
roleArn),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"bucketName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
bucketName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"key" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
key)
          ]
      )