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

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

-- | The group ID whose permissions are used to run a Lambda function.
functionRunAsConfig_gid :: Lens.Lens' FunctionRunAsConfig (Prelude.Maybe Prelude.Int)
functionRunAsConfig_gid :: Lens' FunctionRunAsConfig (Maybe Int)
functionRunAsConfig_gid = 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)

-- | The user ID whose permissions are used to run a Lambda function.
functionRunAsConfig_uid :: Lens.Lens' FunctionRunAsConfig (Prelude.Maybe Prelude.Int)
functionRunAsConfig_uid :: Lens' FunctionRunAsConfig (Maybe Int)
functionRunAsConfig_uid = 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)

instance Data.FromJSON FunctionRunAsConfig where
  parseJSON :: Value -> Parser FunctionRunAsConfig
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"FunctionRunAsConfig"
      ( \Object
x ->
          Maybe Int -> Maybe Int -> FunctionRunAsConfig
FunctionRunAsConfig'
            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
"Gid")
            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
"Uid")
      )

instance Prelude.Hashable FunctionRunAsConfig where
  hashWithSalt :: Int -> FunctionRunAsConfig -> Int
hashWithSalt Int
_salt FunctionRunAsConfig' {Maybe Int
uid :: Maybe Int
gid :: Maybe Int
$sel:uid:FunctionRunAsConfig' :: FunctionRunAsConfig -> Maybe Int
$sel:gid:FunctionRunAsConfig' :: FunctionRunAsConfig -> Maybe Int
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Int
gid
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Int
uid

instance Prelude.NFData FunctionRunAsConfig where
  rnf :: FunctionRunAsConfig -> ()
rnf FunctionRunAsConfig' {Maybe Int
uid :: Maybe Int
gid :: Maybe Int
$sel:uid:FunctionRunAsConfig' :: FunctionRunAsConfig -> Maybe Int
$sel:gid:FunctionRunAsConfig' :: FunctionRunAsConfig -> Maybe Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Int
gid seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Int
uid

instance Data.ToJSON FunctionRunAsConfig where
  toJSON :: FunctionRunAsConfig -> Value
toJSON FunctionRunAsConfig' {Maybe Int
uid :: Maybe Int
gid :: Maybe Int
$sel:uid:FunctionRunAsConfig' :: FunctionRunAsConfig -> Maybe Int
$sel:gid:FunctionRunAsConfig' :: FunctionRunAsConfig -> Maybe Int
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Gid" 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 Int
gid,
            (Key
"Uid" 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 Int
uid
          ]
      )