{-# 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.ModifyUser
-- 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)
--
-- Changes user password(s) and\/or access string.
module Amazonka.ElastiCache.ModifyUser
  ( -- * Creating a Request
    ModifyUser (..),
    newModifyUser,

    -- * Request Lenses
    modifyUser_appendAccessString,
    modifyUser_accessString,
    modifyUser_passwords,
    modifyUser_noPasswordRequired,
    modifyUser_userId,

    -- * Destructuring the Response
    User (..),
    newUser,

    -- * Response Lenses
    user_status,
    user_arn,
    user_userGroupIds,
    user_authentication,
    user_engine,
    user_userName,
    user_accessString,
    user_userId,
  )
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:/ 'newModifyUser' smart constructor.
data ModifyUser = ModifyUser'
  { -- | Adds additional user permissions to the access string.
    ModifyUser -> Maybe Text
appendAccessString :: Prelude.Maybe Prelude.Text,
    -- | Access permissions string used for this user.
    ModifyUser -> Maybe Text
accessString :: Prelude.Maybe Prelude.Text,
    -- | The passwords belonging to the user. You are allowed up to two.
    ModifyUser -> Maybe (NonEmpty Text)
passwords :: Prelude.Maybe (Prelude.NonEmpty Prelude.Text),
    -- | Indicates no password is required for the user.
    ModifyUser -> Maybe Bool
noPasswordRequired :: Prelude.Maybe Prelude.Bool,
    -- | The ID of the user.
    ModifyUser -> Text
userId :: Prelude.Text
  }
  deriving (ModifyUser -> ModifyUser -> Bool
(ModifyUser -> ModifyUser -> Bool)
-> (ModifyUser -> ModifyUser -> Bool) -> Eq ModifyUser
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ModifyUser -> ModifyUser -> Bool
$c/= :: ModifyUser -> ModifyUser -> Bool
== :: ModifyUser -> ModifyUser -> Bool
$c== :: ModifyUser -> ModifyUser -> Bool
Prelude.Eq, ReadPrec [ModifyUser]
ReadPrec ModifyUser
Int -> ReadS ModifyUser
ReadS [ModifyUser]
(Int -> ReadS ModifyUser)
-> ReadS [ModifyUser]
-> ReadPrec ModifyUser
-> ReadPrec [ModifyUser]
-> Read ModifyUser
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ModifyUser]
$creadListPrec :: ReadPrec [ModifyUser]
readPrec :: ReadPrec ModifyUser
$creadPrec :: ReadPrec ModifyUser
readList :: ReadS [ModifyUser]
$creadList :: ReadS [ModifyUser]
readsPrec :: Int -> ReadS ModifyUser
$creadsPrec :: Int -> ReadS ModifyUser
Prelude.Read, Int -> ModifyUser -> ShowS
[ModifyUser] -> ShowS
ModifyUser -> String
(Int -> ModifyUser -> ShowS)
-> (ModifyUser -> String)
-> ([ModifyUser] -> ShowS)
-> Show ModifyUser
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ModifyUser] -> ShowS
$cshowList :: [ModifyUser] -> ShowS
show :: ModifyUser -> String
$cshow :: ModifyUser -> String
showsPrec :: Int -> ModifyUser -> ShowS
$cshowsPrec :: Int -> ModifyUser -> ShowS
Prelude.Show, (forall x. ModifyUser -> Rep ModifyUser x)
-> (forall x. Rep ModifyUser x -> ModifyUser) -> Generic ModifyUser
forall x. Rep ModifyUser x -> ModifyUser
forall x. ModifyUser -> Rep ModifyUser x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ModifyUser x -> ModifyUser
$cfrom :: forall x. ModifyUser -> Rep ModifyUser x
Prelude.Generic)

-- |
-- Create a value of 'ModifyUser' 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:
--
-- 'appendAccessString', 'modifyUser_appendAccessString' - Adds additional user permissions to the access string.
--
-- 'accessString', 'modifyUser_accessString' - Access permissions string used for this user.
--
-- 'passwords', 'modifyUser_passwords' - The passwords belonging to the user. You are allowed up to two.
--
-- 'noPasswordRequired', 'modifyUser_noPasswordRequired' - Indicates no password is required for the user.
--
-- 'userId', 'modifyUser_userId' - The ID of the user.
newModifyUser ::
  -- | 'userId'
  Prelude.Text ->
  ModifyUser
newModifyUser :: Text -> ModifyUser
newModifyUser Text
pUserId_ =
  ModifyUser' :: Maybe Text
-> Maybe Text
-> Maybe (NonEmpty Text)
-> Maybe Bool
-> Text
-> ModifyUser
ModifyUser'
    { $sel:appendAccessString:ModifyUser' :: Maybe Text
appendAccessString = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:accessString:ModifyUser' :: Maybe Text
accessString = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:passwords:ModifyUser' :: Maybe (NonEmpty Text)
passwords = Maybe (NonEmpty Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:noPasswordRequired:ModifyUser' :: Maybe Bool
noPasswordRequired = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:userId:ModifyUser' :: Text
userId = Text
pUserId_
    }

-- | Adds additional user permissions to the access string.
modifyUser_appendAccessString :: Lens.Lens' ModifyUser (Prelude.Maybe Prelude.Text)
modifyUser_appendAccessString :: (Maybe Text -> f (Maybe Text)) -> ModifyUser -> f ModifyUser
modifyUser_appendAccessString = (ModifyUser -> Maybe Text)
-> (ModifyUser -> Maybe Text -> ModifyUser)
-> Lens ModifyUser ModifyUser (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ModifyUser' {Maybe Text
appendAccessString :: Maybe Text
$sel:appendAccessString:ModifyUser' :: ModifyUser -> Maybe Text
appendAccessString} -> Maybe Text
appendAccessString) (\s :: ModifyUser
s@ModifyUser' {} Maybe Text
a -> ModifyUser
s {$sel:appendAccessString:ModifyUser' :: Maybe Text
appendAccessString = Maybe Text
a} :: ModifyUser)

-- | Access permissions string used for this user.
modifyUser_accessString :: Lens.Lens' ModifyUser (Prelude.Maybe Prelude.Text)
modifyUser_accessString :: (Maybe Text -> f (Maybe Text)) -> ModifyUser -> f ModifyUser
modifyUser_accessString = (ModifyUser -> Maybe Text)
-> (ModifyUser -> Maybe Text -> ModifyUser)
-> Lens ModifyUser ModifyUser (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ModifyUser' {Maybe Text
accessString :: Maybe Text
$sel:accessString:ModifyUser' :: ModifyUser -> Maybe Text
accessString} -> Maybe Text
accessString) (\s :: ModifyUser
s@ModifyUser' {} Maybe Text
a -> ModifyUser
s {$sel:accessString:ModifyUser' :: Maybe Text
accessString = Maybe Text
a} :: ModifyUser)

-- | The passwords belonging to the user. You are allowed up to two.
modifyUser_passwords :: Lens.Lens' ModifyUser (Prelude.Maybe (Prelude.NonEmpty Prelude.Text))
modifyUser_passwords :: (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> ModifyUser -> f ModifyUser
modifyUser_passwords = (ModifyUser -> Maybe (NonEmpty Text))
-> (ModifyUser -> Maybe (NonEmpty Text) -> ModifyUser)
-> Lens
     ModifyUser
     ModifyUser
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ModifyUser' {Maybe (NonEmpty Text)
passwords :: Maybe (NonEmpty Text)
$sel:passwords:ModifyUser' :: ModifyUser -> Maybe (NonEmpty Text)
passwords} -> Maybe (NonEmpty Text)
passwords) (\s :: ModifyUser
s@ModifyUser' {} Maybe (NonEmpty Text)
a -> ModifyUser
s {$sel:passwords:ModifyUser' :: Maybe (NonEmpty Text)
passwords = Maybe (NonEmpty Text)
a} :: ModifyUser) ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
 -> ModifyUser -> f ModifyUser)
-> ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
    -> Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> ModifyUser
-> f ModifyUser
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

-- | Indicates no password is required for the user.
modifyUser_noPasswordRequired :: Lens.Lens' ModifyUser (Prelude.Maybe Prelude.Bool)
modifyUser_noPasswordRequired :: (Maybe Bool -> f (Maybe Bool)) -> ModifyUser -> f ModifyUser
modifyUser_noPasswordRequired = (ModifyUser -> Maybe Bool)
-> (ModifyUser -> Maybe Bool -> ModifyUser)
-> Lens ModifyUser ModifyUser (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ModifyUser' {Maybe Bool
noPasswordRequired :: Maybe Bool
$sel:noPasswordRequired:ModifyUser' :: ModifyUser -> Maybe Bool
noPasswordRequired} -> Maybe Bool
noPasswordRequired) (\s :: ModifyUser
s@ModifyUser' {} Maybe Bool
a -> ModifyUser
s {$sel:noPasswordRequired:ModifyUser' :: Maybe Bool
noPasswordRequired = Maybe Bool
a} :: ModifyUser)

-- | The ID of the user.
modifyUser_userId :: Lens.Lens' ModifyUser Prelude.Text
modifyUser_userId :: (Text -> f Text) -> ModifyUser -> f ModifyUser
modifyUser_userId = (ModifyUser -> Text)
-> (ModifyUser -> Text -> ModifyUser)
-> Lens ModifyUser ModifyUser Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ModifyUser' {Text
userId :: Text
$sel:userId:ModifyUser' :: ModifyUser -> Text
userId} -> Text
userId) (\s :: ModifyUser
s@ModifyUser' {} Text
a -> ModifyUser
s {$sel:userId:ModifyUser' :: Text
userId = Text
a} :: ModifyUser)

instance Core.AWSRequest ModifyUser where
  type AWSResponse ModifyUser = User
  request :: ModifyUser -> Request ModifyUser
request = Service -> ModifyUser -> Request ModifyUser
forall a. ToRequest a => Service -> a -> Request a
Request.postQuery Service
defaultService
  response :: Logger
-> Service
-> Proxy ModifyUser
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ModifyUser)))
response =
    Text
-> (Int
    -> ResponseHeaders
    -> [Node]
    -> Either String (AWSResponse ModifyUser))
-> Logger
-> Service
-> Proxy ModifyUser
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ModifyUser)))
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
"ModifyUserResult"
      (\Int
s ResponseHeaders
h [Node]
x -> [Node] -> Either String User
forall a. FromXML a => [Node] -> Either String a
Core.parseXML [Node]
x)

instance Prelude.Hashable ModifyUser

instance Prelude.NFData ModifyUser

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

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

instance Core.ToQuery ModifyUser where
  toQuery :: ModifyUser -> QueryString
toQuery ModifyUser' {Maybe Bool
Maybe (NonEmpty Text)
Maybe Text
Text
userId :: Text
noPasswordRequired :: Maybe Bool
passwords :: Maybe (NonEmpty Text)
accessString :: Maybe Text
appendAccessString :: Maybe Text
$sel:userId:ModifyUser' :: ModifyUser -> Text
$sel:noPasswordRequired:ModifyUser' :: ModifyUser -> Maybe Bool
$sel:passwords:ModifyUser' :: ModifyUser -> Maybe (NonEmpty Text)
$sel:accessString:ModifyUser' :: ModifyUser -> Maybe Text
$sel:appendAccessString:ModifyUser' :: ModifyUser -> Maybe 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
"ModifyUser" :: Prelude.ByteString),
        ByteString
"Version"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"2015-02-02" :: Prelude.ByteString),
        ByteString
"AppendAccessString" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
appendAccessString,
        ByteString
"AccessString" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
accessString,
        ByteString
"Passwords"
          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)
passwords),
        ByteString
"NoPasswordRequired" ByteString -> Maybe Bool -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Bool
noPasswordRequired,
        ByteString
"UserId" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
userId
      ]