{-# 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.IAM.ChangePassword
-- 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 the password of the IAM user who is calling this operation. This
-- operation can be performed using the CLI, the Amazon Web Services API,
-- or the __My Security Credentials__ page in the Amazon Web Services
-- Management Console. The Amazon Web Services account root user password
-- is not affected by this operation.
--
-- Use UpdateLoginProfile to use the CLI, the Amazon Web Services API, or
-- the __Users__ page in the IAM console to change the password for any IAM
-- user. For more information about modifying passwords, see
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/Using_ManagingLogins.html Managing passwords>
-- in the /IAM User Guide/.
module Amazonka.IAM.ChangePassword
  ( -- * Creating a Request
    ChangePassword (..),
    newChangePassword,

    -- * Request Lenses
    changePassword_oldPassword,
    changePassword_newPassword,

    -- * Destructuring the Response
    ChangePasswordResponse (..),
    newChangePasswordResponse,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.IAM.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:/ 'newChangePassword' smart constructor.
data ChangePassword = ChangePassword'
  { -- | The IAM user\'s current password.
    ChangePassword -> Sensitive Text
oldPassword :: Core.Sensitive Prelude.Text,
    -- | The new password. The new password must conform to the Amazon Web
    -- Services account\'s password policy, if one exists.
    --
    -- The <http://wikipedia.org/wiki/regex regex pattern> that is used to
    -- validate this parameter is a string of characters. That string can
    -- include almost any printable ASCII character from the space (@\\u0020@)
    -- through the end of the ASCII character range (@\\u00FF@). You can also
    -- include the tab (@\\u0009@), line feed (@\\u000A@), and carriage return
    -- (@\\u000D@) characters. Any of these characters are valid in a password.
    -- However, many tools, such as the Amazon Web Services Management Console,
    -- might restrict the ability to type certain characters because they have
    -- special meaning within that tool.
    ChangePassword -> Sensitive Text
newPassword' :: Core.Sensitive Prelude.Text
  }
  deriving (ChangePassword -> ChangePassword -> Bool
(ChangePassword -> ChangePassword -> Bool)
-> (ChangePassword -> ChangePassword -> Bool) -> Eq ChangePassword
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ChangePassword -> ChangePassword -> Bool
$c/= :: ChangePassword -> ChangePassword -> Bool
== :: ChangePassword -> ChangePassword -> Bool
$c== :: ChangePassword -> ChangePassword -> Bool
Prelude.Eq, Int -> ChangePassword -> ShowS
[ChangePassword] -> ShowS
ChangePassword -> String
(Int -> ChangePassword -> ShowS)
-> (ChangePassword -> String)
-> ([ChangePassword] -> ShowS)
-> Show ChangePassword
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ChangePassword] -> ShowS
$cshowList :: [ChangePassword] -> ShowS
show :: ChangePassword -> String
$cshow :: ChangePassword -> String
showsPrec :: Int -> ChangePassword -> ShowS
$cshowsPrec :: Int -> ChangePassword -> ShowS
Prelude.Show, (forall x. ChangePassword -> Rep ChangePassword x)
-> (forall x. Rep ChangePassword x -> ChangePassword)
-> Generic ChangePassword
forall x. Rep ChangePassword x -> ChangePassword
forall x. ChangePassword -> Rep ChangePassword x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ChangePassword x -> ChangePassword
$cfrom :: forall x. ChangePassword -> Rep ChangePassword x
Prelude.Generic)

-- |
-- Create a value of 'ChangePassword' 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:
--
-- 'oldPassword', 'changePassword_oldPassword' - The IAM user\'s current password.
--
-- 'newPassword'', 'changePassword_newPassword' - The new password. The new password must conform to the Amazon Web
-- Services account\'s password policy, if one exists.
--
-- The <http://wikipedia.org/wiki/regex regex pattern> that is used to
-- validate this parameter is a string of characters. That string can
-- include almost any printable ASCII character from the space (@\\u0020@)
-- through the end of the ASCII character range (@\\u00FF@). You can also
-- include the tab (@\\u0009@), line feed (@\\u000A@), and carriage return
-- (@\\u000D@) characters. Any of these characters are valid in a password.
-- However, many tools, such as the Amazon Web Services Management Console,
-- might restrict the ability to type certain characters because they have
-- special meaning within that tool.
newChangePassword ::
  -- | 'oldPassword'
  Prelude.Text ->
  -- | 'newPassword''
  Prelude.Text ->
  ChangePassword
newChangePassword :: Text -> Text -> ChangePassword
newChangePassword Text
pOldPassword_ Text
pNewPassword_ =
  ChangePassword' :: Sensitive Text -> Sensitive Text -> ChangePassword
ChangePassword'
    { $sel:oldPassword:ChangePassword' :: Sensitive Text
oldPassword =
        Tagged Text (Identity Text)
-> Tagged (Sensitive Text) (Identity (Sensitive Text))
forall a. Iso' (Sensitive a) a
Core._Sensitive (Tagged Text (Identity Text)
 -> Tagged (Sensitive Text) (Identity (Sensitive Text)))
-> Text -> Sensitive Text
forall t b. AReview t b -> b -> t
Lens.# Text
pOldPassword_,
      $sel:newPassword':ChangePassword' :: Sensitive Text
newPassword' = Tagged Text (Identity Text)
-> Tagged (Sensitive Text) (Identity (Sensitive Text))
forall a. Iso' (Sensitive a) a
Core._Sensitive (Tagged Text (Identity Text)
 -> Tagged (Sensitive Text) (Identity (Sensitive Text)))
-> Text -> Sensitive Text
forall t b. AReview t b -> b -> t
Lens.# Text
pNewPassword_
    }

-- | The IAM user\'s current password.
changePassword_oldPassword :: Lens.Lens' ChangePassword Prelude.Text
changePassword_oldPassword :: (Text -> f Text) -> ChangePassword -> f ChangePassword
changePassword_oldPassword = (ChangePassword -> Sensitive Text)
-> (ChangePassword -> Sensitive Text -> ChangePassword)
-> Lens
     ChangePassword ChangePassword (Sensitive Text) (Sensitive Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ChangePassword' {Sensitive Text
oldPassword :: Sensitive Text
$sel:oldPassword:ChangePassword' :: ChangePassword -> Sensitive Text
oldPassword} -> Sensitive Text
oldPassword) (\s :: ChangePassword
s@ChangePassword' {} Sensitive Text
a -> ChangePassword
s {$sel:oldPassword:ChangePassword' :: Sensitive Text
oldPassword = Sensitive Text
a} :: ChangePassword) ((Sensitive Text -> f (Sensitive Text))
 -> ChangePassword -> f ChangePassword)
-> ((Text -> f Text) -> Sensitive Text -> f (Sensitive Text))
-> (Text -> f Text)
-> ChangePassword
-> f ChangePassword
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (Text -> f Text) -> Sensitive Text -> f (Sensitive Text)
forall a. Iso' (Sensitive a) a
Core._Sensitive

-- | The new password. The new password must conform to the Amazon Web
-- Services account\'s password policy, if one exists.
--
-- The <http://wikipedia.org/wiki/regex regex pattern> that is used to
-- validate this parameter is a string of characters. That string can
-- include almost any printable ASCII character from the space (@\\u0020@)
-- through the end of the ASCII character range (@\\u00FF@). You can also
-- include the tab (@\\u0009@), line feed (@\\u000A@), and carriage return
-- (@\\u000D@) characters. Any of these characters are valid in a password.
-- However, many tools, such as the Amazon Web Services Management Console,
-- might restrict the ability to type certain characters because they have
-- special meaning within that tool.
changePassword_newPassword :: Lens.Lens' ChangePassword Prelude.Text
changePassword_newPassword :: (Text -> f Text) -> ChangePassword -> f ChangePassword
changePassword_newPassword = (ChangePassword -> Sensitive Text)
-> (ChangePassword -> Sensitive Text -> ChangePassword)
-> Lens
     ChangePassword ChangePassword (Sensitive Text) (Sensitive Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ChangePassword' {Sensitive Text
newPassword' :: Sensitive Text
$sel:newPassword':ChangePassword' :: ChangePassword -> Sensitive Text
newPassword'} -> Sensitive Text
newPassword') (\s :: ChangePassword
s@ChangePassword' {} Sensitive Text
a -> ChangePassword
s {$sel:newPassword':ChangePassword' :: Sensitive Text
newPassword' = Sensitive Text
a} :: ChangePassword) ((Sensitive Text -> f (Sensitive Text))
 -> ChangePassword -> f ChangePassword)
-> ((Text -> f Text) -> Sensitive Text -> f (Sensitive Text))
-> (Text -> f Text)
-> ChangePassword
-> f ChangePassword
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (Text -> f Text) -> Sensitive Text -> f (Sensitive Text)
forall a. Iso' (Sensitive a) a
Core._Sensitive

instance Core.AWSRequest ChangePassword where
  type
    AWSResponse ChangePassword =
      ChangePasswordResponse
  request :: ChangePassword -> Request ChangePassword
request = Service -> ChangePassword -> Request ChangePassword
forall a. ToRequest a => Service -> a -> Request a
Request.postQuery Service
defaultService
  response :: Logger
-> Service
-> Proxy ChangePassword
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ChangePassword)))
response =
    AWSResponse ChangePassword
-> Logger
-> Service
-> Proxy ChangePassword
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ChangePassword)))
forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull AWSResponse ChangePassword
ChangePasswordResponse
ChangePasswordResponse'

instance Prelude.Hashable ChangePassword

instance Prelude.NFData ChangePassword

instance Core.ToHeaders ChangePassword where
  toHeaders :: ChangePassword -> [Header]
toHeaders = [Header] -> ChangePassword -> [Header]
forall a b. a -> b -> a
Prelude.const [Header]
forall a. Monoid a => a
Prelude.mempty

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

instance Core.ToQuery ChangePassword where
  toQuery :: ChangePassword -> QueryString
toQuery ChangePassword' {Sensitive Text
newPassword' :: Sensitive Text
oldPassword :: Sensitive Text
$sel:newPassword':ChangePassword' :: ChangePassword -> Sensitive Text
$sel:oldPassword:ChangePassword' :: ChangePassword -> Sensitive 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
"ChangePassword" :: Prelude.ByteString),
        ByteString
"Version"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"2010-05-08" :: Prelude.ByteString),
        ByteString
"OldPassword" ByteString -> Sensitive Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Sensitive Text
oldPassword,
        ByteString
"NewPassword" ByteString -> Sensitive Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Sensitive Text
newPassword'
      ]

-- | /See:/ 'newChangePasswordResponse' smart constructor.
data ChangePasswordResponse = ChangePasswordResponse'
  {
  }
  deriving (ChangePasswordResponse -> ChangePasswordResponse -> Bool
(ChangePasswordResponse -> ChangePasswordResponse -> Bool)
-> (ChangePasswordResponse -> ChangePasswordResponse -> Bool)
-> Eq ChangePasswordResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ChangePasswordResponse -> ChangePasswordResponse -> Bool
$c/= :: ChangePasswordResponse -> ChangePasswordResponse -> Bool
== :: ChangePasswordResponse -> ChangePasswordResponse -> Bool
$c== :: ChangePasswordResponse -> ChangePasswordResponse -> Bool
Prelude.Eq, ReadPrec [ChangePasswordResponse]
ReadPrec ChangePasswordResponse
Int -> ReadS ChangePasswordResponse
ReadS [ChangePasswordResponse]
(Int -> ReadS ChangePasswordResponse)
-> ReadS [ChangePasswordResponse]
-> ReadPrec ChangePasswordResponse
-> ReadPrec [ChangePasswordResponse]
-> Read ChangePasswordResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ChangePasswordResponse]
$creadListPrec :: ReadPrec [ChangePasswordResponse]
readPrec :: ReadPrec ChangePasswordResponse
$creadPrec :: ReadPrec ChangePasswordResponse
readList :: ReadS [ChangePasswordResponse]
$creadList :: ReadS [ChangePasswordResponse]
readsPrec :: Int -> ReadS ChangePasswordResponse
$creadsPrec :: Int -> ReadS ChangePasswordResponse
Prelude.Read, Int -> ChangePasswordResponse -> ShowS
[ChangePasswordResponse] -> ShowS
ChangePasswordResponse -> String
(Int -> ChangePasswordResponse -> ShowS)
-> (ChangePasswordResponse -> String)
-> ([ChangePasswordResponse] -> ShowS)
-> Show ChangePasswordResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ChangePasswordResponse] -> ShowS
$cshowList :: [ChangePasswordResponse] -> ShowS
show :: ChangePasswordResponse -> String
$cshow :: ChangePasswordResponse -> String
showsPrec :: Int -> ChangePasswordResponse -> ShowS
$cshowsPrec :: Int -> ChangePasswordResponse -> ShowS
Prelude.Show, (forall x. ChangePasswordResponse -> Rep ChangePasswordResponse x)
-> (forall x.
    Rep ChangePasswordResponse x -> ChangePasswordResponse)
-> Generic ChangePasswordResponse
forall x. Rep ChangePasswordResponse x -> ChangePasswordResponse
forall x. ChangePasswordResponse -> Rep ChangePasswordResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ChangePasswordResponse x -> ChangePasswordResponse
$cfrom :: forall x. ChangePasswordResponse -> Rep ChangePasswordResponse x
Prelude.Generic)

-- |
-- Create a value of 'ChangePasswordResponse' 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.
newChangePasswordResponse ::
  ChangePasswordResponse
newChangePasswordResponse :: ChangePasswordResponse
newChangePasswordResponse = ChangePasswordResponse
ChangePasswordResponse'

instance Prelude.NFData ChangePasswordResponse