{-# 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.CreateAccessKey
-- 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)
--
-- Creates a new Amazon Web Services secret access key and corresponding
-- Amazon Web Services access key ID for the specified user. The default
-- status for new keys is @Active@.
--
-- If you do not specify a user name, IAM determines the user name
-- implicitly based on the Amazon Web Services access key ID signing 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. This is true even if
-- the Amazon Web Services account has no associated users.
--
-- For information about quotas on the number of keys you can create, see
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_iam-quotas.html IAM and STS quotas>
-- in the /IAM User Guide/.
--
-- To ensure the security of your Amazon Web Services account, the secret
-- access key is accessible only during key and user creation. You must
-- save the key (for example, in a text file) if you want to be able to
-- access it again. If a secret key is lost, you can delete the access keys
-- for the associated user and then create new keys.
module Amazonka.IAM.CreateAccessKey
  ( -- * Creating a Request
    CreateAccessKey (..),
    newCreateAccessKey,

    -- * Request Lenses
    createAccessKey_userName,

    -- * Destructuring the Response
    CreateAccessKeyResponse (..),
    newCreateAccessKeyResponse,

    -- * Response Lenses
    createAccessKeyResponse_httpStatus,
    createAccessKeyResponse_accessKey,
  )
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:/ 'newCreateAccessKey' smart constructor.
data CreateAccessKey = CreateAccessKey'
  { -- | The name of the IAM user that the new key will belong to.
    --
    -- 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: _+=,.\@-
    CreateAccessKey -> Maybe Text
userName :: Prelude.Maybe Prelude.Text
  }
  deriving (CreateAccessKey -> CreateAccessKey -> Bool
(CreateAccessKey -> CreateAccessKey -> Bool)
-> (CreateAccessKey -> CreateAccessKey -> Bool)
-> Eq CreateAccessKey
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateAccessKey -> CreateAccessKey -> Bool
$c/= :: CreateAccessKey -> CreateAccessKey -> Bool
== :: CreateAccessKey -> CreateAccessKey -> Bool
$c== :: CreateAccessKey -> CreateAccessKey -> Bool
Prelude.Eq, ReadPrec [CreateAccessKey]
ReadPrec CreateAccessKey
Int -> ReadS CreateAccessKey
ReadS [CreateAccessKey]
(Int -> ReadS CreateAccessKey)
-> ReadS [CreateAccessKey]
-> ReadPrec CreateAccessKey
-> ReadPrec [CreateAccessKey]
-> Read CreateAccessKey
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateAccessKey]
$creadListPrec :: ReadPrec [CreateAccessKey]
readPrec :: ReadPrec CreateAccessKey
$creadPrec :: ReadPrec CreateAccessKey
readList :: ReadS [CreateAccessKey]
$creadList :: ReadS [CreateAccessKey]
readsPrec :: Int -> ReadS CreateAccessKey
$creadsPrec :: Int -> ReadS CreateAccessKey
Prelude.Read, Int -> CreateAccessKey -> ShowS
[CreateAccessKey] -> ShowS
CreateAccessKey -> String
(Int -> CreateAccessKey -> ShowS)
-> (CreateAccessKey -> String)
-> ([CreateAccessKey] -> ShowS)
-> Show CreateAccessKey
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateAccessKey] -> ShowS
$cshowList :: [CreateAccessKey] -> ShowS
show :: CreateAccessKey -> String
$cshow :: CreateAccessKey -> String
showsPrec :: Int -> CreateAccessKey -> ShowS
$cshowsPrec :: Int -> CreateAccessKey -> ShowS
Prelude.Show, (forall x. CreateAccessKey -> Rep CreateAccessKey x)
-> (forall x. Rep CreateAccessKey x -> CreateAccessKey)
-> Generic CreateAccessKey
forall x. Rep CreateAccessKey x -> CreateAccessKey
forall x. CreateAccessKey -> Rep CreateAccessKey x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateAccessKey x -> CreateAccessKey
$cfrom :: forall x. CreateAccessKey -> Rep CreateAccessKey x
Prelude.Generic)

-- |
-- Create a value of 'CreateAccessKey' 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', 'createAccessKey_userName' - The name of the IAM user that the new key will belong to.
--
-- 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: _+=,.\@-
newCreateAccessKey ::
  CreateAccessKey
newCreateAccessKey :: CreateAccessKey
newCreateAccessKey =
  CreateAccessKey' :: Maybe Text -> CreateAccessKey
CreateAccessKey' {$sel:userName:CreateAccessKey' :: Maybe Text
userName = Maybe Text
forall a. Maybe a
Prelude.Nothing}

-- | The name of the IAM user that the new key will belong to.
--
-- 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: _+=,.\@-
createAccessKey_userName :: Lens.Lens' CreateAccessKey (Prelude.Maybe Prelude.Text)
createAccessKey_userName :: (Maybe Text -> f (Maybe Text))
-> CreateAccessKey -> f CreateAccessKey
createAccessKey_userName = (CreateAccessKey -> Maybe Text)
-> (CreateAccessKey -> Maybe Text -> CreateAccessKey)
-> Lens CreateAccessKey CreateAccessKey (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateAccessKey' {Maybe Text
userName :: Maybe Text
$sel:userName:CreateAccessKey' :: CreateAccessKey -> Maybe Text
userName} -> Maybe Text
userName) (\s :: CreateAccessKey
s@CreateAccessKey' {} Maybe Text
a -> CreateAccessKey
s {$sel:userName:CreateAccessKey' :: Maybe Text
userName = Maybe Text
a} :: CreateAccessKey)

instance Core.AWSRequest CreateAccessKey where
  type
    AWSResponse CreateAccessKey =
      CreateAccessKeyResponse
  request :: CreateAccessKey -> Request CreateAccessKey
request = Service -> CreateAccessKey -> Request CreateAccessKey
forall a. ToRequest a => Service -> a -> Request a
Request.postQuery Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateAccessKey
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateAccessKey)))
response =
    Text
-> (Int
    -> ResponseHeaders
    -> [Node]
    -> Either String (AWSResponse CreateAccessKey))
-> Logger
-> Service
-> Proxy CreateAccessKey
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateAccessKey)))
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
"CreateAccessKeyResult"
      ( \Int
s ResponseHeaders
h [Node]
x ->
          Int -> AccessKeyInfo -> CreateAccessKeyResponse
CreateAccessKeyResponse'
            (Int -> AccessKeyInfo -> CreateAccessKeyResponse)
-> Either String Int
-> Either String (AccessKeyInfo -> CreateAccessKeyResponse)
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))
            Either String (AccessKeyInfo -> CreateAccessKeyResponse)
-> Either String AccessKeyInfo
-> Either String CreateAccessKeyResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String AccessKeyInfo
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"AccessKey")
      )

instance Prelude.Hashable CreateAccessKey

instance Prelude.NFData CreateAccessKey

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

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

instance Core.ToQuery CreateAccessKey where
  toQuery :: CreateAccessKey -> QueryString
toQuery CreateAccessKey' {Maybe Text
userName :: Maybe Text
$sel:userName:CreateAccessKey' :: CreateAccessKey -> 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
"CreateAccessKey" :: 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
      ]

-- | Contains the response to a successful CreateAccessKey request.
--
-- /See:/ 'newCreateAccessKeyResponse' smart constructor.
data CreateAccessKeyResponse = CreateAccessKeyResponse'
  { -- | The response's http status code.
    CreateAccessKeyResponse -> Int
httpStatus :: Prelude.Int,
    -- | A structure with details about the access key.
    CreateAccessKeyResponse -> AccessKeyInfo
accessKey :: AccessKeyInfo
  }
  deriving (CreateAccessKeyResponse -> CreateAccessKeyResponse -> Bool
(CreateAccessKeyResponse -> CreateAccessKeyResponse -> Bool)
-> (CreateAccessKeyResponse -> CreateAccessKeyResponse -> Bool)
-> Eq CreateAccessKeyResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateAccessKeyResponse -> CreateAccessKeyResponse -> Bool
$c/= :: CreateAccessKeyResponse -> CreateAccessKeyResponse -> Bool
== :: CreateAccessKeyResponse -> CreateAccessKeyResponse -> Bool
$c== :: CreateAccessKeyResponse -> CreateAccessKeyResponse -> Bool
Prelude.Eq, Int -> CreateAccessKeyResponse -> ShowS
[CreateAccessKeyResponse] -> ShowS
CreateAccessKeyResponse -> String
(Int -> CreateAccessKeyResponse -> ShowS)
-> (CreateAccessKeyResponse -> String)
-> ([CreateAccessKeyResponse] -> ShowS)
-> Show CreateAccessKeyResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateAccessKeyResponse] -> ShowS
$cshowList :: [CreateAccessKeyResponse] -> ShowS
show :: CreateAccessKeyResponse -> String
$cshow :: CreateAccessKeyResponse -> String
showsPrec :: Int -> CreateAccessKeyResponse -> ShowS
$cshowsPrec :: Int -> CreateAccessKeyResponse -> ShowS
Prelude.Show, (forall x.
 CreateAccessKeyResponse -> Rep CreateAccessKeyResponse x)
-> (forall x.
    Rep CreateAccessKeyResponse x -> CreateAccessKeyResponse)
-> Generic CreateAccessKeyResponse
forall x. Rep CreateAccessKeyResponse x -> CreateAccessKeyResponse
forall x. CreateAccessKeyResponse -> Rep CreateAccessKeyResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateAccessKeyResponse x -> CreateAccessKeyResponse
$cfrom :: forall x. CreateAccessKeyResponse -> Rep CreateAccessKeyResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreateAccessKeyResponse' 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', 'createAccessKeyResponse_httpStatus' - The response's http status code.
--
-- 'accessKey', 'createAccessKeyResponse_accessKey' - A structure with details about the access key.
newCreateAccessKeyResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'accessKey'
  AccessKeyInfo ->
  CreateAccessKeyResponse
newCreateAccessKeyResponse :: Int -> AccessKeyInfo -> CreateAccessKeyResponse
newCreateAccessKeyResponse Int
pHttpStatus_ AccessKeyInfo
pAccessKey_ =
  CreateAccessKeyResponse' :: Int -> AccessKeyInfo -> CreateAccessKeyResponse
CreateAccessKeyResponse'
    { $sel:httpStatus:CreateAccessKeyResponse' :: Int
httpStatus = Int
pHttpStatus_,
      $sel:accessKey:CreateAccessKeyResponse' :: AccessKeyInfo
accessKey = AccessKeyInfo
pAccessKey_
    }

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

-- | A structure with details about the access key.
createAccessKeyResponse_accessKey :: Lens.Lens' CreateAccessKeyResponse AccessKeyInfo
createAccessKeyResponse_accessKey :: (AccessKeyInfo -> f AccessKeyInfo)
-> CreateAccessKeyResponse -> f CreateAccessKeyResponse
createAccessKeyResponse_accessKey = (CreateAccessKeyResponse -> AccessKeyInfo)
-> (CreateAccessKeyResponse
    -> AccessKeyInfo -> CreateAccessKeyResponse)
-> Lens
     CreateAccessKeyResponse
     CreateAccessKeyResponse
     AccessKeyInfo
     AccessKeyInfo
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateAccessKeyResponse' {AccessKeyInfo
accessKey :: AccessKeyInfo
$sel:accessKey:CreateAccessKeyResponse' :: CreateAccessKeyResponse -> AccessKeyInfo
accessKey} -> AccessKeyInfo
accessKey) (\s :: CreateAccessKeyResponse
s@CreateAccessKeyResponse' {} AccessKeyInfo
a -> CreateAccessKeyResponse
s {$sel:accessKey:CreateAccessKeyResponse' :: AccessKeyInfo
accessKey = AccessKeyInfo
a} :: CreateAccessKeyResponse)

instance Prelude.NFData CreateAccessKeyResponse