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

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.EFS.Types.CreationInfo
import qualified Amazonka.Prelude as Prelude

-- | Specifies the directory on the Amazon EFS file system that the access
-- point provides access to. The access point exposes the specified file
-- system path as the root directory of your file system to applications
-- using the access point. NFS clients using the access point can only
-- access data in the access point\'s @RootDirectory@ and it\'s
-- subdirectories.
--
-- /See:/ 'newRootDirectory' smart constructor.
data RootDirectory = RootDirectory'
  { -- | (Optional) Specifies the POSIX IDs and permissions to apply to the
    -- access point\'s @RootDirectory@. If the @RootDirectory@ > @Path@
    -- specified does not exist, EFS creates the root directory using the
    -- @CreationInfo@ settings when a client connects to an access point. When
    -- specifying the @CreationInfo@, you must provide values for all
    -- properties.
    --
    -- If you do not provide @CreationInfo@ and the specified @RootDirectory@ >
    -- @Path@ does not exist, attempts to mount the file system using the
    -- access point will fail.
    RootDirectory -> Maybe CreationInfo
creationInfo :: Prelude.Maybe CreationInfo,
    -- | Specifies the path on the EFS file system to expose as the root
    -- directory to NFS clients using the access point to access the EFS file
    -- system. A path can have up to four subdirectories. If the specified path
    -- does not exist, you are required to provide the @CreationInfo@.
    RootDirectory -> Maybe Text
path :: Prelude.Maybe Prelude.Text
  }
  deriving (RootDirectory -> RootDirectory -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RootDirectory -> RootDirectory -> Bool
$c/= :: RootDirectory -> RootDirectory -> Bool
== :: RootDirectory -> RootDirectory -> Bool
$c== :: RootDirectory -> RootDirectory -> Bool
Prelude.Eq, ReadPrec [RootDirectory]
ReadPrec RootDirectory
Int -> ReadS RootDirectory
ReadS [RootDirectory]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RootDirectory]
$creadListPrec :: ReadPrec [RootDirectory]
readPrec :: ReadPrec RootDirectory
$creadPrec :: ReadPrec RootDirectory
readList :: ReadS [RootDirectory]
$creadList :: ReadS [RootDirectory]
readsPrec :: Int -> ReadS RootDirectory
$creadsPrec :: Int -> ReadS RootDirectory
Prelude.Read, Int -> RootDirectory -> ShowS
[RootDirectory] -> ShowS
RootDirectory -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RootDirectory] -> ShowS
$cshowList :: [RootDirectory] -> ShowS
show :: RootDirectory -> String
$cshow :: RootDirectory -> String
showsPrec :: Int -> RootDirectory -> ShowS
$cshowsPrec :: Int -> RootDirectory -> ShowS
Prelude.Show, forall x. Rep RootDirectory x -> RootDirectory
forall x. RootDirectory -> Rep RootDirectory x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RootDirectory x -> RootDirectory
$cfrom :: forall x. RootDirectory -> Rep RootDirectory x
Prelude.Generic)

-- |
-- Create a value of 'RootDirectory' 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:
--
-- 'creationInfo', 'rootDirectory_creationInfo' - (Optional) Specifies the POSIX IDs and permissions to apply to the
-- access point\'s @RootDirectory@. If the @RootDirectory@ > @Path@
-- specified does not exist, EFS creates the root directory using the
-- @CreationInfo@ settings when a client connects to an access point. When
-- specifying the @CreationInfo@, you must provide values for all
-- properties.
--
-- If you do not provide @CreationInfo@ and the specified @RootDirectory@ >
-- @Path@ does not exist, attempts to mount the file system using the
-- access point will fail.
--
-- 'path', 'rootDirectory_path' - Specifies the path on the EFS file system to expose as the root
-- directory to NFS clients using the access point to access the EFS file
-- system. A path can have up to four subdirectories. If the specified path
-- does not exist, you are required to provide the @CreationInfo@.
newRootDirectory ::
  RootDirectory
newRootDirectory :: RootDirectory
newRootDirectory =
  RootDirectory'
    { $sel:creationInfo:RootDirectory' :: Maybe CreationInfo
creationInfo = forall a. Maybe a
Prelude.Nothing,
      $sel:path:RootDirectory' :: Maybe Text
path = forall a. Maybe a
Prelude.Nothing
    }

-- | (Optional) Specifies the POSIX IDs and permissions to apply to the
-- access point\'s @RootDirectory@. If the @RootDirectory@ > @Path@
-- specified does not exist, EFS creates the root directory using the
-- @CreationInfo@ settings when a client connects to an access point. When
-- specifying the @CreationInfo@, you must provide values for all
-- properties.
--
-- If you do not provide @CreationInfo@ and the specified @RootDirectory@ >
-- @Path@ does not exist, attempts to mount the file system using the
-- access point will fail.
rootDirectory_creationInfo :: Lens.Lens' RootDirectory (Prelude.Maybe CreationInfo)
rootDirectory_creationInfo :: Lens' RootDirectory (Maybe CreationInfo)
rootDirectory_creationInfo = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RootDirectory' {Maybe CreationInfo
creationInfo :: Maybe CreationInfo
$sel:creationInfo:RootDirectory' :: RootDirectory -> Maybe CreationInfo
creationInfo} -> Maybe CreationInfo
creationInfo) (\s :: RootDirectory
s@RootDirectory' {} Maybe CreationInfo
a -> RootDirectory
s {$sel:creationInfo:RootDirectory' :: Maybe CreationInfo
creationInfo = Maybe CreationInfo
a} :: RootDirectory)

-- | Specifies the path on the EFS file system to expose as the root
-- directory to NFS clients using the access point to access the EFS file
-- system. A path can have up to four subdirectories. If the specified path
-- does not exist, you are required to provide the @CreationInfo@.
rootDirectory_path :: Lens.Lens' RootDirectory (Prelude.Maybe Prelude.Text)
rootDirectory_path :: Lens' RootDirectory (Maybe Text)
rootDirectory_path = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RootDirectory' {Maybe Text
path :: Maybe Text
$sel:path:RootDirectory' :: RootDirectory -> Maybe Text
path} -> Maybe Text
path) (\s :: RootDirectory
s@RootDirectory' {} Maybe Text
a -> RootDirectory
s {$sel:path:RootDirectory' :: Maybe Text
path = Maybe Text
a} :: RootDirectory)

instance Data.FromJSON RootDirectory where
  parseJSON :: Value -> Parser RootDirectory
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"RootDirectory"
      ( \Object
x ->
          Maybe CreationInfo -> Maybe Text -> RootDirectory
RootDirectory'
            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
"CreationInfo")
            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
"Path")
      )

instance Prelude.Hashable RootDirectory where
  hashWithSalt :: Int -> RootDirectory -> Int
hashWithSalt Int
_salt RootDirectory' {Maybe Text
Maybe CreationInfo
path :: Maybe Text
creationInfo :: Maybe CreationInfo
$sel:path:RootDirectory' :: RootDirectory -> Maybe Text
$sel:creationInfo:RootDirectory' :: RootDirectory -> Maybe CreationInfo
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe CreationInfo
creationInfo
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
path

instance Prelude.NFData RootDirectory where
  rnf :: RootDirectory -> ()
rnf RootDirectory' {Maybe Text
Maybe CreationInfo
path :: Maybe Text
creationInfo :: Maybe CreationInfo
$sel:path:RootDirectory' :: RootDirectory -> Maybe Text
$sel:creationInfo:RootDirectory' :: RootDirectory -> Maybe CreationInfo
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe CreationInfo
creationInfo
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
path

instance Data.ToJSON RootDirectory where
  toJSON :: RootDirectory -> Value
toJSON RootDirectory' {Maybe Text
Maybe CreationInfo
path :: Maybe Text
creationInfo :: Maybe CreationInfo
$sel:path:RootDirectory' :: RootDirectory -> Maybe Text
$sel:creationInfo:RootDirectory' :: RootDirectory -> Maybe CreationInfo
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"CreationInfo" 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 CreationInfo
creationInfo,
            (Key
"Path" 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 Text
path
          ]
      )