{-# 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.Greengrass.Types.FunctionExecutionConfig
-- 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.Greengrass.Types.FunctionExecutionConfig where

import qualified Amazonka.Core as Core
import Amazonka.Greengrass.Types.FunctionIsolationMode
import Amazonka.Greengrass.Types.FunctionRunAsConfig
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Configuration information that specifies how a Lambda function runs.
--
-- /See:/ 'newFunctionExecutionConfig' smart constructor.
data FunctionExecutionConfig = FunctionExecutionConfig'
  { FunctionExecutionConfig -> Maybe FunctionRunAsConfig
runAs :: Prelude.Maybe FunctionRunAsConfig,
    FunctionExecutionConfig -> Maybe FunctionIsolationMode
isolationMode :: Prelude.Maybe FunctionIsolationMode
  }
  deriving (FunctionExecutionConfig -> FunctionExecutionConfig -> Bool
(FunctionExecutionConfig -> FunctionExecutionConfig -> Bool)
-> (FunctionExecutionConfig -> FunctionExecutionConfig -> Bool)
-> Eq FunctionExecutionConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FunctionExecutionConfig -> FunctionExecutionConfig -> Bool
$c/= :: FunctionExecutionConfig -> FunctionExecutionConfig -> Bool
== :: FunctionExecutionConfig -> FunctionExecutionConfig -> Bool
$c== :: FunctionExecutionConfig -> FunctionExecutionConfig -> Bool
Prelude.Eq, ReadPrec [FunctionExecutionConfig]
ReadPrec FunctionExecutionConfig
Int -> ReadS FunctionExecutionConfig
ReadS [FunctionExecutionConfig]
(Int -> ReadS FunctionExecutionConfig)
-> ReadS [FunctionExecutionConfig]
-> ReadPrec FunctionExecutionConfig
-> ReadPrec [FunctionExecutionConfig]
-> Read FunctionExecutionConfig
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [FunctionExecutionConfig]
$creadListPrec :: ReadPrec [FunctionExecutionConfig]
readPrec :: ReadPrec FunctionExecutionConfig
$creadPrec :: ReadPrec FunctionExecutionConfig
readList :: ReadS [FunctionExecutionConfig]
$creadList :: ReadS [FunctionExecutionConfig]
readsPrec :: Int -> ReadS FunctionExecutionConfig
$creadsPrec :: Int -> ReadS FunctionExecutionConfig
Prelude.Read, Int -> FunctionExecutionConfig -> ShowS
[FunctionExecutionConfig] -> ShowS
FunctionExecutionConfig -> String
(Int -> FunctionExecutionConfig -> ShowS)
-> (FunctionExecutionConfig -> String)
-> ([FunctionExecutionConfig] -> ShowS)
-> Show FunctionExecutionConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FunctionExecutionConfig] -> ShowS
$cshowList :: [FunctionExecutionConfig] -> ShowS
show :: FunctionExecutionConfig -> String
$cshow :: FunctionExecutionConfig -> String
showsPrec :: Int -> FunctionExecutionConfig -> ShowS
$cshowsPrec :: Int -> FunctionExecutionConfig -> ShowS
Prelude.Show, (forall x.
 FunctionExecutionConfig -> Rep FunctionExecutionConfig x)
-> (forall x.
    Rep FunctionExecutionConfig x -> FunctionExecutionConfig)
-> Generic FunctionExecutionConfig
forall x. Rep FunctionExecutionConfig x -> FunctionExecutionConfig
forall x. FunctionExecutionConfig -> Rep FunctionExecutionConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FunctionExecutionConfig x -> FunctionExecutionConfig
$cfrom :: forall x. FunctionExecutionConfig -> Rep FunctionExecutionConfig x
Prelude.Generic)

-- |
-- Create a value of 'FunctionExecutionConfig' 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:
--
-- 'runAs', 'functionExecutionConfig_runAs' - Undocumented member.
--
-- 'isolationMode', 'functionExecutionConfig_isolationMode' - Undocumented member.
newFunctionExecutionConfig ::
  FunctionExecutionConfig
newFunctionExecutionConfig :: FunctionExecutionConfig
newFunctionExecutionConfig =
  FunctionExecutionConfig' :: Maybe FunctionRunAsConfig
-> Maybe FunctionIsolationMode -> FunctionExecutionConfig
FunctionExecutionConfig'
    { $sel:runAs:FunctionExecutionConfig' :: Maybe FunctionRunAsConfig
runAs = Maybe FunctionRunAsConfig
forall a. Maybe a
Prelude.Nothing,
      $sel:isolationMode:FunctionExecutionConfig' :: Maybe FunctionIsolationMode
isolationMode = Maybe FunctionIsolationMode
forall a. Maybe a
Prelude.Nothing
    }

-- | Undocumented member.
functionExecutionConfig_runAs :: Lens.Lens' FunctionExecutionConfig (Prelude.Maybe FunctionRunAsConfig)
functionExecutionConfig_runAs :: (Maybe FunctionRunAsConfig -> f (Maybe FunctionRunAsConfig))
-> FunctionExecutionConfig -> f FunctionExecutionConfig
functionExecutionConfig_runAs = (FunctionExecutionConfig -> Maybe FunctionRunAsConfig)
-> (FunctionExecutionConfig
    -> Maybe FunctionRunAsConfig -> FunctionExecutionConfig)
-> Lens
     FunctionExecutionConfig
     FunctionExecutionConfig
     (Maybe FunctionRunAsConfig)
     (Maybe FunctionRunAsConfig)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FunctionExecutionConfig' {Maybe FunctionRunAsConfig
runAs :: Maybe FunctionRunAsConfig
$sel:runAs:FunctionExecutionConfig' :: FunctionExecutionConfig -> Maybe FunctionRunAsConfig
runAs} -> Maybe FunctionRunAsConfig
runAs) (\s :: FunctionExecutionConfig
s@FunctionExecutionConfig' {} Maybe FunctionRunAsConfig
a -> FunctionExecutionConfig
s {$sel:runAs:FunctionExecutionConfig' :: Maybe FunctionRunAsConfig
runAs = Maybe FunctionRunAsConfig
a} :: FunctionExecutionConfig)

-- | Undocumented member.
functionExecutionConfig_isolationMode :: Lens.Lens' FunctionExecutionConfig (Prelude.Maybe FunctionIsolationMode)
functionExecutionConfig_isolationMode :: (Maybe FunctionIsolationMode -> f (Maybe FunctionIsolationMode))
-> FunctionExecutionConfig -> f FunctionExecutionConfig
functionExecutionConfig_isolationMode = (FunctionExecutionConfig -> Maybe FunctionIsolationMode)
-> (FunctionExecutionConfig
    -> Maybe FunctionIsolationMode -> FunctionExecutionConfig)
-> Lens
     FunctionExecutionConfig
     FunctionExecutionConfig
     (Maybe FunctionIsolationMode)
     (Maybe FunctionIsolationMode)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FunctionExecutionConfig' {Maybe FunctionIsolationMode
isolationMode :: Maybe FunctionIsolationMode
$sel:isolationMode:FunctionExecutionConfig' :: FunctionExecutionConfig -> Maybe FunctionIsolationMode
isolationMode} -> Maybe FunctionIsolationMode
isolationMode) (\s :: FunctionExecutionConfig
s@FunctionExecutionConfig' {} Maybe FunctionIsolationMode
a -> FunctionExecutionConfig
s {$sel:isolationMode:FunctionExecutionConfig' :: Maybe FunctionIsolationMode
isolationMode = Maybe FunctionIsolationMode
a} :: FunctionExecutionConfig)

instance Core.FromJSON FunctionExecutionConfig where
  parseJSON :: Value -> Parser FunctionExecutionConfig
parseJSON =
    String
-> (Object -> Parser FunctionExecutionConfig)
-> Value
-> Parser FunctionExecutionConfig
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"FunctionExecutionConfig"
      ( \Object
x ->
          Maybe FunctionRunAsConfig
-> Maybe FunctionIsolationMode -> FunctionExecutionConfig
FunctionExecutionConfig'
            (Maybe FunctionRunAsConfig
 -> Maybe FunctionIsolationMode -> FunctionExecutionConfig)
-> Parser (Maybe FunctionRunAsConfig)
-> Parser (Maybe FunctionIsolationMode -> FunctionExecutionConfig)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe FunctionRunAsConfig)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"RunAs")
            Parser (Maybe FunctionIsolationMode -> FunctionExecutionConfig)
-> Parser (Maybe FunctionIsolationMode)
-> Parser FunctionExecutionConfig
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe FunctionIsolationMode)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"IsolationMode")
      )

instance Prelude.Hashable FunctionExecutionConfig

instance Prelude.NFData FunctionExecutionConfig

instance Core.ToJSON FunctionExecutionConfig where
  toJSON :: FunctionExecutionConfig -> Value
toJSON FunctionExecutionConfig' {Maybe FunctionIsolationMode
Maybe FunctionRunAsConfig
isolationMode :: Maybe FunctionIsolationMode
runAs :: Maybe FunctionRunAsConfig
$sel:isolationMode:FunctionExecutionConfig' :: FunctionExecutionConfig -> Maybe FunctionIsolationMode
$sel:runAs:FunctionExecutionConfig' :: FunctionExecutionConfig -> Maybe FunctionRunAsConfig
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"RunAs" Text -> FunctionRunAsConfig -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (FunctionRunAsConfig -> Pair)
-> Maybe FunctionRunAsConfig -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe FunctionRunAsConfig
runAs,
            (Text
"IsolationMode" Text -> FunctionIsolationMode -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (FunctionIsolationMode -> Pair)
-> Maybe FunctionIsolationMode -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe FunctionIsolationMode
isolationMode
          ]
      )