{-# 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.ListServiceSpecificCredentials
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Returns information about the service-specific credentials associated
-- with the specified IAM user. If none exists, the operation returns an
-- empty list. The service-specific credentials returned by this operation
-- are used only for authenticating the IAM user to a specific service. For
-- more information about using service-specific credentials to
-- authenticate to an Amazon Web Services service, see
-- <https://docs.aws.amazon.com/codecommit/latest/userguide/setting-up-gc.html Set up service-specific credentials>
-- in the CodeCommit User Guide.
module Amazonka.IAM.ListServiceSpecificCredentials
  ( -- * Creating a Request
    ListServiceSpecificCredentials (..),
    newListServiceSpecificCredentials,

    -- * Request Lenses
    listServiceSpecificCredentials_serviceName,
    listServiceSpecificCredentials_userName,

    -- * Destructuring the Response
    ListServiceSpecificCredentialsResponse (..),
    newListServiceSpecificCredentialsResponse,

    -- * Response Lenses
    listServiceSpecificCredentialsResponse_serviceSpecificCredentials,
    listServiceSpecificCredentialsResponse_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:/ 'newListServiceSpecificCredentials' smart constructor.
data ListServiceSpecificCredentials = ListServiceSpecificCredentials'
  { -- | Filters the returned results to only those for the specified Amazon Web
    -- Services service. If not specified, then Amazon Web Services returns
    -- service-specific credentials for all services.
    ListServiceSpecificCredentials -> Maybe Text
serviceName :: Prelude.Maybe Prelude.Text,
    -- | The name of the user whose service-specific credentials you want
    -- information about. If this value is not specified, then the operation
    -- assumes the user whose credentials are used to call the operation.
    --
    -- 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: _+=,.\@-
    ListServiceSpecificCredentials -> Maybe Text
userName :: Prelude.Maybe Prelude.Text
  }
  deriving (ListServiceSpecificCredentials
-> ListServiceSpecificCredentials -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListServiceSpecificCredentials
-> ListServiceSpecificCredentials -> Bool
$c/= :: ListServiceSpecificCredentials
-> ListServiceSpecificCredentials -> Bool
== :: ListServiceSpecificCredentials
-> ListServiceSpecificCredentials -> Bool
$c== :: ListServiceSpecificCredentials
-> ListServiceSpecificCredentials -> Bool
Prelude.Eq, ReadPrec [ListServiceSpecificCredentials]
ReadPrec ListServiceSpecificCredentials
Int -> ReadS ListServiceSpecificCredentials
ReadS [ListServiceSpecificCredentials]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListServiceSpecificCredentials]
$creadListPrec :: ReadPrec [ListServiceSpecificCredentials]
readPrec :: ReadPrec ListServiceSpecificCredentials
$creadPrec :: ReadPrec ListServiceSpecificCredentials
readList :: ReadS [ListServiceSpecificCredentials]
$creadList :: ReadS [ListServiceSpecificCredentials]
readsPrec :: Int -> ReadS ListServiceSpecificCredentials
$creadsPrec :: Int -> ReadS ListServiceSpecificCredentials
Prelude.Read, Int -> ListServiceSpecificCredentials -> ShowS
[ListServiceSpecificCredentials] -> ShowS
ListServiceSpecificCredentials -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListServiceSpecificCredentials] -> ShowS
$cshowList :: [ListServiceSpecificCredentials] -> ShowS
show :: ListServiceSpecificCredentials -> String
$cshow :: ListServiceSpecificCredentials -> String
showsPrec :: Int -> ListServiceSpecificCredentials -> ShowS
$cshowsPrec :: Int -> ListServiceSpecificCredentials -> ShowS
Prelude.Show, forall x.
Rep ListServiceSpecificCredentials x
-> ListServiceSpecificCredentials
forall x.
ListServiceSpecificCredentials
-> Rep ListServiceSpecificCredentials x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ListServiceSpecificCredentials x
-> ListServiceSpecificCredentials
$cfrom :: forall x.
ListServiceSpecificCredentials
-> Rep ListServiceSpecificCredentials x
Prelude.Generic)

-- |
-- Create a value of 'ListServiceSpecificCredentials' 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:
--
-- 'serviceName', 'listServiceSpecificCredentials_serviceName' - Filters the returned results to only those for the specified Amazon Web
-- Services service. If not specified, then Amazon Web Services returns
-- service-specific credentials for all services.
--
-- 'userName', 'listServiceSpecificCredentials_userName' - The name of the user whose service-specific credentials you want
-- information about. If this value is not specified, then the operation
-- assumes the user whose credentials are used to call the operation.
--
-- 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: _+=,.\@-
newListServiceSpecificCredentials ::
  ListServiceSpecificCredentials
newListServiceSpecificCredentials :: ListServiceSpecificCredentials
newListServiceSpecificCredentials =
  ListServiceSpecificCredentials'
    { $sel:serviceName:ListServiceSpecificCredentials' :: Maybe Text
serviceName =
        forall a. Maybe a
Prelude.Nothing,
      $sel:userName:ListServiceSpecificCredentials' :: Maybe Text
userName = forall a. Maybe a
Prelude.Nothing
    }

-- | Filters the returned results to only those for the specified Amazon Web
-- Services service. If not specified, then Amazon Web Services returns
-- service-specific credentials for all services.
listServiceSpecificCredentials_serviceName :: Lens.Lens' ListServiceSpecificCredentials (Prelude.Maybe Prelude.Text)
listServiceSpecificCredentials_serviceName :: Lens' ListServiceSpecificCredentials (Maybe Text)
listServiceSpecificCredentials_serviceName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListServiceSpecificCredentials' {Maybe Text
serviceName :: Maybe Text
$sel:serviceName:ListServiceSpecificCredentials' :: ListServiceSpecificCredentials -> Maybe Text
serviceName} -> Maybe Text
serviceName) (\s :: ListServiceSpecificCredentials
s@ListServiceSpecificCredentials' {} Maybe Text
a -> ListServiceSpecificCredentials
s {$sel:serviceName:ListServiceSpecificCredentials' :: Maybe Text
serviceName = Maybe Text
a} :: ListServiceSpecificCredentials)

-- | The name of the user whose service-specific credentials you want
-- information about. If this value is not specified, then the operation
-- assumes the user whose credentials are used to call the operation.
--
-- 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: _+=,.\@-
listServiceSpecificCredentials_userName :: Lens.Lens' ListServiceSpecificCredentials (Prelude.Maybe Prelude.Text)
listServiceSpecificCredentials_userName :: Lens' ListServiceSpecificCredentials (Maybe Text)
listServiceSpecificCredentials_userName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListServiceSpecificCredentials' {Maybe Text
userName :: Maybe Text
$sel:userName:ListServiceSpecificCredentials' :: ListServiceSpecificCredentials -> Maybe Text
userName} -> Maybe Text
userName) (\s :: ListServiceSpecificCredentials
s@ListServiceSpecificCredentials' {} Maybe Text
a -> ListServiceSpecificCredentials
s {$sel:userName:ListServiceSpecificCredentials' :: Maybe Text
userName = Maybe Text
a} :: ListServiceSpecificCredentials)

instance
  Core.AWSRequest
    ListServiceSpecificCredentials
  where
  type
    AWSResponse ListServiceSpecificCredentials =
      ListServiceSpecificCredentialsResponse
  request :: (Service -> Service)
-> ListServiceSpecificCredentials
-> Request ListServiceSpecificCredentials
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 ListServiceSpecificCredentials
-> ClientResponse ClientBody
-> m (Either
        Error
        (ClientResponse (AWSResponse ListServiceSpecificCredentials)))
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
"ListServiceSpecificCredentialsResult"
      ( \Int
s ResponseHeaders
h [Node]
x ->
          Maybe [ServiceSpecificCredentialMetadata]
-> Int -> ListServiceSpecificCredentialsResponse
ListServiceSpecificCredentialsResponse'
            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
"ServiceSpecificCredentials"
                            forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty
                            forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (forall a. FromXML a => Text -> [Node] -> Either String [a]
Data.parseXMLList Text
"member")
                        )
            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
    ListServiceSpecificCredentials
  where
  hashWithSalt :: Int -> ListServiceSpecificCredentials -> Int
hashWithSalt
    Int
_salt
    ListServiceSpecificCredentials' {Maybe Text
userName :: Maybe Text
serviceName :: Maybe Text
$sel:userName:ListServiceSpecificCredentials' :: ListServiceSpecificCredentials -> Maybe Text
$sel:serviceName:ListServiceSpecificCredentials' :: ListServiceSpecificCredentials -> Maybe Text
..} =
      Int
_salt
        forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
serviceName
        forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
userName

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

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

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

instance Data.ToQuery ListServiceSpecificCredentials where
  toQuery :: ListServiceSpecificCredentials -> QueryString
toQuery ListServiceSpecificCredentials' {Maybe Text
userName :: Maybe Text
serviceName :: Maybe Text
$sel:userName:ListServiceSpecificCredentials' :: ListServiceSpecificCredentials -> Maybe Text
$sel:serviceName:ListServiceSpecificCredentials' :: ListServiceSpecificCredentials -> Maybe Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Action"
          forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: ( ByteString
"ListServiceSpecificCredentials" ::
                      Prelude.ByteString
                  ),
        ByteString
"Version"
          forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: (ByteString
"2010-05-08" :: Prelude.ByteString),
        ByteString
"ServiceName" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Text
serviceName,
        ByteString
"UserName" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Text
userName
      ]

-- | /See:/ 'newListServiceSpecificCredentialsResponse' smart constructor.
data ListServiceSpecificCredentialsResponse = ListServiceSpecificCredentialsResponse'
  { -- | A list of structures that each contain details about a service-specific
    -- credential.
    ListServiceSpecificCredentialsResponse
-> Maybe [ServiceSpecificCredentialMetadata]
serviceSpecificCredentials :: Prelude.Maybe [ServiceSpecificCredentialMetadata],
    -- | The response's http status code.
    ListServiceSpecificCredentialsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ListServiceSpecificCredentialsResponse
-> ListServiceSpecificCredentialsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListServiceSpecificCredentialsResponse
-> ListServiceSpecificCredentialsResponse -> Bool
$c/= :: ListServiceSpecificCredentialsResponse
-> ListServiceSpecificCredentialsResponse -> Bool
== :: ListServiceSpecificCredentialsResponse
-> ListServiceSpecificCredentialsResponse -> Bool
$c== :: ListServiceSpecificCredentialsResponse
-> ListServiceSpecificCredentialsResponse -> Bool
Prelude.Eq, ReadPrec [ListServiceSpecificCredentialsResponse]
ReadPrec ListServiceSpecificCredentialsResponse
Int -> ReadS ListServiceSpecificCredentialsResponse
ReadS [ListServiceSpecificCredentialsResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListServiceSpecificCredentialsResponse]
$creadListPrec :: ReadPrec [ListServiceSpecificCredentialsResponse]
readPrec :: ReadPrec ListServiceSpecificCredentialsResponse
$creadPrec :: ReadPrec ListServiceSpecificCredentialsResponse
readList :: ReadS [ListServiceSpecificCredentialsResponse]
$creadList :: ReadS [ListServiceSpecificCredentialsResponse]
readsPrec :: Int -> ReadS ListServiceSpecificCredentialsResponse
$creadsPrec :: Int -> ReadS ListServiceSpecificCredentialsResponse
Prelude.Read, Int -> ListServiceSpecificCredentialsResponse -> ShowS
[ListServiceSpecificCredentialsResponse] -> ShowS
ListServiceSpecificCredentialsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListServiceSpecificCredentialsResponse] -> ShowS
$cshowList :: [ListServiceSpecificCredentialsResponse] -> ShowS
show :: ListServiceSpecificCredentialsResponse -> String
$cshow :: ListServiceSpecificCredentialsResponse -> String
showsPrec :: Int -> ListServiceSpecificCredentialsResponse -> ShowS
$cshowsPrec :: Int -> ListServiceSpecificCredentialsResponse -> ShowS
Prelude.Show, forall x.
Rep ListServiceSpecificCredentialsResponse x
-> ListServiceSpecificCredentialsResponse
forall x.
ListServiceSpecificCredentialsResponse
-> Rep ListServiceSpecificCredentialsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ListServiceSpecificCredentialsResponse x
-> ListServiceSpecificCredentialsResponse
$cfrom :: forall x.
ListServiceSpecificCredentialsResponse
-> Rep ListServiceSpecificCredentialsResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListServiceSpecificCredentialsResponse' 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:
--
-- 'serviceSpecificCredentials', 'listServiceSpecificCredentialsResponse_serviceSpecificCredentials' - A list of structures that each contain details about a service-specific
-- credential.
--
-- 'httpStatus', 'listServiceSpecificCredentialsResponse_httpStatus' - The response's http status code.
newListServiceSpecificCredentialsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListServiceSpecificCredentialsResponse
newListServiceSpecificCredentialsResponse :: Int -> ListServiceSpecificCredentialsResponse
newListServiceSpecificCredentialsResponse
  Int
pHttpStatus_ =
    ListServiceSpecificCredentialsResponse'
      { $sel:serviceSpecificCredentials:ListServiceSpecificCredentialsResponse' :: Maybe [ServiceSpecificCredentialMetadata]
serviceSpecificCredentials =
          forall a. Maybe a
Prelude.Nothing,
        $sel:httpStatus:ListServiceSpecificCredentialsResponse' :: Int
httpStatus = Int
pHttpStatus_
      }

-- | A list of structures that each contain details about a service-specific
-- credential.
listServiceSpecificCredentialsResponse_serviceSpecificCredentials :: Lens.Lens' ListServiceSpecificCredentialsResponse (Prelude.Maybe [ServiceSpecificCredentialMetadata])
listServiceSpecificCredentialsResponse_serviceSpecificCredentials :: Lens'
  ListServiceSpecificCredentialsResponse
  (Maybe [ServiceSpecificCredentialMetadata])
listServiceSpecificCredentialsResponse_serviceSpecificCredentials = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListServiceSpecificCredentialsResponse' {Maybe [ServiceSpecificCredentialMetadata]
serviceSpecificCredentials :: Maybe [ServiceSpecificCredentialMetadata]
$sel:serviceSpecificCredentials:ListServiceSpecificCredentialsResponse' :: ListServiceSpecificCredentialsResponse
-> Maybe [ServiceSpecificCredentialMetadata]
serviceSpecificCredentials} -> Maybe [ServiceSpecificCredentialMetadata]
serviceSpecificCredentials) (\s :: ListServiceSpecificCredentialsResponse
s@ListServiceSpecificCredentialsResponse' {} Maybe [ServiceSpecificCredentialMetadata]
a -> ListServiceSpecificCredentialsResponse
s {$sel:serviceSpecificCredentials:ListServiceSpecificCredentialsResponse' :: Maybe [ServiceSpecificCredentialMetadata]
serviceSpecificCredentials = Maybe [ServiceSpecificCredentialMetadata]
a} :: ListServiceSpecificCredentialsResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance
  Prelude.NFData
    ListServiceSpecificCredentialsResponse
  where
  rnf :: ListServiceSpecificCredentialsResponse -> ()
rnf ListServiceSpecificCredentialsResponse' {Int
Maybe [ServiceSpecificCredentialMetadata]
httpStatus :: Int
serviceSpecificCredentials :: Maybe [ServiceSpecificCredentialMetadata]
$sel:httpStatus:ListServiceSpecificCredentialsResponse' :: ListServiceSpecificCredentialsResponse -> Int
$sel:serviceSpecificCredentials:ListServiceSpecificCredentialsResponse' :: ListServiceSpecificCredentialsResponse
-> Maybe [ServiceSpecificCredentialMetadata]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [ServiceSpecificCredentialMetadata]
serviceSpecificCredentials
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus