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

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

-- | Specifies the user and group whose permissions are used when running the
-- Lambda function. You can specify one or both values to override the
-- default values. We recommend that you avoid running as root unless
-- absolutely necessary to minimize the risk of unintended changes or
-- malicious attacks. To run as root, you must set \'\'IsolationMode\'\' to
-- \'\'NoContainer\'\' and update config.json in
-- \'\'greengrass-root\/config\'\' to set \'\'allowFunctionsToRunAsRoot\'\'
-- to \'\'yes\'\'.
--
-- /See:/ 'newFunctionRunAsConfig' smart constructor.
data FunctionRunAsConfig = FunctionRunAsConfig'
  { -- | The user ID whose permissions are used to run a Lambda function.
    FunctionRunAsConfig -> Maybe Int
uid :: Prelude.Maybe Prelude.Int,
    -- | The group ID whose permissions are used to run a Lambda function.
    FunctionRunAsConfig -> Maybe Int
gid :: Prelude.Maybe Prelude.Int
  }
  deriving (FunctionRunAsConfig -> FunctionRunAsConfig -> Bool
(FunctionRunAsConfig -> FunctionRunAsConfig -> Bool)
-> (FunctionRunAsConfig -> FunctionRunAsConfig -> Bool)
-> Eq FunctionRunAsConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FunctionRunAsConfig -> FunctionRunAsConfig -> Bool
$c/= :: FunctionRunAsConfig -> FunctionRunAsConfig -> Bool
== :: FunctionRunAsConfig -> FunctionRunAsConfig -> Bool
$c== :: FunctionRunAsConfig -> FunctionRunAsConfig -> Bool
Prelude.Eq, ReadPrec [FunctionRunAsConfig]
ReadPrec FunctionRunAsConfig
Int -> ReadS FunctionRunAsConfig
ReadS [FunctionRunAsConfig]
(Int -> ReadS FunctionRunAsConfig)
-> ReadS [FunctionRunAsConfig]
-> ReadPrec FunctionRunAsConfig
-> ReadPrec [FunctionRunAsConfig]
-> Read FunctionRunAsConfig
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [FunctionRunAsConfig]
$creadListPrec :: ReadPrec [FunctionRunAsConfig]
readPrec :: ReadPrec FunctionRunAsConfig
$creadPrec :: ReadPrec FunctionRunAsConfig
readList :: ReadS [FunctionRunAsConfig]
$creadList :: ReadS [FunctionRunAsConfig]
readsPrec :: Int -> ReadS FunctionRunAsConfig
$creadsPrec :: Int -> ReadS FunctionRunAsConfig
Prelude.Read, Int -> FunctionRunAsConfig -> ShowS
[FunctionRunAsConfig] -> ShowS
FunctionRunAsConfig -> String
(Int -> FunctionRunAsConfig -> ShowS)
-> (FunctionRunAsConfig -> String)
-> ([FunctionRunAsConfig] -> ShowS)
-> Show FunctionRunAsConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FunctionRunAsConfig] -> ShowS
$cshowList :: [FunctionRunAsConfig] -> ShowS
show :: FunctionRunAsConfig -> String
$cshow :: FunctionRunAsConfig -> String
showsPrec :: Int -> FunctionRunAsConfig -> ShowS
$cshowsPrec :: Int -> FunctionRunAsConfig -> ShowS
Prelude.Show, (forall x. FunctionRunAsConfig -> Rep FunctionRunAsConfig x)
-> (forall x. Rep FunctionRunAsConfig x -> FunctionRunAsConfig)
-> Generic FunctionRunAsConfig
forall x. Rep FunctionRunAsConfig x -> FunctionRunAsConfig
forall x. FunctionRunAsConfig -> Rep FunctionRunAsConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FunctionRunAsConfig x -> FunctionRunAsConfig
$cfrom :: forall x. FunctionRunAsConfig -> Rep FunctionRunAsConfig x
Prelude.Generic)

-- |
-- Create a value of 'FunctionRunAsConfig' 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:
--
-- 'uid', 'functionRunAsConfig_uid' - The user ID whose permissions are used to run a Lambda function.
--
-- 'gid', 'functionRunAsConfig_gid' - The group ID whose permissions are used to run a Lambda function.
newFunctionRunAsConfig ::
  FunctionRunAsConfig
newFunctionRunAsConfig :: FunctionRunAsConfig
newFunctionRunAsConfig =
  FunctionRunAsConfig' :: Maybe Int -> Maybe Int -> FunctionRunAsConfig
FunctionRunAsConfig'
    { $sel:uid:FunctionRunAsConfig' :: Maybe Int
uid = Maybe Int
forall a. Maybe a
Prelude.Nothing,
      $sel:gid:FunctionRunAsConfig' :: Maybe Int
gid = Maybe Int
forall a. Maybe a
Prelude.Nothing
    }

-- | The user ID whose permissions are used to run a Lambda function.
functionRunAsConfig_uid :: Lens.Lens' FunctionRunAsConfig (Prelude.Maybe Prelude.Int)
functionRunAsConfig_uid :: (Maybe Int -> f (Maybe Int))
-> FunctionRunAsConfig -> f FunctionRunAsConfig
functionRunAsConfig_uid = (FunctionRunAsConfig -> Maybe Int)
-> (FunctionRunAsConfig -> Maybe Int -> FunctionRunAsConfig)
-> Lens
     FunctionRunAsConfig FunctionRunAsConfig (Maybe Int) (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FunctionRunAsConfig' {Maybe Int
uid :: Maybe Int
$sel:uid:FunctionRunAsConfig' :: FunctionRunAsConfig -> Maybe Int
uid} -> Maybe Int
uid) (\s :: FunctionRunAsConfig
s@FunctionRunAsConfig' {} Maybe Int
a -> FunctionRunAsConfig
s {$sel:uid:FunctionRunAsConfig' :: Maybe Int
uid = Maybe Int
a} :: FunctionRunAsConfig)

-- | The group ID whose permissions are used to run a Lambda function.
functionRunAsConfig_gid :: Lens.Lens' FunctionRunAsConfig (Prelude.Maybe Prelude.Int)
functionRunAsConfig_gid :: (Maybe Int -> f (Maybe Int))
-> FunctionRunAsConfig -> f FunctionRunAsConfig
functionRunAsConfig_gid = (FunctionRunAsConfig -> Maybe Int)
-> (FunctionRunAsConfig -> Maybe Int -> FunctionRunAsConfig)
-> Lens
     FunctionRunAsConfig FunctionRunAsConfig (Maybe Int) (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FunctionRunAsConfig' {Maybe Int
gid :: Maybe Int
$sel:gid:FunctionRunAsConfig' :: FunctionRunAsConfig -> Maybe Int
gid} -> Maybe Int
gid) (\s :: FunctionRunAsConfig
s@FunctionRunAsConfig' {} Maybe Int
a -> FunctionRunAsConfig
s {$sel:gid:FunctionRunAsConfig' :: Maybe Int
gid = Maybe Int
a} :: FunctionRunAsConfig)

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

instance Prelude.Hashable FunctionRunAsConfig

instance Prelude.NFData FunctionRunAsConfig

instance Core.ToJSON FunctionRunAsConfig where
  toJSON :: FunctionRunAsConfig -> Value
toJSON FunctionRunAsConfig' {Maybe Int
gid :: Maybe Int
uid :: Maybe Int
$sel:gid:FunctionRunAsConfig' :: FunctionRunAsConfig -> Maybe Int
$sel:uid:FunctionRunAsConfig' :: FunctionRunAsConfig -> Maybe Int
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Uid" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Int -> Pair) -> Maybe Int -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Int
uid,
            (Text
"Gid" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Int -> Pair) -> Maybe Int -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Int
gid
          ]
      )