{-# 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.PresignedUrlConfig
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.IoT.Types.PresignedUrlConfig where

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

-- | Configuration for pre-signed S3 URLs.
--
-- /See:/ 'newPresignedUrlConfig' smart constructor.
data PresignedUrlConfig = PresignedUrlConfig'
  { -- | How long (in seconds) pre-signed URLs are valid. Valid values are 60 -
    -- 3600, the default value is 3600 seconds. Pre-signed URLs are generated
    -- when Jobs receives an MQTT request for the job document.
    PresignedUrlConfig -> Maybe Natural
expiresInSec :: Prelude.Maybe Prelude.Natural,
    -- | The ARN of an IAM role that grants grants permission to download files
    -- from the S3 bucket where the job data\/updates are stored. The role must
    -- also grant permission for IoT to download the files.
    --
    -- For information about addressing the confused deputy problem, see
    -- <https://docs.aws.amazon.com/iot/latest/developerguide/cross-service-confused-deputy-prevention.html cross-service confused deputy prevention>
    -- in the /Amazon Web Services IoT Core developer guide/.
    PresignedUrlConfig -> Maybe Text
roleArn :: Prelude.Maybe Prelude.Text
  }
  deriving (PresignedUrlConfig -> PresignedUrlConfig -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PresignedUrlConfig -> PresignedUrlConfig -> Bool
$c/= :: PresignedUrlConfig -> PresignedUrlConfig -> Bool
== :: PresignedUrlConfig -> PresignedUrlConfig -> Bool
$c== :: PresignedUrlConfig -> PresignedUrlConfig -> Bool
Prelude.Eq, ReadPrec [PresignedUrlConfig]
ReadPrec PresignedUrlConfig
Int -> ReadS PresignedUrlConfig
ReadS [PresignedUrlConfig]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PresignedUrlConfig]
$creadListPrec :: ReadPrec [PresignedUrlConfig]
readPrec :: ReadPrec PresignedUrlConfig
$creadPrec :: ReadPrec PresignedUrlConfig
readList :: ReadS [PresignedUrlConfig]
$creadList :: ReadS [PresignedUrlConfig]
readsPrec :: Int -> ReadS PresignedUrlConfig
$creadsPrec :: Int -> ReadS PresignedUrlConfig
Prelude.Read, Int -> PresignedUrlConfig -> ShowS
[PresignedUrlConfig] -> ShowS
PresignedUrlConfig -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PresignedUrlConfig] -> ShowS
$cshowList :: [PresignedUrlConfig] -> ShowS
show :: PresignedUrlConfig -> String
$cshow :: PresignedUrlConfig -> String
showsPrec :: Int -> PresignedUrlConfig -> ShowS
$cshowsPrec :: Int -> PresignedUrlConfig -> ShowS
Prelude.Show, forall x. Rep PresignedUrlConfig x -> PresignedUrlConfig
forall x. PresignedUrlConfig -> Rep PresignedUrlConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PresignedUrlConfig x -> PresignedUrlConfig
$cfrom :: forall x. PresignedUrlConfig -> Rep PresignedUrlConfig x
Prelude.Generic)

-- |
-- Create a value of 'PresignedUrlConfig' 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:
--
-- 'expiresInSec', 'presignedUrlConfig_expiresInSec' - How long (in seconds) pre-signed URLs are valid. Valid values are 60 -
-- 3600, the default value is 3600 seconds. Pre-signed URLs are generated
-- when Jobs receives an MQTT request for the job document.
--
-- 'roleArn', 'presignedUrlConfig_roleArn' - The ARN of an IAM role that grants grants permission to download files
-- from the S3 bucket where the job data\/updates are stored. The role must
-- also grant permission for IoT to download the files.
--
-- For information about addressing the confused deputy problem, see
-- <https://docs.aws.amazon.com/iot/latest/developerguide/cross-service-confused-deputy-prevention.html cross-service confused deputy prevention>
-- in the /Amazon Web Services IoT Core developer guide/.
newPresignedUrlConfig ::
  PresignedUrlConfig
newPresignedUrlConfig :: PresignedUrlConfig
newPresignedUrlConfig =
  PresignedUrlConfig'
    { $sel:expiresInSec:PresignedUrlConfig' :: Maybe Natural
expiresInSec = forall a. Maybe a
Prelude.Nothing,
      $sel:roleArn:PresignedUrlConfig' :: Maybe Text
roleArn = forall a. Maybe a
Prelude.Nothing
    }

-- | How long (in seconds) pre-signed URLs are valid. Valid values are 60 -
-- 3600, the default value is 3600 seconds. Pre-signed URLs are generated
-- when Jobs receives an MQTT request for the job document.
presignedUrlConfig_expiresInSec :: Lens.Lens' PresignedUrlConfig (Prelude.Maybe Prelude.Natural)
presignedUrlConfig_expiresInSec :: Lens' PresignedUrlConfig (Maybe Natural)
presignedUrlConfig_expiresInSec = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PresignedUrlConfig' {Maybe Natural
expiresInSec :: Maybe Natural
$sel:expiresInSec:PresignedUrlConfig' :: PresignedUrlConfig -> Maybe Natural
expiresInSec} -> Maybe Natural
expiresInSec) (\s :: PresignedUrlConfig
s@PresignedUrlConfig' {} Maybe Natural
a -> PresignedUrlConfig
s {$sel:expiresInSec:PresignedUrlConfig' :: Maybe Natural
expiresInSec = Maybe Natural
a} :: PresignedUrlConfig)

-- | The ARN of an IAM role that grants grants permission to download files
-- from the S3 bucket where the job data\/updates are stored. The role must
-- also grant permission for IoT to download the files.
--
-- For information about addressing the confused deputy problem, see
-- <https://docs.aws.amazon.com/iot/latest/developerguide/cross-service-confused-deputy-prevention.html cross-service confused deputy prevention>
-- in the /Amazon Web Services IoT Core developer guide/.
presignedUrlConfig_roleArn :: Lens.Lens' PresignedUrlConfig (Prelude.Maybe Prelude.Text)
presignedUrlConfig_roleArn :: Lens' PresignedUrlConfig (Maybe Text)
presignedUrlConfig_roleArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PresignedUrlConfig' {Maybe Text
roleArn :: Maybe Text
$sel:roleArn:PresignedUrlConfig' :: PresignedUrlConfig -> Maybe Text
roleArn} -> Maybe Text
roleArn) (\s :: PresignedUrlConfig
s@PresignedUrlConfig' {} Maybe Text
a -> PresignedUrlConfig
s {$sel:roleArn:PresignedUrlConfig' :: Maybe Text
roleArn = Maybe Text
a} :: PresignedUrlConfig)

instance Data.FromJSON PresignedUrlConfig where
  parseJSON :: Value -> Parser PresignedUrlConfig
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"PresignedUrlConfig"
      ( \Object
x ->
          Maybe Natural -> Maybe Text -> PresignedUrlConfig
PresignedUrlConfig'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"expiresInSec")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"roleArn")
      )

instance Prelude.Hashable PresignedUrlConfig where
  hashWithSalt :: Int -> PresignedUrlConfig -> Int
hashWithSalt Int
_salt PresignedUrlConfig' {Maybe Natural
Maybe Text
roleArn :: Maybe Text
expiresInSec :: Maybe Natural
$sel:roleArn:PresignedUrlConfig' :: PresignedUrlConfig -> Maybe Text
$sel:expiresInSec:PresignedUrlConfig' :: PresignedUrlConfig -> Maybe Natural
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
expiresInSec
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
roleArn

instance Prelude.NFData PresignedUrlConfig where
  rnf :: PresignedUrlConfig -> ()
rnf PresignedUrlConfig' {Maybe Natural
Maybe Text
roleArn :: Maybe Text
expiresInSec :: Maybe Natural
$sel:roleArn:PresignedUrlConfig' :: PresignedUrlConfig -> Maybe Text
$sel:expiresInSec:PresignedUrlConfig' :: PresignedUrlConfig -> Maybe Natural
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
expiresInSec
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
roleArn

instance Data.ToJSON PresignedUrlConfig where
  toJSON :: PresignedUrlConfig -> Value
toJSON PresignedUrlConfig' {Maybe Natural
Maybe Text
roleArn :: Maybe Text
expiresInSec :: Maybe Natural
$sel:roleArn:PresignedUrlConfig' :: PresignedUrlConfig -> Maybe Text
$sel:expiresInSec:PresignedUrlConfig' :: PresignedUrlConfig -> Maybe Natural
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"expiresInSec" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
expiresInSec,
            (Key
"roleArn" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
roleArn
          ]
      )