{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# 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.CreateAccessPoint
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Creates an EFS access point. An access point is an application-specific
-- view into an EFS file system that applies an operating system user and
-- group, and a file system path, to any file system request made through
-- the access point. The operating system user and group override any
-- identity information provided by the NFS client. The file system path is
-- exposed as the access point\'s root directory. Applications using the
-- access point can only access data in the application\'s own directory
-- and any subdirectories. To learn more, see
-- <https://docs.aws.amazon.com/efs/latest/ug/efs-access-points.html Mounting a file system using EFS access points>.
--
-- If multiple requests to create access points on the same file system are
-- sent in quick succession, and the file system is near the limit of 120
-- access points, you may experience a throttling response for these
-- requests. This is to ensure that the file system does not exceed the
-- stated access point limit.
--
-- This operation requires permissions for the
-- @elasticfilesystem:CreateAccessPoint@ action.
module Amazonka.EFS.CreateAccessPoint
  ( -- * Creating a Request
    CreateAccessPoint (..),
    newCreateAccessPoint,

    -- * Request Lenses
    createAccessPoint_posixUser,
    createAccessPoint_rootDirectory,
    createAccessPoint_tags,
    createAccessPoint_clientToken,
    createAccessPoint_fileSystemId,

    -- * Destructuring the Response
    AccessPointDescription (..),
    newAccessPointDescription,

    -- * Response Lenses
    accessPointDescription_accessPointArn,
    accessPointDescription_accessPointId,
    accessPointDescription_clientToken,
    accessPointDescription_fileSystemId,
    accessPointDescription_lifeCycleState,
    accessPointDescription_name,
    accessPointDescription_ownerId,
    accessPointDescription_posixUser,
    accessPointDescription_rootDirectory,
    accessPointDescription_tags,
  )
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
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newCreateAccessPoint' smart constructor.
data CreateAccessPoint = CreateAccessPoint'
  { -- | The operating system user and group applied to all file system requests
    -- made using the access point.
    CreateAccessPoint -> Maybe PosixUser
posixUser :: Prelude.Maybe PosixUser,
    -- | Specifies the directory on the Amazon EFS file system that the access
    -- point exposes as the root directory of your file system to NFS clients
    -- using the access point. The clients using the access point can only
    -- access the root directory and below. If the @RootDirectory@ > @Path@
    -- specified does not exist, EFS creates it and applies the @CreationInfo@
    -- settings when a client connects to an access point. When specifying a
    -- @RootDirectory@, you must provide the @Path@, and the @CreationInfo@.
    --
    -- 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.
    CreateAccessPoint -> Maybe RootDirectory
rootDirectory :: Prelude.Maybe RootDirectory,
    -- | Creates tags associated with the access point. Each tag is a key-value
    -- pair, each key must be unique. For more information, see
    -- <https://docs.aws.amazon.com/general/latest/gr/aws_tagging.html Tagging Amazon Web Services resources>
    -- in the /Amazon Web Services General Reference Guide/.
    CreateAccessPoint -> Maybe [Tag]
tags :: Prelude.Maybe [Tag],
    -- | A string of up to 64 ASCII characters that Amazon EFS uses to ensure
    -- idempotent creation.
    CreateAccessPoint -> Text
clientToken :: Prelude.Text,
    -- | The ID of the EFS file system that the access point provides access to.
    CreateAccessPoint -> Text
fileSystemId :: Prelude.Text
  }
  deriving (CreateAccessPoint -> CreateAccessPoint -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateAccessPoint -> CreateAccessPoint -> Bool
$c/= :: CreateAccessPoint -> CreateAccessPoint -> Bool
== :: CreateAccessPoint -> CreateAccessPoint -> Bool
$c== :: CreateAccessPoint -> CreateAccessPoint -> Bool
Prelude.Eq, ReadPrec [CreateAccessPoint]
ReadPrec CreateAccessPoint
Int -> ReadS CreateAccessPoint
ReadS [CreateAccessPoint]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateAccessPoint]
$creadListPrec :: ReadPrec [CreateAccessPoint]
readPrec :: ReadPrec CreateAccessPoint
$creadPrec :: ReadPrec CreateAccessPoint
readList :: ReadS [CreateAccessPoint]
$creadList :: ReadS [CreateAccessPoint]
readsPrec :: Int -> ReadS CreateAccessPoint
$creadsPrec :: Int -> ReadS CreateAccessPoint
Prelude.Read, Int -> CreateAccessPoint -> ShowS
[CreateAccessPoint] -> ShowS
CreateAccessPoint -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateAccessPoint] -> ShowS
$cshowList :: [CreateAccessPoint] -> ShowS
show :: CreateAccessPoint -> String
$cshow :: CreateAccessPoint -> String
showsPrec :: Int -> CreateAccessPoint -> ShowS
$cshowsPrec :: Int -> CreateAccessPoint -> ShowS
Prelude.Show, forall x. Rep CreateAccessPoint x -> CreateAccessPoint
forall x. CreateAccessPoint -> Rep CreateAccessPoint x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateAccessPoint x -> CreateAccessPoint
$cfrom :: forall x. CreateAccessPoint -> Rep CreateAccessPoint x
Prelude.Generic)

-- |
-- Create a value of 'CreateAccessPoint' 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:
--
-- 'posixUser', 'createAccessPoint_posixUser' - The operating system user and group applied to all file system requests
-- made using the access point.
--
-- 'rootDirectory', 'createAccessPoint_rootDirectory' - Specifies the directory on the Amazon EFS file system that the access
-- point exposes as the root directory of your file system to NFS clients
-- using the access point. The clients using the access point can only
-- access the root directory and below. If the @RootDirectory@ > @Path@
-- specified does not exist, EFS creates it and applies the @CreationInfo@
-- settings when a client connects to an access point. When specifying a
-- @RootDirectory@, you must provide the @Path@, and the @CreationInfo@.
--
-- 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.
--
-- 'tags', 'createAccessPoint_tags' - Creates tags associated with the access point. Each tag is a key-value
-- pair, each key must be unique. For more information, see
-- <https://docs.aws.amazon.com/general/latest/gr/aws_tagging.html Tagging Amazon Web Services resources>
-- in the /Amazon Web Services General Reference Guide/.
--
-- 'clientToken', 'createAccessPoint_clientToken' - A string of up to 64 ASCII characters that Amazon EFS uses to ensure
-- idempotent creation.
--
-- 'fileSystemId', 'createAccessPoint_fileSystemId' - The ID of the EFS file system that the access point provides access to.
newCreateAccessPoint ::
  -- | 'clientToken'
  Prelude.Text ->
  -- | 'fileSystemId'
  Prelude.Text ->
  CreateAccessPoint
newCreateAccessPoint :: Text -> Text -> CreateAccessPoint
newCreateAccessPoint Text
pClientToken_ Text
pFileSystemId_ =
  CreateAccessPoint'
    { $sel:posixUser:CreateAccessPoint' :: Maybe PosixUser
posixUser = forall a. Maybe a
Prelude.Nothing,
      $sel:rootDirectory:CreateAccessPoint' :: Maybe RootDirectory
rootDirectory = forall a. Maybe a
Prelude.Nothing,
      $sel:tags:CreateAccessPoint' :: Maybe [Tag]
tags = forall a. Maybe a
Prelude.Nothing,
      $sel:clientToken:CreateAccessPoint' :: Text
clientToken = Text
pClientToken_,
      $sel:fileSystemId:CreateAccessPoint' :: Text
fileSystemId = Text
pFileSystemId_
    }

-- | The operating system user and group applied to all file system requests
-- made using the access point.
createAccessPoint_posixUser :: Lens.Lens' CreateAccessPoint (Prelude.Maybe PosixUser)
createAccessPoint_posixUser :: Lens' CreateAccessPoint (Maybe PosixUser)
createAccessPoint_posixUser = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateAccessPoint' {Maybe PosixUser
posixUser :: Maybe PosixUser
$sel:posixUser:CreateAccessPoint' :: CreateAccessPoint -> Maybe PosixUser
posixUser} -> Maybe PosixUser
posixUser) (\s :: CreateAccessPoint
s@CreateAccessPoint' {} Maybe PosixUser
a -> CreateAccessPoint
s {$sel:posixUser:CreateAccessPoint' :: Maybe PosixUser
posixUser = Maybe PosixUser
a} :: CreateAccessPoint)

-- | Specifies the directory on the Amazon EFS file system that the access
-- point exposes as the root directory of your file system to NFS clients
-- using the access point. The clients using the access point can only
-- access the root directory and below. If the @RootDirectory@ > @Path@
-- specified does not exist, EFS creates it and applies the @CreationInfo@
-- settings when a client connects to an access point. When specifying a
-- @RootDirectory@, you must provide the @Path@, and the @CreationInfo@.
--
-- 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.
createAccessPoint_rootDirectory :: Lens.Lens' CreateAccessPoint (Prelude.Maybe RootDirectory)
createAccessPoint_rootDirectory :: Lens' CreateAccessPoint (Maybe RootDirectory)
createAccessPoint_rootDirectory = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateAccessPoint' {Maybe RootDirectory
rootDirectory :: Maybe RootDirectory
$sel:rootDirectory:CreateAccessPoint' :: CreateAccessPoint -> Maybe RootDirectory
rootDirectory} -> Maybe RootDirectory
rootDirectory) (\s :: CreateAccessPoint
s@CreateAccessPoint' {} Maybe RootDirectory
a -> CreateAccessPoint
s {$sel:rootDirectory:CreateAccessPoint' :: Maybe RootDirectory
rootDirectory = Maybe RootDirectory
a} :: CreateAccessPoint)

-- | Creates tags associated with the access point. Each tag is a key-value
-- pair, each key must be unique. For more information, see
-- <https://docs.aws.amazon.com/general/latest/gr/aws_tagging.html Tagging Amazon Web Services resources>
-- in the /Amazon Web Services General Reference Guide/.
createAccessPoint_tags :: Lens.Lens' CreateAccessPoint (Prelude.Maybe [Tag])
createAccessPoint_tags :: Lens' CreateAccessPoint (Maybe [Tag])
createAccessPoint_tags = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateAccessPoint' {Maybe [Tag]
tags :: Maybe [Tag]
$sel:tags:CreateAccessPoint' :: CreateAccessPoint -> Maybe [Tag]
tags} -> Maybe [Tag]
tags) (\s :: CreateAccessPoint
s@CreateAccessPoint' {} Maybe [Tag]
a -> CreateAccessPoint
s {$sel:tags:CreateAccessPoint' :: Maybe [Tag]
tags = Maybe [Tag]
a} :: CreateAccessPoint) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | A string of up to 64 ASCII characters that Amazon EFS uses to ensure
-- idempotent creation.
createAccessPoint_clientToken :: Lens.Lens' CreateAccessPoint Prelude.Text
createAccessPoint_clientToken :: Lens' CreateAccessPoint Text
createAccessPoint_clientToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateAccessPoint' {Text
clientToken :: Text
$sel:clientToken:CreateAccessPoint' :: CreateAccessPoint -> Text
clientToken} -> Text
clientToken) (\s :: CreateAccessPoint
s@CreateAccessPoint' {} Text
a -> CreateAccessPoint
s {$sel:clientToken:CreateAccessPoint' :: Text
clientToken = Text
a} :: CreateAccessPoint)

-- | The ID of the EFS file system that the access point provides access to.
createAccessPoint_fileSystemId :: Lens.Lens' CreateAccessPoint Prelude.Text
createAccessPoint_fileSystemId :: Lens' CreateAccessPoint Text
createAccessPoint_fileSystemId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateAccessPoint' {Text
fileSystemId :: Text
$sel:fileSystemId:CreateAccessPoint' :: CreateAccessPoint -> Text
fileSystemId} -> Text
fileSystemId) (\s :: CreateAccessPoint
s@CreateAccessPoint' {} Text
a -> CreateAccessPoint
s {$sel:fileSystemId:CreateAccessPoint' :: Text
fileSystemId = Text
a} :: CreateAccessPoint)

instance Core.AWSRequest CreateAccessPoint where
  type
    AWSResponse CreateAccessPoint =
      AccessPointDescription
  request :: (Service -> Service)
-> CreateAccessPoint -> Request CreateAccessPoint
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy CreateAccessPoint
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateAccessPoint)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      (\Int
s ResponseHeaders
h Object
x -> forall a. FromJSON a => Object -> Either String a
Data.eitherParseJSON Object
x)

instance Prelude.Hashable CreateAccessPoint where
  hashWithSalt :: Int -> CreateAccessPoint -> Int
hashWithSalt Int
_salt CreateAccessPoint' {Maybe [Tag]
Maybe PosixUser
Maybe RootDirectory
Text
fileSystemId :: Text
clientToken :: Text
tags :: Maybe [Tag]
rootDirectory :: Maybe RootDirectory
posixUser :: Maybe PosixUser
$sel:fileSystemId:CreateAccessPoint' :: CreateAccessPoint -> Text
$sel:clientToken:CreateAccessPoint' :: CreateAccessPoint -> Text
$sel:tags:CreateAccessPoint' :: CreateAccessPoint -> Maybe [Tag]
$sel:rootDirectory:CreateAccessPoint' :: CreateAccessPoint -> Maybe RootDirectory
$sel:posixUser:CreateAccessPoint' :: CreateAccessPoint -> Maybe PosixUser
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe PosixUser
posixUser
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe RootDirectory
rootDirectory
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Tag]
tags
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
clientToken
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
fileSystemId

instance Prelude.NFData CreateAccessPoint where
  rnf :: CreateAccessPoint -> ()
rnf CreateAccessPoint' {Maybe [Tag]
Maybe PosixUser
Maybe RootDirectory
Text
fileSystemId :: Text
clientToken :: Text
tags :: Maybe [Tag]
rootDirectory :: Maybe RootDirectory
posixUser :: Maybe PosixUser
$sel:fileSystemId:CreateAccessPoint' :: CreateAccessPoint -> Text
$sel:clientToken:CreateAccessPoint' :: CreateAccessPoint -> Text
$sel:tags:CreateAccessPoint' :: CreateAccessPoint -> Maybe [Tag]
$sel:rootDirectory:CreateAccessPoint' :: CreateAccessPoint -> Maybe RootDirectory
$sel:posixUser:CreateAccessPoint' :: CreateAccessPoint -> Maybe PosixUser
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe PosixUser
posixUser
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe RootDirectory
rootDirectory
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [Tag]
tags
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
clientToken
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
fileSystemId

instance Data.ToHeaders CreateAccessPoint where
  toHeaders :: CreateAccessPoint -> ResponseHeaders
toHeaders = forall a b. a -> b -> a
Prelude.const forall a. Monoid a => a
Prelude.mempty

instance Data.ToJSON CreateAccessPoint where
  toJSON :: CreateAccessPoint -> Value
toJSON CreateAccessPoint' {Maybe [Tag]
Maybe PosixUser
Maybe RootDirectory
Text
fileSystemId :: Text
clientToken :: Text
tags :: Maybe [Tag]
rootDirectory :: Maybe RootDirectory
posixUser :: Maybe PosixUser
$sel:fileSystemId:CreateAccessPoint' :: CreateAccessPoint -> Text
$sel:clientToken:CreateAccessPoint' :: CreateAccessPoint -> Text
$sel:tags:CreateAccessPoint' :: CreateAccessPoint -> Maybe [Tag]
$sel:rootDirectory:CreateAccessPoint' :: CreateAccessPoint -> Maybe RootDirectory
$sel:posixUser:CreateAccessPoint' :: CreateAccessPoint -> Maybe PosixUser
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"PosixUser" 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 PosixUser
posixUser,
            (Key
"RootDirectory" 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 RootDirectory
rootDirectory,
            (Key
"Tags" 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 [Tag]
tags,
            forall a. a -> Maybe a
Prelude.Just (Key
"ClientToken" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
clientToken),
            forall a. a -> Maybe a
Prelude.Just (Key
"FileSystemId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
fileSystemId)
          ]
      )

instance Data.ToPath CreateAccessPoint where
  toPath :: CreateAccessPoint -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/2015-02-01/access-points"

instance Data.ToQuery CreateAccessPoint where
  toQuery :: CreateAccessPoint -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const forall a. Monoid a => a
Prelude.mempty