{-# 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.ElastiCache.CreateUserGroup
-- 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)
--
-- For Redis engine version 6.x onwards: Creates a Redis user group. For
-- more information, see
-- <http://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/Clusters.RBAC.html Using Role Based Access Control (RBAC)>
module Amazonka.ElastiCache.CreateUserGroup
  ( -- * Creating a Request
    CreateUserGroup (..),
    newCreateUserGroup,

    -- * Request Lenses
    createUserGroup_userIds,
    createUserGroup_tags,
    createUserGroup_userGroupId,
    createUserGroup_engine,

    -- * Destructuring the Response
    UserGroup (..),
    newUserGroup,

    -- * Response Lenses
    userGroup_status,
    userGroup_userIds,
    userGroup_arn,
    userGroup_userGroupId,
    userGroup_engine,
    userGroup_pendingChanges,
    userGroup_replicationGroups,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.ElastiCache.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:/ 'newCreateUserGroup' smart constructor.
data CreateUserGroup = CreateUserGroup'
  { -- | The list of user IDs that belong to the user group.
    CreateUserGroup -> Maybe (NonEmpty Text)
userIds :: 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.
    CreateUserGroup -> Maybe [Tag]
tags :: Prelude.Maybe [Tag],
    -- | The ID of the user group.
    CreateUserGroup -> Text
userGroupId :: Prelude.Text,
    -- | The current supported value is Redis.
    CreateUserGroup -> Text
engine :: Prelude.Text
  }
  deriving (CreateUserGroup -> CreateUserGroup -> Bool
(CreateUserGroup -> CreateUserGroup -> Bool)
-> (CreateUserGroup -> CreateUserGroup -> Bool)
-> Eq CreateUserGroup
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateUserGroup -> CreateUserGroup -> Bool
$c/= :: CreateUserGroup -> CreateUserGroup -> Bool
== :: CreateUserGroup -> CreateUserGroup -> Bool
$c== :: CreateUserGroup -> CreateUserGroup -> Bool
Prelude.Eq, ReadPrec [CreateUserGroup]
ReadPrec CreateUserGroup
Int -> ReadS CreateUserGroup
ReadS [CreateUserGroup]
(Int -> ReadS CreateUserGroup)
-> ReadS [CreateUserGroup]
-> ReadPrec CreateUserGroup
-> ReadPrec [CreateUserGroup]
-> Read CreateUserGroup
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateUserGroup]
$creadListPrec :: ReadPrec [CreateUserGroup]
readPrec :: ReadPrec CreateUserGroup
$creadPrec :: ReadPrec CreateUserGroup
readList :: ReadS [CreateUserGroup]
$creadList :: ReadS [CreateUserGroup]
readsPrec :: Int -> ReadS CreateUserGroup
$creadsPrec :: Int -> ReadS CreateUserGroup
Prelude.Read, Int -> CreateUserGroup -> ShowS
[CreateUserGroup] -> ShowS
CreateUserGroup -> String
(Int -> CreateUserGroup -> ShowS)
-> (CreateUserGroup -> String)
-> ([CreateUserGroup] -> ShowS)
-> Show CreateUserGroup
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateUserGroup] -> ShowS
$cshowList :: [CreateUserGroup] -> ShowS
show :: CreateUserGroup -> String
$cshow :: CreateUserGroup -> String
showsPrec :: Int -> CreateUserGroup -> ShowS
$cshowsPrec :: Int -> CreateUserGroup -> ShowS
Prelude.Show, (forall x. CreateUserGroup -> Rep CreateUserGroup x)
-> (forall x. Rep CreateUserGroup x -> CreateUserGroup)
-> Generic CreateUserGroup
forall x. Rep CreateUserGroup x -> CreateUserGroup
forall x. CreateUserGroup -> Rep CreateUserGroup x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateUserGroup x -> CreateUserGroup
$cfrom :: forall x. CreateUserGroup -> Rep CreateUserGroup x
Prelude.Generic)

-- |
-- Create a value of 'CreateUserGroup' 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:
--
-- 'userIds', 'createUserGroup_userIds' - The list of user IDs that belong to the user group.
--
-- 'tags', 'createUserGroup_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.
--
-- 'userGroupId', 'createUserGroup_userGroupId' - The ID of the user group.
--
-- 'engine', 'createUserGroup_engine' - The current supported value is Redis.
newCreateUserGroup ::
  -- | 'userGroupId'
  Prelude.Text ->
  -- | 'engine'
  Prelude.Text ->
  CreateUserGroup
newCreateUserGroup :: Text -> Text -> CreateUserGroup
newCreateUserGroup Text
pUserGroupId_ Text
pEngine_ =
  CreateUserGroup' :: Maybe (NonEmpty Text)
-> Maybe [Tag] -> Text -> Text -> CreateUserGroup
CreateUserGroup'
    { $sel:userIds:CreateUserGroup' :: Maybe (NonEmpty Text)
userIds = Maybe (NonEmpty Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:tags:CreateUserGroup' :: Maybe [Tag]
tags = Maybe [Tag]
forall a. Maybe a
Prelude.Nothing,
      $sel:userGroupId:CreateUserGroup' :: Text
userGroupId = Text
pUserGroupId_,
      $sel:engine:CreateUserGroup' :: Text
engine = Text
pEngine_
    }

-- | The list of user IDs that belong to the user group.
createUserGroup_userIds :: Lens.Lens' CreateUserGroup (Prelude.Maybe (Prelude.NonEmpty Prelude.Text))
createUserGroup_userIds :: (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> CreateUserGroup -> f CreateUserGroup
createUserGroup_userIds = (CreateUserGroup -> Maybe (NonEmpty Text))
-> (CreateUserGroup -> Maybe (NonEmpty Text) -> CreateUserGroup)
-> Lens
     CreateUserGroup
     CreateUserGroup
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateUserGroup' {Maybe (NonEmpty Text)
userIds :: Maybe (NonEmpty Text)
$sel:userIds:CreateUserGroup' :: CreateUserGroup -> Maybe (NonEmpty Text)
userIds} -> Maybe (NonEmpty Text)
userIds) (\s :: CreateUserGroup
s@CreateUserGroup' {} Maybe (NonEmpty Text)
a -> CreateUserGroup
s {$sel:userIds:CreateUserGroup' :: Maybe (NonEmpty Text)
userIds = Maybe (NonEmpty Text)
a} :: CreateUserGroup) ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
 -> CreateUserGroup -> f CreateUserGroup)
-> ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
    -> Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> CreateUserGroup
-> f CreateUserGroup
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.
createUserGroup_tags :: Lens.Lens' CreateUserGroup (Prelude.Maybe [Tag])
createUserGroup_tags :: (Maybe [Tag] -> f (Maybe [Tag]))
-> CreateUserGroup -> f CreateUserGroup
createUserGroup_tags = (CreateUserGroup -> Maybe [Tag])
-> (CreateUserGroup -> Maybe [Tag] -> CreateUserGroup)
-> Lens CreateUserGroup CreateUserGroup (Maybe [Tag]) (Maybe [Tag])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateUserGroup' {Maybe [Tag]
tags :: Maybe [Tag]
$sel:tags:CreateUserGroup' :: CreateUserGroup -> Maybe [Tag]
tags} -> Maybe [Tag]
tags) (\s :: CreateUserGroup
s@CreateUserGroup' {} Maybe [Tag]
a -> CreateUserGroup
s {$sel:tags:CreateUserGroup' :: Maybe [Tag]
tags = Maybe [Tag]
a} :: CreateUserGroup) ((Maybe [Tag] -> f (Maybe [Tag]))
 -> CreateUserGroup -> f CreateUserGroup)
-> ((Maybe [Tag] -> f (Maybe [Tag]))
    -> Maybe [Tag] -> f (Maybe [Tag]))
-> (Maybe [Tag] -> f (Maybe [Tag]))
-> CreateUserGroup
-> f CreateUserGroup
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 ID of the user group.
createUserGroup_userGroupId :: Lens.Lens' CreateUserGroup Prelude.Text
createUserGroup_userGroupId :: (Text -> f Text) -> CreateUserGroup -> f CreateUserGroup
createUserGroup_userGroupId = (CreateUserGroup -> Text)
-> (CreateUserGroup -> Text -> CreateUserGroup)
-> Lens CreateUserGroup CreateUserGroup Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateUserGroup' {Text
userGroupId :: Text
$sel:userGroupId:CreateUserGroup' :: CreateUserGroup -> Text
userGroupId} -> Text
userGroupId) (\s :: CreateUserGroup
s@CreateUserGroup' {} Text
a -> CreateUserGroup
s {$sel:userGroupId:CreateUserGroup' :: Text
userGroupId = Text
a} :: CreateUserGroup)

-- | The current supported value is Redis.
createUserGroup_engine :: Lens.Lens' CreateUserGroup Prelude.Text
createUserGroup_engine :: (Text -> f Text) -> CreateUserGroup -> f CreateUserGroup
createUserGroup_engine = (CreateUserGroup -> Text)
-> (CreateUserGroup -> Text -> CreateUserGroup)
-> Lens CreateUserGroup CreateUserGroup Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateUserGroup' {Text
engine :: Text
$sel:engine:CreateUserGroup' :: CreateUserGroup -> Text
engine} -> Text
engine) (\s :: CreateUserGroup
s@CreateUserGroup' {} Text
a -> CreateUserGroup
s {$sel:engine:CreateUserGroup' :: Text
engine = Text
a} :: CreateUserGroup)

instance Core.AWSRequest CreateUserGroup where
  type AWSResponse CreateUserGroup = UserGroup
  request :: CreateUserGroup -> Request CreateUserGroup
request = Service -> CreateUserGroup -> Request CreateUserGroup
forall a. ToRequest a => Service -> a -> Request a
Request.postQuery Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateUserGroup
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateUserGroup)))
response =
    Text
-> (Int
    -> ResponseHeaders
    -> [Node]
    -> Either String (AWSResponse CreateUserGroup))
-> Logger
-> Service
-> Proxy CreateUserGroup
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateUserGroup)))
forall (m :: * -> *) a.
MonadResource m =>
Text
-> (Int
    -> ResponseHeaders -> [Node] -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveXMLWrapper
      Text
"CreateUserGroupResult"
      (\Int
s ResponseHeaders
h [Node]
x -> [Node] -> Either String UserGroup
forall a. FromXML a => [Node] -> Either String a
Core.parseXML [Node]
x)

instance Prelude.Hashable CreateUserGroup

instance Prelude.NFData CreateUserGroup

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

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

instance Core.ToQuery CreateUserGroup where
  toQuery :: CreateUserGroup -> QueryString
toQuery CreateUserGroup' {Maybe [Tag]
Maybe (NonEmpty Text)
Text
engine :: Text
userGroupId :: Text
tags :: Maybe [Tag]
userIds :: Maybe (NonEmpty Text)
$sel:engine:CreateUserGroup' :: CreateUserGroup -> Text
$sel:userGroupId:CreateUserGroup' :: CreateUserGroup -> Text
$sel:tags:CreateUserGroup' :: CreateUserGroup -> Maybe [Tag]
$sel:userIds:CreateUserGroup' :: CreateUserGroup -> Maybe (NonEmpty Text)
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Action"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"CreateUserGroup" :: Prelude.ByteString),
        ByteString
"Version"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"2015-02-02" :: Prelude.ByteString),
        ByteString
"UserIds"
          ByteString -> QueryString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe QueryString -> QueryString
forall a. ToQuery a => a -> QueryString
Core.toQuery
            (ByteString -> NonEmpty Text -> QueryString
forall a.
(IsList a, ToQuery (Item a)) =>
ByteString -> a -> QueryString
Core.toQueryList ByteString
"member" (NonEmpty Text -> QueryString)
-> Maybe (NonEmpty Text) -> Maybe QueryString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty Text)
userIds),
        ByteString
"Tags"
          ByteString -> QueryString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe QueryString -> QueryString
forall a. ToQuery a => a -> QueryString
Core.toQuery
            (ByteString -> [Tag] -> QueryString
forall a.
(IsList a, ToQuery (Item a)) =>
ByteString -> a -> QueryString
Core.toQueryList ByteString
"Tag" ([Tag] -> QueryString) -> Maybe [Tag] -> Maybe QueryString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Tag]
tags),
        ByteString
"UserGroupId" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
userGroupId,
        ByteString
"Engine" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
engine
      ]