{-# 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.UpdateAccessKey
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Changes the status of the specified access key from Active to Inactive,
-- or vice versa. This operation can be used to disable a user\'s key as
-- part of a key rotation workflow.
--
-- If the @UserName@ is not specified, the user name is determined
-- implicitly based on the Amazon Web Services access key ID used to sign
-- the request. If a temporary access key is used, then @UserName@ is
-- required. If a long-term key is assigned to the user, then @UserName@ is
-- not required. This operation works for access keys under the Amazon Web
-- Services account. Consequently, you can use this operation to manage
-- Amazon Web Services account root user credentials even if the Amazon Web
-- Services account has no associated users.
--
-- For information about rotating keys, see
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/ManagingCredentials.html Managing keys and certificates>
-- in the /IAM User Guide/.
module Amazonka.IAM.UpdateAccessKey
  ( -- * Creating a Request
    UpdateAccessKey (..),
    newUpdateAccessKey,

    -- * Request Lenses
    updateAccessKey_userName,
    updateAccessKey_accessKeyId,
    updateAccessKey_status,

    -- * Destructuring the Response
    UpdateAccessKeyResponse (..),
    newUpdateAccessKeyResponse,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.IAM.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newUpdateAccessKey' smart constructor.
data UpdateAccessKey = UpdateAccessKey'
  { -- | The name of the user whose key you want to update.
    --
    -- This parameter allows (through its
    -- <http://wikipedia.org/wiki/regex regex pattern>) a string of characters
    -- consisting of upper and lowercase alphanumeric characters with no
    -- spaces. You can also include any of the following characters: _+=,.\@-
    UpdateAccessKey -> Maybe Text
userName :: Prelude.Maybe Prelude.Text,
    -- | The access key ID of the secret access key you want to update.
    --
    -- This parameter allows (through its
    -- <http://wikipedia.org/wiki/regex regex pattern>) a string of characters
    -- that can consist of any upper or lowercased letter or digit.
    UpdateAccessKey -> AccessKey
accessKeyId :: Core.AccessKey,
    -- | The status you want to assign to the secret access key. @Active@ means
    -- that the key can be used for programmatic calls to Amazon Web Services,
    -- while @Inactive@ means that the key cannot be used.
    UpdateAccessKey -> StatusType
status :: StatusType
  }
  deriving (UpdateAccessKey -> UpdateAccessKey -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateAccessKey -> UpdateAccessKey -> Bool
$c/= :: UpdateAccessKey -> UpdateAccessKey -> Bool
== :: UpdateAccessKey -> UpdateAccessKey -> Bool
$c== :: UpdateAccessKey -> UpdateAccessKey -> Bool
Prelude.Eq, ReadPrec [UpdateAccessKey]
ReadPrec UpdateAccessKey
Int -> ReadS UpdateAccessKey
ReadS [UpdateAccessKey]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateAccessKey]
$creadListPrec :: ReadPrec [UpdateAccessKey]
readPrec :: ReadPrec UpdateAccessKey
$creadPrec :: ReadPrec UpdateAccessKey
readList :: ReadS [UpdateAccessKey]
$creadList :: ReadS [UpdateAccessKey]
readsPrec :: Int -> ReadS UpdateAccessKey
$creadsPrec :: Int -> ReadS UpdateAccessKey
Prelude.Read, Int -> UpdateAccessKey -> ShowS
[UpdateAccessKey] -> ShowS
UpdateAccessKey -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateAccessKey] -> ShowS
$cshowList :: [UpdateAccessKey] -> ShowS
show :: UpdateAccessKey -> String
$cshow :: UpdateAccessKey -> String
showsPrec :: Int -> UpdateAccessKey -> ShowS
$cshowsPrec :: Int -> UpdateAccessKey -> ShowS
Prelude.Show, forall x. Rep UpdateAccessKey x -> UpdateAccessKey
forall x. UpdateAccessKey -> Rep UpdateAccessKey x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpdateAccessKey x -> UpdateAccessKey
$cfrom :: forall x. UpdateAccessKey -> Rep UpdateAccessKey x
Prelude.Generic)

-- |
-- Create a value of 'UpdateAccessKey' 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:
--
-- 'userName', 'updateAccessKey_userName' - The name of the user whose key you want to update.
--
-- This parameter allows (through its
-- <http://wikipedia.org/wiki/regex regex pattern>) a string of characters
-- consisting of upper and lowercase alphanumeric characters with no
-- spaces. You can also include any of the following characters: _+=,.\@-
--
-- 'accessKeyId', 'updateAccessKey_accessKeyId' - The access key ID of the secret access key you want to update.
--
-- This parameter allows (through its
-- <http://wikipedia.org/wiki/regex regex pattern>) a string of characters
-- that can consist of any upper or lowercased letter or digit.
--
-- 'status', 'updateAccessKey_status' - The status you want to assign to the secret access key. @Active@ means
-- that the key can be used for programmatic calls to Amazon Web Services,
-- while @Inactive@ means that the key cannot be used.
newUpdateAccessKey ::
  -- | 'accessKeyId'
  Core.AccessKey ->
  -- | 'status'
  StatusType ->
  UpdateAccessKey
newUpdateAccessKey :: AccessKey -> StatusType -> UpdateAccessKey
newUpdateAccessKey AccessKey
pAccessKeyId_ StatusType
pStatus_ =
  UpdateAccessKey'
    { $sel:userName:UpdateAccessKey' :: Maybe Text
userName = forall a. Maybe a
Prelude.Nothing,
      $sel:accessKeyId:UpdateAccessKey' :: AccessKey
accessKeyId = AccessKey
pAccessKeyId_,
      $sel:status:UpdateAccessKey' :: StatusType
status = StatusType
pStatus_
    }

-- | The name of the user whose key you want to update.
--
-- This parameter allows (through its
-- <http://wikipedia.org/wiki/regex regex pattern>) a string of characters
-- consisting of upper and lowercase alphanumeric characters with no
-- spaces. You can also include any of the following characters: _+=,.\@-
updateAccessKey_userName :: Lens.Lens' UpdateAccessKey (Prelude.Maybe Prelude.Text)
updateAccessKey_userName :: Lens' UpdateAccessKey (Maybe Text)
updateAccessKey_userName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateAccessKey' {Maybe Text
userName :: Maybe Text
$sel:userName:UpdateAccessKey' :: UpdateAccessKey -> Maybe Text
userName} -> Maybe Text
userName) (\s :: UpdateAccessKey
s@UpdateAccessKey' {} Maybe Text
a -> UpdateAccessKey
s {$sel:userName:UpdateAccessKey' :: Maybe Text
userName = Maybe Text
a} :: UpdateAccessKey)

-- | The access key ID of the secret access key you want to update.
--
-- This parameter allows (through its
-- <http://wikipedia.org/wiki/regex regex pattern>) a string of characters
-- that can consist of any upper or lowercased letter or digit.
updateAccessKey_accessKeyId :: Lens.Lens' UpdateAccessKey Core.AccessKey
updateAccessKey_accessKeyId :: Lens' UpdateAccessKey AccessKey
updateAccessKey_accessKeyId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateAccessKey' {AccessKey
accessKeyId :: AccessKey
$sel:accessKeyId:UpdateAccessKey' :: UpdateAccessKey -> AccessKey
accessKeyId} -> AccessKey
accessKeyId) (\s :: UpdateAccessKey
s@UpdateAccessKey' {} AccessKey
a -> UpdateAccessKey
s {$sel:accessKeyId:UpdateAccessKey' :: AccessKey
accessKeyId = AccessKey
a} :: UpdateAccessKey)

-- | The status you want to assign to the secret access key. @Active@ means
-- that the key can be used for programmatic calls to Amazon Web Services,
-- while @Inactive@ means that the key cannot be used.
updateAccessKey_status :: Lens.Lens' UpdateAccessKey StatusType
updateAccessKey_status :: Lens' UpdateAccessKey StatusType
updateAccessKey_status = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateAccessKey' {StatusType
status :: StatusType
$sel:status:UpdateAccessKey' :: UpdateAccessKey -> StatusType
status} -> StatusType
status) (\s :: UpdateAccessKey
s@UpdateAccessKey' {} StatusType
a -> UpdateAccessKey
s {$sel:status:UpdateAccessKey' :: StatusType
status = StatusType
a} :: UpdateAccessKey)

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

instance Prelude.Hashable UpdateAccessKey where
  hashWithSalt :: Int -> UpdateAccessKey -> Int
hashWithSalt Int
_salt UpdateAccessKey' {Maybe Text
AccessKey
StatusType
status :: StatusType
accessKeyId :: AccessKey
userName :: Maybe Text
$sel:status:UpdateAccessKey' :: UpdateAccessKey -> StatusType
$sel:accessKeyId:UpdateAccessKey' :: UpdateAccessKey -> AccessKey
$sel:userName:UpdateAccessKey' :: UpdateAccessKey -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
userName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` AccessKey
accessKeyId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` StatusType
status

instance Prelude.NFData UpdateAccessKey where
  rnf :: UpdateAccessKey -> ()
rnf UpdateAccessKey' {Maybe Text
AccessKey
StatusType
status :: StatusType
accessKeyId :: AccessKey
userName :: Maybe Text
$sel:status:UpdateAccessKey' :: UpdateAccessKey -> StatusType
$sel:accessKeyId:UpdateAccessKey' :: UpdateAccessKey -> AccessKey
$sel:userName:UpdateAccessKey' :: UpdateAccessKey -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
userName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf AccessKey
accessKeyId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf StatusType
status

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

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

instance Data.ToQuery UpdateAccessKey where
  toQuery :: UpdateAccessKey -> QueryString
toQuery UpdateAccessKey' {Maybe Text
AccessKey
StatusType
status :: StatusType
accessKeyId :: AccessKey
userName :: Maybe Text
$sel:status:UpdateAccessKey' :: UpdateAccessKey -> StatusType
$sel:accessKeyId:UpdateAccessKey' :: UpdateAccessKey -> AccessKey
$sel:userName:UpdateAccessKey' :: UpdateAccessKey -> Maybe Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Action"
          forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: (ByteString
"UpdateAccessKey" :: Prelude.ByteString),
        ByteString
"Version"
          forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: (ByteString
"2010-05-08" :: Prelude.ByteString),
        ByteString
"UserName" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Text
userName,
        ByteString
"AccessKeyId" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: AccessKey
accessKeyId,
        ByteString
"Status" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: StatusType
status
      ]

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

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

instance Prelude.NFData UpdateAccessKeyResponse where
  rnf :: UpdateAccessKeyResponse -> ()
rnf UpdateAccessKeyResponse
_ = ()