{-# 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-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)
--
-- 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 its own directory and below. To
-- learn more, see
-- <https://docs.aws.amazon.com/efs/latest/ug/efs-access-points.html Mounting a file system using EFS access points>.
--
-- 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_posixUser,
    accessPointDescription_rootDirectory,
    accessPointDescription_clientToken,
    accessPointDescription_accessPointId,
    accessPointDescription_fileSystemId,
    accessPointDescription_ownerId,
    accessPointDescription_name,
    accessPointDescription_accessPointArn,
    accessPointDescription_lifeCycleState,
    accessPointDescription_tags,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.EFS.Types
import qualified Amazonka.Lens as Lens
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 need to 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
(CreateAccessPoint -> CreateAccessPoint -> Bool)
-> (CreateAccessPoint -> CreateAccessPoint -> Bool)
-> Eq CreateAccessPoint
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]
(Int -> ReadS CreateAccessPoint)
-> ReadS [CreateAccessPoint]
-> ReadPrec CreateAccessPoint
-> ReadPrec [CreateAccessPoint]
-> Read 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
(Int -> CreateAccessPoint -> ShowS)
-> (CreateAccessPoint -> String)
-> ([CreateAccessPoint] -> ShowS)
-> Show CreateAccessPoint
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. CreateAccessPoint -> Rep CreateAccessPoint x)
-> (forall x. Rep CreateAccessPoint x -> CreateAccessPoint)
-> Generic CreateAccessPoint
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 need to 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' :: Maybe PosixUser
-> Maybe RootDirectory
-> Maybe [Tag]
-> Text
-> Text
-> CreateAccessPoint
CreateAccessPoint'
    { $sel:posixUser:CreateAccessPoint' :: Maybe PosixUser
posixUser = Maybe PosixUser
forall a. Maybe a
Prelude.Nothing,
      $sel:rootDirectory:CreateAccessPoint' :: Maybe RootDirectory
rootDirectory = Maybe RootDirectory
forall a. Maybe a
Prelude.Nothing,
      $sel:tags:CreateAccessPoint' :: Maybe [Tag]
tags = Maybe [Tag]
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 :: (Maybe PosixUser -> f (Maybe PosixUser))
-> CreateAccessPoint -> f CreateAccessPoint
createAccessPoint_posixUser = (CreateAccessPoint -> Maybe PosixUser)
-> (CreateAccessPoint -> Maybe PosixUser -> CreateAccessPoint)
-> Lens
     CreateAccessPoint
     CreateAccessPoint
     (Maybe PosixUser)
     (Maybe 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 need to 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 :: (Maybe RootDirectory -> f (Maybe RootDirectory))
-> CreateAccessPoint -> f CreateAccessPoint
createAccessPoint_rootDirectory = (CreateAccessPoint -> Maybe RootDirectory)
-> (CreateAccessPoint -> Maybe RootDirectory -> CreateAccessPoint)
-> Lens
     CreateAccessPoint
     CreateAccessPoint
     (Maybe RootDirectory)
     (Maybe 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 :: (Maybe [Tag] -> f (Maybe [Tag]))
-> CreateAccessPoint -> f CreateAccessPoint
createAccessPoint_tags = (CreateAccessPoint -> Maybe [Tag])
-> (CreateAccessPoint -> Maybe [Tag] -> CreateAccessPoint)
-> Lens
     CreateAccessPoint CreateAccessPoint (Maybe [Tag]) (Maybe [Tag])
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) ((Maybe [Tag] -> f (Maybe [Tag]))
 -> CreateAccessPoint -> f CreateAccessPoint)
-> ((Maybe [Tag] -> f (Maybe [Tag]))
    -> Maybe [Tag] -> f (Maybe [Tag]))
-> (Maybe [Tag] -> f (Maybe [Tag]))
-> CreateAccessPoint
-> f CreateAccessPoint
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Tag] [Tag] [Tag] [Tag]
-> Iso (Maybe [Tag]) (Maybe [Tag]) (Maybe [Tag]) (Maybe [Tag])
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 AnIso [Tag] [Tag] [Tag] [Tag]
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 :: (Text -> f Text) -> CreateAccessPoint -> f CreateAccessPoint
createAccessPoint_clientToken = (CreateAccessPoint -> Text)
-> (CreateAccessPoint -> Text -> CreateAccessPoint)
-> Lens CreateAccessPoint CreateAccessPoint Text Text
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 :: (Text -> f Text) -> CreateAccessPoint -> f CreateAccessPoint
createAccessPoint_fileSystemId = (CreateAccessPoint -> Text)
-> (CreateAccessPoint -> Text -> CreateAccessPoint)
-> Lens CreateAccessPoint CreateAccessPoint Text Text
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 :: CreateAccessPoint -> Request CreateAccessPoint
request = Service -> CreateAccessPoint -> Request CreateAccessPoint
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateAccessPoint
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateAccessPoint)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse CreateAccessPoint))
-> Logger
-> Service
-> Proxy CreateAccessPoint
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateAccessPoint)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      (\Int
s ResponseHeaders
h Object
x -> Object -> Either String AccessPointDescription
forall a. FromJSON a => Object -> Either String a
Core.eitherParseJSON Object
x)

instance Prelude.Hashable CreateAccessPoint

instance Prelude.NFData CreateAccessPoint

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

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"PosixUser" Text -> PosixUser -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (PosixUser -> Pair) -> Maybe PosixUser -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe PosixUser
posixUser,
            (Text
"RootDirectory" Text -> RootDirectory -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (RootDirectory -> Pair) -> Maybe RootDirectory -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe RootDirectory
rootDirectory,
            (Text
"Tags" Text -> [Tag] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) ([Tag] -> Pair) -> Maybe [Tag] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Tag]
tags,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"ClientToken" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
clientToken),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"FileSystemId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
fileSystemId)
          ]
      )

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

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