{-# 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.DirectoryService.ResetUserPassword
-- 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)
--
-- Resets the password for any user in your Managed Microsoft AD or Simple
-- AD directory.
--
-- You can reset the password for any user in your directory with the
-- following exceptions:
--
-- -   For Simple AD, you cannot reset the password for any user that is a
--     member of either the __Domain Admins__ or __Enterprise Admins__
--     group except for the administrator user.
--
-- -   For Managed Microsoft AD, you can only reset the password for a user
--     that is in an OU based off of the NetBIOS name that you typed when
--     you created your directory. For example, you cannot reset the
--     password for a user in the __Amazon Web Services Reserved__ OU. For
--     more information about the OU structure for an Managed Microsoft AD
--     directory, see
--     <https://docs.aws.amazon.com/directoryservice/latest/admin-guide/ms_ad_getting_started_what_gets_created.html What Gets Created>
--     in the /Directory Service Administration Guide/.
module Amazonka.DirectoryService.ResetUserPassword
  ( -- * Creating a Request
    ResetUserPassword (..),
    newResetUserPassword,

    -- * Request Lenses
    resetUserPassword_directoryId,
    resetUserPassword_userName,
    resetUserPassword_newPassword,

    -- * Destructuring the Response
    ResetUserPasswordResponse (..),
    newResetUserPasswordResponse,

    -- * Response Lenses
    resetUserPasswordResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.DirectoryService.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:/ 'newResetUserPassword' smart constructor.
data ResetUserPassword = ResetUserPassword'
  { -- | Identifier of the Managed Microsoft AD or Simple AD directory in which
    -- the user resides.
    ResetUserPassword -> Text
directoryId :: Prelude.Text,
    -- | The user name of the user whose password will be reset.
    ResetUserPassword -> Text
userName :: Prelude.Text,
    -- | The new password that will be reset.
    ResetUserPassword -> Sensitive Text
newPassword' :: Core.Sensitive Prelude.Text
  }
  deriving (ResetUserPassword -> ResetUserPassword -> Bool
(ResetUserPassword -> ResetUserPassword -> Bool)
-> (ResetUserPassword -> ResetUserPassword -> Bool)
-> Eq ResetUserPassword
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ResetUserPassword -> ResetUserPassword -> Bool
$c/= :: ResetUserPassword -> ResetUserPassword -> Bool
== :: ResetUserPassword -> ResetUserPassword -> Bool
$c== :: ResetUserPassword -> ResetUserPassword -> Bool
Prelude.Eq, Int -> ResetUserPassword -> ShowS
[ResetUserPassword] -> ShowS
ResetUserPassword -> String
(Int -> ResetUserPassword -> ShowS)
-> (ResetUserPassword -> String)
-> ([ResetUserPassword] -> ShowS)
-> Show ResetUserPassword
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ResetUserPassword] -> ShowS
$cshowList :: [ResetUserPassword] -> ShowS
show :: ResetUserPassword -> String
$cshow :: ResetUserPassword -> String
showsPrec :: Int -> ResetUserPassword -> ShowS
$cshowsPrec :: Int -> ResetUserPassword -> ShowS
Prelude.Show, (forall x. ResetUserPassword -> Rep ResetUserPassword x)
-> (forall x. Rep ResetUserPassword x -> ResetUserPassword)
-> Generic ResetUserPassword
forall x. Rep ResetUserPassword x -> ResetUserPassword
forall x. ResetUserPassword -> Rep ResetUserPassword x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ResetUserPassword x -> ResetUserPassword
$cfrom :: forall x. ResetUserPassword -> Rep ResetUserPassword x
Prelude.Generic)

-- |
-- Create a value of 'ResetUserPassword' 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:
--
-- 'directoryId', 'resetUserPassword_directoryId' - Identifier of the Managed Microsoft AD or Simple AD directory in which
-- the user resides.
--
-- 'userName', 'resetUserPassword_userName' - The user name of the user whose password will be reset.
--
-- 'newPassword'', 'resetUserPassword_newPassword' - The new password that will be reset.
newResetUserPassword ::
  -- | 'directoryId'
  Prelude.Text ->
  -- | 'userName'
  Prelude.Text ->
  -- | 'newPassword''
  Prelude.Text ->
  ResetUserPassword
newResetUserPassword :: Text -> Text -> Text -> ResetUserPassword
newResetUserPassword
  Text
pDirectoryId_
  Text
pUserName_
  Text
pNewPassword_ =
    ResetUserPassword' :: Text -> Text -> Sensitive Text -> ResetUserPassword
ResetUserPassword'
      { $sel:directoryId:ResetUserPassword' :: Text
directoryId = Text
pDirectoryId_,
        $sel:userName:ResetUserPassword' :: Text
userName = Text
pUserName_,
        $sel:newPassword':ResetUserPassword' :: 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_
      }

-- | Identifier of the Managed Microsoft AD or Simple AD directory in which
-- the user resides.
resetUserPassword_directoryId :: Lens.Lens' ResetUserPassword Prelude.Text
resetUserPassword_directoryId :: (Text -> f Text) -> ResetUserPassword -> f ResetUserPassword
resetUserPassword_directoryId = (ResetUserPassword -> Text)
-> (ResetUserPassword -> Text -> ResetUserPassword)
-> Lens ResetUserPassword ResetUserPassword Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResetUserPassword' {Text
directoryId :: Text
$sel:directoryId:ResetUserPassword' :: ResetUserPassword -> Text
directoryId} -> Text
directoryId) (\s :: ResetUserPassword
s@ResetUserPassword' {} Text
a -> ResetUserPassword
s {$sel:directoryId:ResetUserPassword' :: Text
directoryId = Text
a} :: ResetUserPassword)

-- | The user name of the user whose password will be reset.
resetUserPassword_userName :: Lens.Lens' ResetUserPassword Prelude.Text
resetUserPassword_userName :: (Text -> f Text) -> ResetUserPassword -> f ResetUserPassword
resetUserPassword_userName = (ResetUserPassword -> Text)
-> (ResetUserPassword -> Text -> ResetUserPassword)
-> Lens ResetUserPassword ResetUserPassword Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResetUserPassword' {Text
userName :: Text
$sel:userName:ResetUserPassword' :: ResetUserPassword -> Text
userName} -> Text
userName) (\s :: ResetUserPassword
s@ResetUserPassword' {} Text
a -> ResetUserPassword
s {$sel:userName:ResetUserPassword' :: Text
userName = Text
a} :: ResetUserPassword)

-- | The new password that will be reset.
resetUserPassword_newPassword :: Lens.Lens' ResetUserPassword Prelude.Text
resetUserPassword_newPassword :: (Text -> f Text) -> ResetUserPassword -> f ResetUserPassword
resetUserPassword_newPassword = (ResetUserPassword -> Sensitive Text)
-> (ResetUserPassword -> Sensitive Text -> ResetUserPassword)
-> Lens
     ResetUserPassword
     ResetUserPassword
     (Sensitive Text)
     (Sensitive Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResetUserPassword' {Sensitive Text
newPassword' :: Sensitive Text
$sel:newPassword':ResetUserPassword' :: ResetUserPassword -> Sensitive Text
newPassword'} -> Sensitive Text
newPassword') (\s :: ResetUserPassword
s@ResetUserPassword' {} Sensitive Text
a -> ResetUserPassword
s {$sel:newPassword':ResetUserPassword' :: Sensitive Text
newPassword' = Sensitive Text
a} :: ResetUserPassword) ((Sensitive Text -> f (Sensitive Text))
 -> ResetUserPassword -> f ResetUserPassword)
-> ((Text -> f Text) -> Sensitive Text -> f (Sensitive Text))
-> (Text -> f Text)
-> ResetUserPassword
-> f ResetUserPassword
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 ResetUserPassword where
  type
    AWSResponse ResetUserPassword =
      ResetUserPasswordResponse
  request :: ResetUserPassword -> Request ResetUserPassword
request = Service -> ResetUserPassword -> Request ResetUserPassword
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy ResetUserPassword
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse ResetUserPassword)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse ResetUserPassword))
-> Logger
-> Service
-> Proxy ResetUserPassword
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse ResetUserPassword)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> ResetUserPasswordResponse
ResetUserPasswordResponse'
            (Int -> ResetUserPasswordResponse)
-> Either String Int -> Either String ResetUserPasswordResponse
forall (f :: * -> *) a b. Functor 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 ResetUserPassword

instance Prelude.NFData ResetUserPassword

instance Core.ToHeaders ResetUserPassword where
  toHeaders :: ResetUserPassword -> ResponseHeaders
toHeaders =
    ResponseHeaders -> ResetUserPassword -> 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
"DirectoryService_20150416.ResetUserPassword" ::
                          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 ResetUserPassword where
  toJSON :: ResetUserPassword -> Value
toJSON ResetUserPassword' {Text
Sensitive Text
newPassword' :: Sensitive Text
userName :: Text
directoryId :: Text
$sel:newPassword':ResetUserPassword' :: ResetUserPassword -> Sensitive Text
$sel:userName:ResetUserPassword' :: ResetUserPassword -> Text
$sel:directoryId:ResetUserPassword' :: ResetUserPassword -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"DirectoryId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
directoryId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"UserName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
userName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"NewPassword" Text -> Sensitive Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Sensitive Text
newPassword')
          ]
      )

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

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

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

-- |
-- Create a value of 'ResetUserPasswordResponse' 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:
--
-- 'httpStatus', 'resetUserPasswordResponse_httpStatus' - The response's http status code.
newResetUserPasswordResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ResetUserPasswordResponse
newResetUserPasswordResponse :: Int -> ResetUserPasswordResponse
newResetUserPasswordResponse Int
pHttpStatus_ =
  ResetUserPasswordResponse' :: Int -> ResetUserPasswordResponse
ResetUserPasswordResponse'
    { $sel:httpStatus:ResetUserPasswordResponse' :: Int
httpStatus =
        Int
pHttpStatus_
    }

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

instance Prelude.NFData ResetUserPasswordResponse