{-# 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-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 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. 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 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:/ '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
(UpdateAccessKey -> UpdateAccessKey -> Bool)
-> (UpdateAccessKey -> UpdateAccessKey -> Bool)
-> Eq UpdateAccessKey
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]
(Int -> ReadS UpdateAccessKey)
-> ReadS [UpdateAccessKey]
-> ReadPrec UpdateAccessKey
-> ReadPrec [UpdateAccessKey]
-> Read 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
(Int -> UpdateAccessKey -> ShowS)
-> (UpdateAccessKey -> String)
-> ([UpdateAccessKey] -> ShowS)
-> Show UpdateAccessKey
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. UpdateAccessKey -> Rep UpdateAccessKey x)
-> (forall x. Rep UpdateAccessKey x -> UpdateAccessKey)
-> Generic UpdateAccessKey
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' :: Maybe Text -> AccessKey -> StatusType -> UpdateAccessKey
UpdateAccessKey'
    { $sel:userName:UpdateAccessKey' :: Maybe Text
userName = Maybe Text
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 :: (Maybe Text -> f (Maybe Text))
-> UpdateAccessKey -> f UpdateAccessKey
updateAccessKey_userName = (UpdateAccessKey -> Maybe Text)
-> (UpdateAccessKey -> Maybe Text -> UpdateAccessKey)
-> Lens UpdateAccessKey UpdateAccessKey (Maybe Text) (Maybe Text)
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 :: (AccessKey -> f AccessKey) -> UpdateAccessKey -> f UpdateAccessKey
updateAccessKey_accessKeyId = (UpdateAccessKey -> AccessKey)
-> (UpdateAccessKey -> AccessKey -> UpdateAccessKey)
-> Lens UpdateAccessKey UpdateAccessKey AccessKey AccessKey
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 :: (StatusType -> f StatusType)
-> UpdateAccessKey -> f UpdateAccessKey
updateAccessKey_status = (UpdateAccessKey -> StatusType)
-> (UpdateAccessKey -> StatusType -> UpdateAccessKey)
-> Lens UpdateAccessKey UpdateAccessKey StatusType StatusType
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 :: UpdateAccessKey -> Request UpdateAccessKey
request = Service -> UpdateAccessKey -> Request UpdateAccessKey
forall a. ToRequest a => Service -> a -> Request a
Request.postQuery Service
defaultService
  response :: Logger
-> Service
-> Proxy UpdateAccessKey
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse UpdateAccessKey)))
response =
    AWSResponse UpdateAccessKey
-> Logger
-> Service
-> Proxy UpdateAccessKey
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse UpdateAccessKey)))
forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull AWSResponse UpdateAccessKey
UpdateAccessKeyResponse
UpdateAccessKeyResponse'

instance Prelude.Hashable UpdateAccessKey

instance Prelude.NFData UpdateAccessKey

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

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

instance Core.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
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Action"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"UpdateAccessKey" :: Prelude.ByteString),
        ByteString
"Version"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"2010-05-08" :: Prelude.ByteString),
        ByteString
"UserName" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
userName,
        ByteString
"AccessKeyId" ByteString -> AccessKey -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: AccessKey
accessKeyId,
        ByteString
"Status" ByteString -> StatusType -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: StatusType
status
      ]

-- | /See:/ 'newUpdateAccessKeyResponse' smart constructor.
data UpdateAccessKeyResponse = UpdateAccessKeyResponse'
  {
  }
  deriving (UpdateAccessKeyResponse -> UpdateAccessKeyResponse -> Bool
(UpdateAccessKeyResponse -> UpdateAccessKeyResponse -> Bool)
-> (UpdateAccessKeyResponse -> UpdateAccessKeyResponse -> Bool)
-> Eq UpdateAccessKeyResponse
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]
(Int -> ReadS UpdateAccessKeyResponse)
-> ReadS [UpdateAccessKeyResponse]
-> ReadPrec UpdateAccessKeyResponse
-> ReadPrec [UpdateAccessKeyResponse]
-> Read 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
(Int -> UpdateAccessKeyResponse -> ShowS)
-> (UpdateAccessKeyResponse -> String)
-> ([UpdateAccessKeyResponse] -> ShowS)
-> Show UpdateAccessKeyResponse
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.
 UpdateAccessKeyResponse -> Rep UpdateAccessKeyResponse x)
-> (forall x.
    Rep UpdateAccessKeyResponse x -> UpdateAccessKeyResponse)
-> Generic UpdateAccessKeyResponse
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