{-# 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-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.PresignedUrlConfig where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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.
    PresignedUrlConfig -> Maybe Text
roleArn :: Prelude.Maybe Prelude.Text
  }
  deriving (PresignedUrlConfig -> PresignedUrlConfig -> Bool
(PresignedUrlConfig -> PresignedUrlConfig -> Bool)
-> (PresignedUrlConfig -> PresignedUrlConfig -> Bool)
-> Eq PresignedUrlConfig
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]
(Int -> ReadS PresignedUrlConfig)
-> ReadS [PresignedUrlConfig]
-> ReadPrec PresignedUrlConfig
-> ReadPrec [PresignedUrlConfig]
-> Read 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
(Int -> PresignedUrlConfig -> ShowS)
-> (PresignedUrlConfig -> String)
-> ([PresignedUrlConfig] -> ShowS)
-> Show PresignedUrlConfig
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. PresignedUrlConfig -> Rep PresignedUrlConfig x)
-> (forall x. Rep PresignedUrlConfig x -> PresignedUrlConfig)
-> Generic PresignedUrlConfig
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.
newPresignedUrlConfig ::
  PresignedUrlConfig
newPresignedUrlConfig :: PresignedUrlConfig
newPresignedUrlConfig =
  PresignedUrlConfig' :: Maybe Natural -> Maybe Text -> PresignedUrlConfig
PresignedUrlConfig'
    { $sel:expiresInSec:PresignedUrlConfig' :: Maybe Natural
expiresInSec = Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:roleArn:PresignedUrlConfig' :: Maybe Text
roleArn = Maybe Text
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 :: (Maybe Natural -> f (Maybe Natural))
-> PresignedUrlConfig -> f PresignedUrlConfig
presignedUrlConfig_expiresInSec = (PresignedUrlConfig -> Maybe Natural)
-> (PresignedUrlConfig -> Maybe Natural -> PresignedUrlConfig)
-> Lens
     PresignedUrlConfig
     PresignedUrlConfig
     (Maybe Natural)
     (Maybe Natural)
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.
presignedUrlConfig_roleArn :: Lens.Lens' PresignedUrlConfig (Prelude.Maybe Prelude.Text)
presignedUrlConfig_roleArn :: (Maybe Text -> f (Maybe Text))
-> PresignedUrlConfig -> f PresignedUrlConfig
presignedUrlConfig_roleArn = (PresignedUrlConfig -> Maybe Text)
-> (PresignedUrlConfig -> Maybe Text -> PresignedUrlConfig)
-> Lens
     PresignedUrlConfig PresignedUrlConfig (Maybe Text) (Maybe Text)
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 Core.FromJSON PresignedUrlConfig where
  parseJSON :: Value -> Parser PresignedUrlConfig
parseJSON =
    String
-> (Object -> Parser PresignedUrlConfig)
-> Value
-> Parser PresignedUrlConfig
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"PresignedUrlConfig"
      ( \Object
x ->
          Maybe Natural -> Maybe Text -> PresignedUrlConfig
PresignedUrlConfig'
            (Maybe Natural -> Maybe Text -> PresignedUrlConfig)
-> Parser (Maybe Natural)
-> Parser (Maybe Text -> PresignedUrlConfig)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Natural)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"expiresInSec")
            Parser (Maybe Text -> PresignedUrlConfig)
-> Parser (Maybe Text) -> Parser PresignedUrlConfig
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"roleArn")
      )

instance Prelude.Hashable PresignedUrlConfig

instance Prelude.NFData PresignedUrlConfig

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"expiresInSec" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Natural -> Pair) -> Maybe Natural -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
expiresInSec,
            (Text
"roleArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
roleArn
          ]
      )