{-# 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.MemoryDb.CreateACL
-- 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 Access Control List. For more information, see
-- <https://docs.aws.amazon.com/MemoryDB/latest/devguide/clusters.acls.html Authenticating users with Access Contol Lists (ACLs)>.
module Amazonka.MemoryDb.CreateACL
  ( -- * Creating a Request
    CreateACL (..),
    newCreateACL,

    -- * Request Lenses
    createACL_userNames,
    createACL_tags,
    createACL_aCLName,

    -- * Destructuring the Response
    CreateACLResponse (..),
    newCreateACLResponse,

    -- * Response Lenses
    createACLResponse_acl,
    createACLResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.MemoryDb.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newCreateACL' smart constructor.
data CreateACL = CreateACL'
  { -- | The list of users that belong to the Access Control List.
    CreateACL -> Maybe (NonEmpty Text)
userNames :: Prelude.Maybe (Prelude.NonEmpty Prelude.Text),
    -- | A list of tags to be added to this resource. A tag is a key-value pair.
    -- A tag key must be accompanied by a tag value, although null is accepted.
    CreateACL -> Maybe [Tag]
tags :: Prelude.Maybe [Tag],
    -- | The name of the Access Control List.
    CreateACL -> Text
aCLName :: Prelude.Text
  }
  deriving (CreateACL -> CreateACL -> Bool
(CreateACL -> CreateACL -> Bool)
-> (CreateACL -> CreateACL -> Bool) -> Eq CreateACL
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateACL -> CreateACL -> Bool
$c/= :: CreateACL -> CreateACL -> Bool
== :: CreateACL -> CreateACL -> Bool
$c== :: CreateACL -> CreateACL -> Bool
Prelude.Eq, ReadPrec [CreateACL]
ReadPrec CreateACL
Int -> ReadS CreateACL
ReadS [CreateACL]
(Int -> ReadS CreateACL)
-> ReadS [CreateACL]
-> ReadPrec CreateACL
-> ReadPrec [CreateACL]
-> Read CreateACL
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateACL]
$creadListPrec :: ReadPrec [CreateACL]
readPrec :: ReadPrec CreateACL
$creadPrec :: ReadPrec CreateACL
readList :: ReadS [CreateACL]
$creadList :: ReadS [CreateACL]
readsPrec :: Int -> ReadS CreateACL
$creadsPrec :: Int -> ReadS CreateACL
Prelude.Read, Int -> CreateACL -> ShowS
[CreateACL] -> ShowS
CreateACL -> String
(Int -> CreateACL -> ShowS)
-> (CreateACL -> String)
-> ([CreateACL] -> ShowS)
-> Show CreateACL
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateACL] -> ShowS
$cshowList :: [CreateACL] -> ShowS
show :: CreateACL -> String
$cshow :: CreateACL -> String
showsPrec :: Int -> CreateACL -> ShowS
$cshowsPrec :: Int -> CreateACL -> ShowS
Prelude.Show, (forall x. CreateACL -> Rep CreateACL x)
-> (forall x. Rep CreateACL x -> CreateACL) -> Generic CreateACL
forall x. Rep CreateACL x -> CreateACL
forall x. CreateACL -> Rep CreateACL x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateACL x -> CreateACL
$cfrom :: forall x. CreateACL -> Rep CreateACL x
Prelude.Generic)

-- |
-- Create a value of 'CreateACL' 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:
--
-- 'userNames', 'createACL_userNames' - The list of users that belong to the Access Control List.
--
-- 'tags', 'createACL_tags' - A list of tags to be added to this resource. A tag is a key-value pair.
-- A tag key must be accompanied by a tag value, although null is accepted.
--
-- 'aCLName', 'createACL_aCLName' - The name of the Access Control List.
newCreateACL ::
  -- | 'aCLName'
  Prelude.Text ->
  CreateACL
newCreateACL :: Text -> CreateACL
newCreateACL Text
pACLName_ =
  CreateACL' :: Maybe (NonEmpty Text) -> Maybe [Tag] -> Text -> CreateACL
CreateACL'
    { $sel:userNames:CreateACL' :: Maybe (NonEmpty Text)
userNames = Maybe (NonEmpty Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:tags:CreateACL' :: Maybe [Tag]
tags = Maybe [Tag]
forall a. Maybe a
Prelude.Nothing,
      $sel:aCLName:CreateACL' :: Text
aCLName = Text
pACLName_
    }

-- | The list of users that belong to the Access Control List.
createACL_userNames :: Lens.Lens' CreateACL (Prelude.Maybe (Prelude.NonEmpty Prelude.Text))
createACL_userNames :: (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> CreateACL -> f CreateACL
createACL_userNames = (CreateACL -> Maybe (NonEmpty Text))
-> (CreateACL -> Maybe (NonEmpty Text) -> CreateACL)
-> Lens
     CreateACL CreateACL (Maybe (NonEmpty Text)) (Maybe (NonEmpty Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateACL' {Maybe (NonEmpty Text)
userNames :: Maybe (NonEmpty Text)
$sel:userNames:CreateACL' :: CreateACL -> Maybe (NonEmpty Text)
userNames} -> Maybe (NonEmpty Text)
userNames) (\s :: CreateACL
s@CreateACL' {} Maybe (NonEmpty Text)
a -> CreateACL
s {$sel:userNames:CreateACL' :: Maybe (NonEmpty Text)
userNames = Maybe (NonEmpty Text)
a} :: CreateACL) ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
 -> CreateACL -> f CreateACL)
-> ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
    -> Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> CreateACL
-> f CreateACL
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (NonEmpty Text) (NonEmpty Text) (NonEmpty Text) (NonEmpty Text)
-> Iso
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
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
  (NonEmpty Text) (NonEmpty Text) (NonEmpty Text) (NonEmpty Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | A list of tags to be added to this resource. A tag is a key-value pair.
-- A tag key must be accompanied by a tag value, although null is accepted.
createACL_tags :: Lens.Lens' CreateACL (Prelude.Maybe [Tag])
createACL_tags :: (Maybe [Tag] -> f (Maybe [Tag])) -> CreateACL -> f CreateACL
createACL_tags = (CreateACL -> Maybe [Tag])
-> (CreateACL -> Maybe [Tag] -> CreateACL)
-> Lens CreateACL CreateACL (Maybe [Tag]) (Maybe [Tag])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateACL' {Maybe [Tag]
tags :: Maybe [Tag]
$sel:tags:CreateACL' :: CreateACL -> Maybe [Tag]
tags} -> Maybe [Tag]
tags) (\s :: CreateACL
s@CreateACL' {} Maybe [Tag]
a -> CreateACL
s {$sel:tags:CreateACL' :: Maybe [Tag]
tags = Maybe [Tag]
a} :: CreateACL) ((Maybe [Tag] -> f (Maybe [Tag])) -> CreateACL -> f CreateACL)
-> ((Maybe [Tag] -> f (Maybe [Tag]))
    -> Maybe [Tag] -> f (Maybe [Tag]))
-> (Maybe [Tag] -> f (Maybe [Tag]))
-> CreateACL
-> f CreateACL
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

-- | The name of the Access Control List.
createACL_aCLName :: Lens.Lens' CreateACL Prelude.Text
createACL_aCLName :: (Text -> f Text) -> CreateACL -> f CreateACL
createACL_aCLName = (CreateACL -> Text)
-> (CreateACL -> Text -> CreateACL)
-> Lens CreateACL CreateACL Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateACL' {Text
aCLName :: Text
$sel:aCLName:CreateACL' :: CreateACL -> Text
aCLName} -> Text
aCLName) (\s :: CreateACL
s@CreateACL' {} Text
a -> CreateACL
s {$sel:aCLName:CreateACL' :: Text
aCLName = Text
a} :: CreateACL)

instance Core.AWSRequest CreateACL where
  type AWSResponse CreateACL = CreateACLResponse
  request :: CreateACL -> Request CreateACL
request = Service -> CreateACL -> Request CreateACL
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateACL
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateACL)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse CreateACL))
-> Logger
-> Service
-> Proxy CreateACL
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateACL)))
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 ->
          Maybe ACL -> Int -> CreateACLResponse
CreateACLResponse'
            (Maybe ACL -> Int -> CreateACLResponse)
-> Either String (Maybe ACL)
-> Either String (Int -> CreateACLResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe ACL)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"ACL")
            Either String (Int -> CreateACLResponse)
-> Either String Int -> Either String CreateACLResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable CreateACL

instance Prelude.NFData CreateACL

instance Core.ToHeaders CreateACL where
  toHeaders :: CreateACL -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreateACL -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# (ByteString
"AmazonMemoryDB.CreateACL" :: Prelude.ByteString),
            HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON CreateACL where
  toJSON :: CreateACL -> Value
toJSON CreateACL' {Maybe [Tag]
Maybe (NonEmpty Text)
Text
aCLName :: Text
tags :: Maybe [Tag]
userNames :: Maybe (NonEmpty Text)
$sel:aCLName:CreateACL' :: CreateACL -> Text
$sel:tags:CreateACL' :: CreateACL -> Maybe [Tag]
$sel:userNames:CreateACL' :: CreateACL -> Maybe (NonEmpty Text)
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"UserNames" Text -> NonEmpty Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (NonEmpty Text -> Pair) -> Maybe (NonEmpty Text) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty Text)
userNames,
            (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
"ACLName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
aCLName)
          ]
      )

instance Core.ToPath CreateACL where
  toPath :: CreateACL -> ByteString
toPath = ByteString -> CreateACL -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

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

-- | /See:/ 'newCreateACLResponse' smart constructor.
data CreateACLResponse = CreateACLResponse'
  { -- | The newly-created Access Control List.
    CreateACLResponse -> Maybe ACL
acl :: Prelude.Maybe ACL,
    -- | The response's http status code.
    CreateACLResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CreateACLResponse -> CreateACLResponse -> Bool
(CreateACLResponse -> CreateACLResponse -> Bool)
-> (CreateACLResponse -> CreateACLResponse -> Bool)
-> Eq CreateACLResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateACLResponse -> CreateACLResponse -> Bool
$c/= :: CreateACLResponse -> CreateACLResponse -> Bool
== :: CreateACLResponse -> CreateACLResponse -> Bool
$c== :: CreateACLResponse -> CreateACLResponse -> Bool
Prelude.Eq, ReadPrec [CreateACLResponse]
ReadPrec CreateACLResponse
Int -> ReadS CreateACLResponse
ReadS [CreateACLResponse]
(Int -> ReadS CreateACLResponse)
-> ReadS [CreateACLResponse]
-> ReadPrec CreateACLResponse
-> ReadPrec [CreateACLResponse]
-> Read CreateACLResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateACLResponse]
$creadListPrec :: ReadPrec [CreateACLResponse]
readPrec :: ReadPrec CreateACLResponse
$creadPrec :: ReadPrec CreateACLResponse
readList :: ReadS [CreateACLResponse]
$creadList :: ReadS [CreateACLResponse]
readsPrec :: Int -> ReadS CreateACLResponse
$creadsPrec :: Int -> ReadS CreateACLResponse
Prelude.Read, Int -> CreateACLResponse -> ShowS
[CreateACLResponse] -> ShowS
CreateACLResponse -> String
(Int -> CreateACLResponse -> ShowS)
-> (CreateACLResponse -> String)
-> ([CreateACLResponse] -> ShowS)
-> Show CreateACLResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateACLResponse] -> ShowS
$cshowList :: [CreateACLResponse] -> ShowS
show :: CreateACLResponse -> String
$cshow :: CreateACLResponse -> String
showsPrec :: Int -> CreateACLResponse -> ShowS
$cshowsPrec :: Int -> CreateACLResponse -> ShowS
Prelude.Show, (forall x. CreateACLResponse -> Rep CreateACLResponse x)
-> (forall x. Rep CreateACLResponse x -> CreateACLResponse)
-> Generic CreateACLResponse
forall x. Rep CreateACLResponse x -> CreateACLResponse
forall x. CreateACLResponse -> Rep CreateACLResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateACLResponse x -> CreateACLResponse
$cfrom :: forall x. CreateACLResponse -> Rep CreateACLResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreateACLResponse' 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:
--
-- 'acl', 'createACLResponse_acl' - The newly-created Access Control List.
--
-- 'httpStatus', 'createACLResponse_httpStatus' - The response's http status code.
newCreateACLResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateACLResponse
newCreateACLResponse :: Int -> CreateACLResponse
newCreateACLResponse Int
pHttpStatus_ =
  CreateACLResponse' :: Maybe ACL -> Int -> CreateACLResponse
CreateACLResponse'
    { $sel:acl:CreateACLResponse' :: Maybe ACL
acl = Maybe ACL
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreateACLResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The newly-created Access Control List.
createACLResponse_acl :: Lens.Lens' CreateACLResponse (Prelude.Maybe ACL)
createACLResponse_acl :: (Maybe ACL -> f (Maybe ACL))
-> CreateACLResponse -> f CreateACLResponse
createACLResponse_acl = (CreateACLResponse -> Maybe ACL)
-> (CreateACLResponse -> Maybe ACL -> CreateACLResponse)
-> Lens CreateACLResponse CreateACLResponse (Maybe ACL) (Maybe ACL)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateACLResponse' {Maybe ACL
acl :: Maybe ACL
$sel:acl:CreateACLResponse' :: CreateACLResponse -> Maybe ACL
acl} -> Maybe ACL
acl) (\s :: CreateACLResponse
s@CreateACLResponse' {} Maybe ACL
a -> CreateACLResponse
s {$sel:acl:CreateACLResponse' :: Maybe ACL
acl = Maybe ACL
a} :: CreateACLResponse)

-- | The response's http status code.
createACLResponse_httpStatus :: Lens.Lens' CreateACLResponse Prelude.Int
createACLResponse_httpStatus :: (Int -> f Int) -> CreateACLResponse -> f CreateACLResponse
createACLResponse_httpStatus = (CreateACLResponse -> Int)
-> (CreateACLResponse -> Int -> CreateACLResponse)
-> Lens CreateACLResponse CreateACLResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateACLResponse' {Int
httpStatus :: Int
$sel:httpStatus:CreateACLResponse' :: CreateACLResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: CreateACLResponse
s@CreateACLResponse' {} Int
a -> CreateACLResponse
s {$sel:httpStatus:CreateACLResponse' :: Int
httpStatus = Int
a} :: CreateACLResponse)

instance Prelude.NFData CreateACLResponse