{-# 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.EFS.Types.CreationInfo
-- 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.EFS.Types.CreationInfo 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

-- | Required if the @RootDirectory@ > @Path@ specified does not exist.
-- Specifies the POSIX IDs and permissions to apply to the access point\'s
-- @RootDirectory@ > @Path@. If the access point root directory does not
-- exist, EFS creates it with these settings when a client connects to the
-- access point. When specifying @CreationInfo@, you must include values
-- for all properties.
--
-- Amazon EFS creates a root directory only if you have provided the
-- CreationInfo: OwnUid, OwnGID, and permissions for the directory. If you
-- do not provide this information, Amazon EFS does not create the root
-- directory. If the root directory does not exist, attempts to mount using
-- the access point will fail.
--
-- If you do not provide @CreationInfo@ and the specified @RootDirectory@
-- does not exist, attempts to mount the file system using the access point
-- will fail.
--
-- /See:/ 'newCreationInfo' smart constructor.
data CreationInfo = CreationInfo'
  { -- | Specifies the POSIX user ID to apply to the @RootDirectory@. Accepts
    -- values from 0 to 2^32 (4294967295).
    CreationInfo -> Natural
ownerUid :: Prelude.Natural,
    -- | Specifies the POSIX group ID to apply to the @RootDirectory@. Accepts
    -- values from 0 to 2^32 (4294967295).
    CreationInfo -> Natural
ownerGid :: Prelude.Natural,
    -- | Specifies the POSIX permissions to apply to the @RootDirectory@, in the
    -- format of an octal number representing the file\'s mode bits.
    CreationInfo -> Text
permissions :: Prelude.Text
  }
  deriving (CreationInfo -> CreationInfo -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreationInfo -> CreationInfo -> Bool
$c/= :: CreationInfo -> CreationInfo -> Bool
== :: CreationInfo -> CreationInfo -> Bool
$c== :: CreationInfo -> CreationInfo -> Bool
Prelude.Eq, ReadPrec [CreationInfo]
ReadPrec CreationInfo
Int -> ReadS CreationInfo
ReadS [CreationInfo]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreationInfo]
$creadListPrec :: ReadPrec [CreationInfo]
readPrec :: ReadPrec CreationInfo
$creadPrec :: ReadPrec CreationInfo
readList :: ReadS [CreationInfo]
$creadList :: ReadS [CreationInfo]
readsPrec :: Int -> ReadS CreationInfo
$creadsPrec :: Int -> ReadS CreationInfo
Prelude.Read, Int -> CreationInfo -> ShowS
[CreationInfo] -> ShowS
CreationInfo -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreationInfo] -> ShowS
$cshowList :: [CreationInfo] -> ShowS
show :: CreationInfo -> String
$cshow :: CreationInfo -> String
showsPrec :: Int -> CreationInfo -> ShowS
$cshowsPrec :: Int -> CreationInfo -> ShowS
Prelude.Show, forall x. Rep CreationInfo x -> CreationInfo
forall x. CreationInfo -> Rep CreationInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreationInfo x -> CreationInfo
$cfrom :: forall x. CreationInfo -> Rep CreationInfo x
Prelude.Generic)

-- |
-- Create a value of 'CreationInfo' 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:
--
-- 'ownerUid', 'creationInfo_ownerUid' - Specifies the POSIX user ID to apply to the @RootDirectory@. Accepts
-- values from 0 to 2^32 (4294967295).
--
-- 'ownerGid', 'creationInfo_ownerGid' - Specifies the POSIX group ID to apply to the @RootDirectory@. Accepts
-- values from 0 to 2^32 (4294967295).
--
-- 'permissions', 'creationInfo_permissions' - Specifies the POSIX permissions to apply to the @RootDirectory@, in the
-- format of an octal number representing the file\'s mode bits.
newCreationInfo ::
  -- | 'ownerUid'
  Prelude.Natural ->
  -- | 'ownerGid'
  Prelude.Natural ->
  -- | 'permissions'
  Prelude.Text ->
  CreationInfo
newCreationInfo :: Natural -> Natural -> Text -> CreationInfo
newCreationInfo Natural
pOwnerUid_ Natural
pOwnerGid_ Text
pPermissions_ =
  CreationInfo'
    { $sel:ownerUid:CreationInfo' :: Natural
ownerUid = Natural
pOwnerUid_,
      $sel:ownerGid:CreationInfo' :: Natural
ownerGid = Natural
pOwnerGid_,
      $sel:permissions:CreationInfo' :: Text
permissions = Text
pPermissions_
    }

-- | Specifies the POSIX user ID to apply to the @RootDirectory@. Accepts
-- values from 0 to 2^32 (4294967295).
creationInfo_ownerUid :: Lens.Lens' CreationInfo Prelude.Natural
creationInfo_ownerUid :: Lens' CreationInfo Natural
creationInfo_ownerUid = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreationInfo' {Natural
ownerUid :: Natural
$sel:ownerUid:CreationInfo' :: CreationInfo -> Natural
ownerUid} -> Natural
ownerUid) (\s :: CreationInfo
s@CreationInfo' {} Natural
a -> CreationInfo
s {$sel:ownerUid:CreationInfo' :: Natural
ownerUid = Natural
a} :: CreationInfo)

-- | Specifies the POSIX group ID to apply to the @RootDirectory@. Accepts
-- values from 0 to 2^32 (4294967295).
creationInfo_ownerGid :: Lens.Lens' CreationInfo Prelude.Natural
creationInfo_ownerGid :: Lens' CreationInfo Natural
creationInfo_ownerGid = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreationInfo' {Natural
ownerGid :: Natural
$sel:ownerGid:CreationInfo' :: CreationInfo -> Natural
ownerGid} -> Natural
ownerGid) (\s :: CreationInfo
s@CreationInfo' {} Natural
a -> CreationInfo
s {$sel:ownerGid:CreationInfo' :: Natural
ownerGid = Natural
a} :: CreationInfo)

-- | Specifies the POSIX permissions to apply to the @RootDirectory@, in the
-- format of an octal number representing the file\'s mode bits.
creationInfo_permissions :: Lens.Lens' CreationInfo Prelude.Text
creationInfo_permissions :: Lens' CreationInfo Text
creationInfo_permissions = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreationInfo' {Text
permissions :: Text
$sel:permissions:CreationInfo' :: CreationInfo -> Text
permissions} -> Text
permissions) (\s :: CreationInfo
s@CreationInfo' {} Text
a -> CreationInfo
s {$sel:permissions:CreationInfo' :: Text
permissions = Text
a} :: CreationInfo)

instance Data.FromJSON CreationInfo where
  parseJSON :: Value -> Parser CreationInfo
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"CreationInfo"
      ( \Object
x ->
          Natural -> Natural -> Text -> CreationInfo
CreationInfo'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"OwnerUid")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"OwnerGid")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Permissions")
      )

instance Prelude.Hashable CreationInfo where
  hashWithSalt :: Int -> CreationInfo -> Int
hashWithSalt Int
_salt CreationInfo' {Natural
Text
permissions :: Text
ownerGid :: Natural
ownerUid :: Natural
$sel:permissions:CreationInfo' :: CreationInfo -> Text
$sel:ownerGid:CreationInfo' :: CreationInfo -> Natural
$sel:ownerUid:CreationInfo' :: CreationInfo -> Natural
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Natural
ownerUid
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Natural
ownerGid
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
permissions

instance Prelude.NFData CreationInfo where
  rnf :: CreationInfo -> ()
rnf CreationInfo' {Natural
Text
permissions :: Text
ownerGid :: Natural
ownerUid :: Natural
$sel:permissions:CreationInfo' :: CreationInfo -> Text
$sel:ownerGid:CreationInfo' :: CreationInfo -> Natural
$sel:ownerUid:CreationInfo' :: CreationInfo -> Natural
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Natural
ownerUid
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Natural
ownerGid
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
permissions

instance Data.ToJSON CreationInfo where
  toJSON :: CreationInfo -> Value
toJSON CreationInfo' {Natural
Text
permissions :: Text
ownerGid :: Natural
ownerUid :: Natural
$sel:permissions:CreationInfo' :: CreationInfo -> Text
$sel:ownerGid:CreationInfo' :: CreationInfo -> Natural
$sel:ownerUid:CreationInfo' :: CreationInfo -> Natural
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"OwnerUid" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Natural
ownerUid),
            forall a. a -> Maybe a
Prelude.Just (Key
"OwnerGid" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Natural
ownerGid),
            forall a. a -> Maybe a
Prelude.Just (Key
"Permissions" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
permissions)
          ]
      )