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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(CreationInfo -> CreationInfo -> Bool)
-> (CreationInfo -> CreationInfo -> Bool) -> Eq CreationInfo
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]
(Int -> ReadS CreationInfo)
-> ReadS [CreationInfo]
-> ReadPrec CreationInfo
-> ReadPrec [CreationInfo]
-> Read 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
(Int -> CreationInfo -> ShowS)
-> (CreationInfo -> String)
-> ([CreationInfo] -> ShowS)
-> Show CreationInfo
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. CreationInfo -> Rep CreationInfo x)
-> (forall x. Rep CreationInfo x -> CreationInfo)
-> Generic CreationInfo
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' :: Natural -> Natural -> Text -> CreationInfo
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 :: (Natural -> f Natural) -> CreationInfo -> f CreationInfo
creationInfo_ownerUid = (CreationInfo -> Natural)
-> (CreationInfo -> Natural -> CreationInfo)
-> Lens CreationInfo CreationInfo Natural Natural
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 :: (Natural -> f Natural) -> CreationInfo -> f CreationInfo
creationInfo_ownerGid = (CreationInfo -> Natural)
-> (CreationInfo -> Natural -> CreationInfo)
-> Lens CreationInfo CreationInfo Natural Natural
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 :: (Text -> f Text) -> CreationInfo -> f CreationInfo
creationInfo_permissions = (CreationInfo -> Text)
-> (CreationInfo -> Text -> CreationInfo)
-> Lens CreationInfo CreationInfo Text Text
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 Core.FromJSON CreationInfo where
  parseJSON :: Value -> Parser CreationInfo
parseJSON =
    String
-> (Object -> Parser CreationInfo) -> Value -> Parser CreationInfo
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"CreationInfo"
      ( \Object
x ->
          Natural -> Natural -> Text -> CreationInfo
CreationInfo'
            (Natural -> Natural -> Text -> CreationInfo)
-> Parser Natural -> Parser (Natural -> Text -> CreationInfo)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Natural
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"OwnerUid")
            Parser (Natural -> Text -> CreationInfo)
-> Parser Natural -> Parser (Text -> CreationInfo)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Natural
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"OwnerGid")
            Parser (Text -> CreationInfo) -> Parser Text -> Parser CreationInfo
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Permissions")
      )

instance Prelude.Hashable CreationInfo

instance Prelude.NFData CreationInfo

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"OwnerUid" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Natural
ownerUid),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"OwnerGid" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Natural
ownerGid),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Permissions" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
permissions)
          ]
      )