{-# 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.UploadSSHPublicKey
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Uploads an SSH public key and associates it with the specified IAM user.
--
-- The SSH public key uploaded by this operation can be used only for
-- authenticating the associated IAM user to an CodeCommit repository. For
-- more information about using SSH keys to authenticate to an CodeCommit
-- repository, see
-- <https://docs.aws.amazon.com/codecommit/latest/userguide/setting-up-credentials-ssh.html Set up CodeCommit for SSH connections>
-- in the /CodeCommit User Guide/.
module Amazonka.IAM.UploadSSHPublicKey
  ( -- * Creating a Request
    UploadSSHPublicKey (..),
    newUploadSSHPublicKey,

    -- * Request Lenses
    uploadSSHPublicKey_userName,
    uploadSSHPublicKey_sSHPublicKeyBody,

    -- * Destructuring the Response
    UploadSSHPublicKeyResponse (..),
    newUploadSSHPublicKeyResponse,

    -- * Response Lenses
    uploadSSHPublicKeyResponse_sSHPublicKey,
    uploadSSHPublicKeyResponse_httpStatus,
  )
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:/ 'newUploadSSHPublicKey' smart constructor.
data UploadSSHPublicKey = UploadSSHPublicKey'
  { -- | The name of the IAM user to associate the SSH public key with.
    --
    -- 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: _+=,.\@-
    UploadSSHPublicKey -> Text
userName :: Prelude.Text,
    -- | The SSH public key. The public key must be encoded in ssh-rsa format or
    -- PEM format. The minimum bit-length of the public key is 2048 bits. For
    -- example, you can generate a 2048-bit key, and the resulting PEM file is
    -- 1679 bytes long.
    --
    -- The <http://wikipedia.org/wiki/regex regex pattern> used to validate
    -- this parameter is a string of characters consisting of the following:
    --
    -- -   Any printable ASCII character ranging from the space character
    --     (@\\u0020@) through the end of the ASCII character range
    --
    -- -   The printable characters in the Basic Latin and Latin-1 Supplement
    --     character set (through @\\u00FF@)
    --
    -- -   The special characters tab (@\\u0009@), line feed (@\\u000A@), and
    --     carriage return (@\\u000D@)
    UploadSSHPublicKey -> Text
sSHPublicKeyBody :: Prelude.Text
  }
  deriving (UploadSSHPublicKey -> UploadSSHPublicKey -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UploadSSHPublicKey -> UploadSSHPublicKey -> Bool
$c/= :: UploadSSHPublicKey -> UploadSSHPublicKey -> Bool
== :: UploadSSHPublicKey -> UploadSSHPublicKey -> Bool
$c== :: UploadSSHPublicKey -> UploadSSHPublicKey -> Bool
Prelude.Eq, ReadPrec [UploadSSHPublicKey]
ReadPrec UploadSSHPublicKey
Int -> ReadS UploadSSHPublicKey
ReadS [UploadSSHPublicKey]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UploadSSHPublicKey]
$creadListPrec :: ReadPrec [UploadSSHPublicKey]
readPrec :: ReadPrec UploadSSHPublicKey
$creadPrec :: ReadPrec UploadSSHPublicKey
readList :: ReadS [UploadSSHPublicKey]
$creadList :: ReadS [UploadSSHPublicKey]
readsPrec :: Int -> ReadS UploadSSHPublicKey
$creadsPrec :: Int -> ReadS UploadSSHPublicKey
Prelude.Read, Int -> UploadSSHPublicKey -> ShowS
[UploadSSHPublicKey] -> ShowS
UploadSSHPublicKey -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UploadSSHPublicKey] -> ShowS
$cshowList :: [UploadSSHPublicKey] -> ShowS
show :: UploadSSHPublicKey -> String
$cshow :: UploadSSHPublicKey -> String
showsPrec :: Int -> UploadSSHPublicKey -> ShowS
$cshowsPrec :: Int -> UploadSSHPublicKey -> ShowS
Prelude.Show, forall x. Rep UploadSSHPublicKey x -> UploadSSHPublicKey
forall x. UploadSSHPublicKey -> Rep UploadSSHPublicKey x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UploadSSHPublicKey x -> UploadSSHPublicKey
$cfrom :: forall x. UploadSSHPublicKey -> Rep UploadSSHPublicKey x
Prelude.Generic)

-- |
-- Create a value of 'UploadSSHPublicKey' 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', 'uploadSSHPublicKey_userName' - The name of the IAM user to associate the SSH public key with.
--
-- 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: _+=,.\@-
--
-- 'sSHPublicKeyBody', 'uploadSSHPublicKey_sSHPublicKeyBody' - The SSH public key. The public key must be encoded in ssh-rsa format or
-- PEM format. The minimum bit-length of the public key is 2048 bits. For
-- example, you can generate a 2048-bit key, and the resulting PEM file is
-- 1679 bytes long.
--
-- The <http://wikipedia.org/wiki/regex regex pattern> used to validate
-- this parameter is a string of characters consisting of the following:
--
-- -   Any printable ASCII character ranging from the space character
--     (@\\u0020@) through the end of the ASCII character range
--
-- -   The printable characters in the Basic Latin and Latin-1 Supplement
--     character set (through @\\u00FF@)
--
-- -   The special characters tab (@\\u0009@), line feed (@\\u000A@), and
--     carriage return (@\\u000D@)
newUploadSSHPublicKey ::
  -- | 'userName'
  Prelude.Text ->
  -- | 'sSHPublicKeyBody'
  Prelude.Text ->
  UploadSSHPublicKey
newUploadSSHPublicKey :: Text -> Text -> UploadSSHPublicKey
newUploadSSHPublicKey Text
pUserName_ Text
pSSHPublicKeyBody_ =
  UploadSSHPublicKey'
    { $sel:userName:UploadSSHPublicKey' :: Text
userName = Text
pUserName_,
      $sel:sSHPublicKeyBody:UploadSSHPublicKey' :: Text
sSHPublicKeyBody = Text
pSSHPublicKeyBody_
    }

-- | The name of the IAM user to associate the SSH public key with.
--
-- 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: _+=,.\@-
uploadSSHPublicKey_userName :: Lens.Lens' UploadSSHPublicKey Prelude.Text
uploadSSHPublicKey_userName :: Lens' UploadSSHPublicKey Text
uploadSSHPublicKey_userName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UploadSSHPublicKey' {Text
userName :: Text
$sel:userName:UploadSSHPublicKey' :: UploadSSHPublicKey -> Text
userName} -> Text
userName) (\s :: UploadSSHPublicKey
s@UploadSSHPublicKey' {} Text
a -> UploadSSHPublicKey
s {$sel:userName:UploadSSHPublicKey' :: Text
userName = Text
a} :: UploadSSHPublicKey)

-- | The SSH public key. The public key must be encoded in ssh-rsa format or
-- PEM format. The minimum bit-length of the public key is 2048 bits. For
-- example, you can generate a 2048-bit key, and the resulting PEM file is
-- 1679 bytes long.
--
-- The <http://wikipedia.org/wiki/regex regex pattern> used to validate
-- this parameter is a string of characters consisting of the following:
--
-- -   Any printable ASCII character ranging from the space character
--     (@\\u0020@) through the end of the ASCII character range
--
-- -   The printable characters in the Basic Latin and Latin-1 Supplement
--     character set (through @\\u00FF@)
--
-- -   The special characters tab (@\\u0009@), line feed (@\\u000A@), and
--     carriage return (@\\u000D@)
uploadSSHPublicKey_sSHPublicKeyBody :: Lens.Lens' UploadSSHPublicKey Prelude.Text
uploadSSHPublicKey_sSHPublicKeyBody :: Lens' UploadSSHPublicKey Text
uploadSSHPublicKey_sSHPublicKeyBody = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UploadSSHPublicKey' {Text
sSHPublicKeyBody :: Text
$sel:sSHPublicKeyBody:UploadSSHPublicKey' :: UploadSSHPublicKey -> Text
sSHPublicKeyBody} -> Text
sSHPublicKeyBody) (\s :: UploadSSHPublicKey
s@UploadSSHPublicKey' {} Text
a -> UploadSSHPublicKey
s {$sel:sSHPublicKeyBody:UploadSSHPublicKey' :: Text
sSHPublicKeyBody = Text
a} :: UploadSSHPublicKey)

instance Core.AWSRequest UploadSSHPublicKey where
  type
    AWSResponse UploadSSHPublicKey =
      UploadSSHPublicKeyResponse
  request :: (Service -> Service)
-> UploadSSHPublicKey -> Request UploadSSHPublicKey
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 UploadSSHPublicKey
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse UploadSSHPublicKey)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
Text
-> (Int
    -> ResponseHeaders -> [Node] -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveXMLWrapper
      Text
"UploadSSHPublicKeyResult"
      ( \Int
s ResponseHeaders
h [Node]
x ->
          Maybe SSHPublicKey -> Int -> UploadSSHPublicKeyResponse
UploadSSHPublicKeyResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"SSHPublicKey")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable UploadSSHPublicKey where
  hashWithSalt :: Int -> UploadSSHPublicKey -> Int
hashWithSalt Int
_salt UploadSSHPublicKey' {Text
sSHPublicKeyBody :: Text
userName :: Text
$sel:sSHPublicKeyBody:UploadSSHPublicKey' :: UploadSSHPublicKey -> Text
$sel:userName:UploadSSHPublicKey' :: UploadSSHPublicKey -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
userName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
sSHPublicKeyBody

instance Prelude.NFData UploadSSHPublicKey where
  rnf :: UploadSSHPublicKey -> ()
rnf UploadSSHPublicKey' {Text
sSHPublicKeyBody :: Text
userName :: Text
$sel:sSHPublicKeyBody:UploadSSHPublicKey' :: UploadSSHPublicKey -> Text
$sel:userName:UploadSSHPublicKey' :: UploadSSHPublicKey -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
userName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
sSHPublicKeyBody

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

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

instance Data.ToQuery UploadSSHPublicKey where
  toQuery :: UploadSSHPublicKey -> QueryString
toQuery UploadSSHPublicKey' {Text
sSHPublicKeyBody :: Text
userName :: Text
$sel:sSHPublicKeyBody:UploadSSHPublicKey' :: UploadSSHPublicKey -> Text
$sel:userName:UploadSSHPublicKey' :: UploadSSHPublicKey -> Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Action"
          forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: (ByteString
"UploadSSHPublicKey" :: 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.=: Text
userName,
        ByteString
"SSHPublicKeyBody" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Text
sSHPublicKeyBody
      ]

-- | Contains the response to a successful UploadSSHPublicKey request.
--
-- /See:/ 'newUploadSSHPublicKeyResponse' smart constructor.
data UploadSSHPublicKeyResponse = UploadSSHPublicKeyResponse'
  { -- | Contains information about the SSH public key.
    UploadSSHPublicKeyResponse -> Maybe SSHPublicKey
sSHPublicKey :: Prelude.Maybe SSHPublicKey,
    -- | The response's http status code.
    UploadSSHPublicKeyResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (UploadSSHPublicKeyResponse -> UploadSSHPublicKeyResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UploadSSHPublicKeyResponse -> UploadSSHPublicKeyResponse -> Bool
$c/= :: UploadSSHPublicKeyResponse -> UploadSSHPublicKeyResponse -> Bool
== :: UploadSSHPublicKeyResponse -> UploadSSHPublicKeyResponse -> Bool
$c== :: UploadSSHPublicKeyResponse -> UploadSSHPublicKeyResponse -> Bool
Prelude.Eq, ReadPrec [UploadSSHPublicKeyResponse]
ReadPrec UploadSSHPublicKeyResponse
Int -> ReadS UploadSSHPublicKeyResponse
ReadS [UploadSSHPublicKeyResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UploadSSHPublicKeyResponse]
$creadListPrec :: ReadPrec [UploadSSHPublicKeyResponse]
readPrec :: ReadPrec UploadSSHPublicKeyResponse
$creadPrec :: ReadPrec UploadSSHPublicKeyResponse
readList :: ReadS [UploadSSHPublicKeyResponse]
$creadList :: ReadS [UploadSSHPublicKeyResponse]
readsPrec :: Int -> ReadS UploadSSHPublicKeyResponse
$creadsPrec :: Int -> ReadS UploadSSHPublicKeyResponse
Prelude.Read, Int -> UploadSSHPublicKeyResponse -> ShowS
[UploadSSHPublicKeyResponse] -> ShowS
UploadSSHPublicKeyResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UploadSSHPublicKeyResponse] -> ShowS
$cshowList :: [UploadSSHPublicKeyResponse] -> ShowS
show :: UploadSSHPublicKeyResponse -> String
$cshow :: UploadSSHPublicKeyResponse -> String
showsPrec :: Int -> UploadSSHPublicKeyResponse -> ShowS
$cshowsPrec :: Int -> UploadSSHPublicKeyResponse -> ShowS
Prelude.Show, forall x.
Rep UploadSSHPublicKeyResponse x -> UploadSSHPublicKeyResponse
forall x.
UploadSSHPublicKeyResponse -> Rep UploadSSHPublicKeyResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep UploadSSHPublicKeyResponse x -> UploadSSHPublicKeyResponse
$cfrom :: forall x.
UploadSSHPublicKeyResponse -> Rep UploadSSHPublicKeyResponse x
Prelude.Generic)

-- |
-- Create a value of 'UploadSSHPublicKeyResponse' 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:
--
-- 'sSHPublicKey', 'uploadSSHPublicKeyResponse_sSHPublicKey' - Contains information about the SSH public key.
--
-- 'httpStatus', 'uploadSSHPublicKeyResponse_httpStatus' - The response's http status code.
newUploadSSHPublicKeyResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  UploadSSHPublicKeyResponse
newUploadSSHPublicKeyResponse :: Int -> UploadSSHPublicKeyResponse
newUploadSSHPublicKeyResponse Int
pHttpStatus_ =
  UploadSSHPublicKeyResponse'
    { $sel:sSHPublicKey:UploadSSHPublicKeyResponse' :: Maybe SSHPublicKey
sSHPublicKey =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:UploadSSHPublicKeyResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Contains information about the SSH public key.
uploadSSHPublicKeyResponse_sSHPublicKey :: Lens.Lens' UploadSSHPublicKeyResponse (Prelude.Maybe SSHPublicKey)
uploadSSHPublicKeyResponse_sSHPublicKey :: Lens' UploadSSHPublicKeyResponse (Maybe SSHPublicKey)
uploadSSHPublicKeyResponse_sSHPublicKey = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UploadSSHPublicKeyResponse' {Maybe SSHPublicKey
sSHPublicKey :: Maybe SSHPublicKey
$sel:sSHPublicKey:UploadSSHPublicKeyResponse' :: UploadSSHPublicKeyResponse -> Maybe SSHPublicKey
sSHPublicKey} -> Maybe SSHPublicKey
sSHPublicKey) (\s :: UploadSSHPublicKeyResponse
s@UploadSSHPublicKeyResponse' {} Maybe SSHPublicKey
a -> UploadSSHPublicKeyResponse
s {$sel:sSHPublicKey:UploadSSHPublicKeyResponse' :: Maybe SSHPublicKey
sSHPublicKey = Maybe SSHPublicKey
a} :: UploadSSHPublicKeyResponse)

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

instance Prelude.NFData UploadSSHPublicKeyResponse where
  rnf :: UploadSSHPublicKeyResponse -> ()
rnf UploadSSHPublicKeyResponse' {Int
Maybe SSHPublicKey
httpStatus :: Int
sSHPublicKey :: Maybe SSHPublicKey
$sel:httpStatus:UploadSSHPublicKeyResponse' :: UploadSSHPublicKeyResponse -> Int
$sel:sSHPublicKey:UploadSSHPublicKeyResponse' :: UploadSSHPublicKeyResponse -> Maybe SSHPublicKey
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe SSHPublicKey
sSHPublicKey
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus