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

import qualified Amazonka.Core as Core
import Amazonka.EFS.Types.CreationInfo
import qualified Amazonka.Lens as Lens
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
(RootDirectory -> RootDirectory -> Bool)
-> (RootDirectory -> RootDirectory -> Bool) -> Eq RootDirectory
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]
(Int -> ReadS RootDirectory)
-> ReadS [RootDirectory]
-> ReadPrec RootDirectory
-> ReadPrec [RootDirectory]
-> Read 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
(Int -> RootDirectory -> ShowS)
-> (RootDirectory -> String)
-> ([RootDirectory] -> ShowS)
-> Show RootDirectory
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. RootDirectory -> Rep RootDirectory x)
-> (forall x. Rep RootDirectory x -> RootDirectory)
-> Generic RootDirectory
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' :: Maybe CreationInfo -> Maybe Text -> RootDirectory
RootDirectory'
    { $sel:creationInfo:RootDirectory' :: Maybe CreationInfo
creationInfo = Maybe CreationInfo
forall a. Maybe a
Prelude.Nothing,
      $sel:path:RootDirectory' :: Maybe Text
path = Maybe Text
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 :: (Maybe CreationInfo -> f (Maybe CreationInfo))
-> RootDirectory -> f RootDirectory
rootDirectory_creationInfo = (RootDirectory -> Maybe CreationInfo)
-> (RootDirectory -> Maybe CreationInfo -> RootDirectory)
-> Lens
     RootDirectory
     RootDirectory
     (Maybe CreationInfo)
     (Maybe 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 :: (Maybe Text -> f (Maybe Text)) -> RootDirectory -> f RootDirectory
rootDirectory_path = (RootDirectory -> Maybe Text)
-> (RootDirectory -> Maybe Text -> RootDirectory)
-> Lens RootDirectory RootDirectory (Maybe Text) (Maybe Text)
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 Core.FromJSON RootDirectory where
  parseJSON :: Value -> Parser RootDirectory
parseJSON =
    String
-> (Object -> Parser RootDirectory)
-> Value
-> Parser RootDirectory
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"RootDirectory"
      ( \Object
x ->
          Maybe CreationInfo -> Maybe Text -> RootDirectory
RootDirectory'
            (Maybe CreationInfo -> Maybe Text -> RootDirectory)
-> Parser (Maybe CreationInfo)
-> Parser (Maybe Text -> RootDirectory)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe CreationInfo)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"CreationInfo")
            Parser (Maybe Text -> RootDirectory)
-> Parser (Maybe Text) -> Parser RootDirectory
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Path")
      )

instance Prelude.Hashable RootDirectory

instance Prelude.NFData RootDirectory

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"CreationInfo" Text -> CreationInfo -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (CreationInfo -> Pair) -> Maybe CreationInfo -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe CreationInfo
creationInfo,
            (Text
"Path" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
path
          ]
      )