{-# 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.CloudHSM.ListHsms
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- This is documentation for __AWS CloudHSM Classic__. For more
-- information, see
-- <http://aws.amazon.com/cloudhsm/faqs-classic/ AWS CloudHSM Classic FAQs>,
-- the
-- <https://docs.aws.amazon.com/cloudhsm/classic/userguide/ AWS CloudHSM Classic User Guide>,
-- and the
-- <https://docs.aws.amazon.com/cloudhsm/classic/APIReference/ AWS CloudHSM Classic API Reference>.
--
-- __For information about the current version of AWS CloudHSM__, see
-- <http://aws.amazon.com/cloudhsm/ AWS CloudHSM>, the
-- <https://docs.aws.amazon.com/cloudhsm/latest/userguide/ AWS CloudHSM User Guide>,
-- and the
-- <https://docs.aws.amazon.com/cloudhsm/latest/APIReference/ AWS CloudHSM API Reference>.
--
-- Retrieves the identifiers of all of the HSMs provisioned for the current
-- customer.
--
-- This operation supports pagination with the use of the @NextToken@
-- member. If more results are available, the @NextToken@ member of the
-- response contains a token that you pass in the next call to @ListHsms@
-- to retrieve the next set of items.
--
-- This operation returns paginated results.
module Amazonka.CloudHSM.ListHsms
  ( -- * Creating a Request
    ListHsms (..),
    newListHsms,

    -- * Request Lenses
    listHsms_nextToken,

    -- * Destructuring the Response
    ListHsmsResponse (..),
    newListHsmsResponse,

    -- * Response Lenses
    listHsmsResponse_hsmList,
    listHsmsResponse_nextToken,
    listHsmsResponse_httpStatus,
  )
where

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

-- | /See:/ 'newListHsms' smart constructor.
data ListHsms = ListHsms'
  { -- | The @NextToken@ value from a previous call to @ListHsms@. Pass null if
    -- this is the first call.
    ListHsms -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text
  }
  deriving (ListHsms -> ListHsms -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListHsms -> ListHsms -> Bool
$c/= :: ListHsms -> ListHsms -> Bool
== :: ListHsms -> ListHsms -> Bool
$c== :: ListHsms -> ListHsms -> Bool
Prelude.Eq, ReadPrec [ListHsms]
ReadPrec ListHsms
Int -> ReadS ListHsms
ReadS [ListHsms]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListHsms]
$creadListPrec :: ReadPrec [ListHsms]
readPrec :: ReadPrec ListHsms
$creadPrec :: ReadPrec ListHsms
readList :: ReadS [ListHsms]
$creadList :: ReadS [ListHsms]
readsPrec :: Int -> ReadS ListHsms
$creadsPrec :: Int -> ReadS ListHsms
Prelude.Read, Int -> ListHsms -> ShowS
[ListHsms] -> ShowS
ListHsms -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListHsms] -> ShowS
$cshowList :: [ListHsms] -> ShowS
show :: ListHsms -> String
$cshow :: ListHsms -> String
showsPrec :: Int -> ListHsms -> ShowS
$cshowsPrec :: Int -> ListHsms -> ShowS
Prelude.Show, forall x. Rep ListHsms x -> ListHsms
forall x. ListHsms -> Rep ListHsms x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListHsms x -> ListHsms
$cfrom :: forall x. ListHsms -> Rep ListHsms x
Prelude.Generic)

-- |
-- Create a value of 'ListHsms' 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:
--
-- 'nextToken', 'listHsms_nextToken' - The @NextToken@ value from a previous call to @ListHsms@. Pass null if
-- this is the first call.
newListHsms ::
  ListHsms
newListHsms :: ListHsms
newListHsms = ListHsms' {$sel:nextToken:ListHsms' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing}

-- | The @NextToken@ value from a previous call to @ListHsms@. Pass null if
-- this is the first call.
listHsms_nextToken :: Lens.Lens' ListHsms (Prelude.Maybe Prelude.Text)
listHsms_nextToken :: Lens' ListHsms (Maybe Text)
listHsms_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListHsms' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListHsms' :: ListHsms -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListHsms
s@ListHsms' {} Maybe Text
a -> ListHsms
s {$sel:nextToken:ListHsms' :: Maybe Text
nextToken = Maybe Text
a} :: ListHsms)

instance Core.AWSPager ListHsms where
  page :: ListHsms -> AWSResponse ListHsms -> Maybe ListHsms
page ListHsms
rq AWSResponse ListHsms
rs
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListHsms
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListHsmsResponse (Maybe Text)
listHsmsResponse_nextToken
            forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just
        ) =
        forall a. Maybe a
Prelude.Nothing
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListHsms
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListHsmsResponse (Maybe [Text])
listHsmsResponse_hsmList
            forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just
        ) =
        forall a. Maybe a
Prelude.Nothing
    | Bool
Prelude.otherwise =
        forall a. a -> Maybe a
Prelude.Just
          forall a b. (a -> b) -> a -> b
Prelude.$ ListHsms
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' ListHsms (Maybe Text)
listHsms_nextToken
          forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse ListHsms
rs
          forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListHsmsResponse (Maybe Text)
listHsmsResponse_nextToken
          forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just

instance Core.AWSRequest ListHsms where
  type AWSResponse ListHsms = ListHsmsResponse
  request :: (Service -> Service) -> ListHsms -> Request ListHsms
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy ListHsms
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ListHsms)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe [Text] -> Maybe Text -> Int -> ListHsmsResponse
ListHsmsResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"HsmList" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"NextToken")
            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 ListHsms where
  hashWithSalt :: Int -> ListHsms -> Int
hashWithSalt Int
_salt ListHsms' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListHsms' :: ListHsms -> Maybe Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
nextToken

instance Prelude.NFData ListHsms where
  rnf :: ListHsms -> ()
rnf ListHsms' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListHsms' :: ListHsms -> Maybe Text
..} = forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
nextToken

instance Data.ToHeaders ListHsms where
  toHeaders :: ListHsms -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"CloudHsmFrontendService.ListHsms" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON ListHsms where
  toJSON :: ListHsms -> Value
toJSON ListHsms' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListHsms' :: ListHsms -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [(Key
"NextToken" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
nextToken]
      )

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

instance Data.ToQuery ListHsms where
  toQuery :: ListHsms -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const forall a. Monoid a => a
Prelude.mempty

-- | Contains the output of the @ListHsms@ operation.
--
-- /See:/ 'newListHsmsResponse' smart constructor.
data ListHsmsResponse = ListHsmsResponse'
  { -- | The list of ARNs that identify the HSMs.
    ListHsmsResponse -> Maybe [Text]
hsmList :: Prelude.Maybe [Prelude.Text],
    -- | If not null, more results are available. Pass this value to @ListHsms@
    -- to retrieve the next set of items.
    ListHsmsResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    ListHsmsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ListHsmsResponse -> ListHsmsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListHsmsResponse -> ListHsmsResponse -> Bool
$c/= :: ListHsmsResponse -> ListHsmsResponse -> Bool
== :: ListHsmsResponse -> ListHsmsResponse -> Bool
$c== :: ListHsmsResponse -> ListHsmsResponse -> Bool
Prelude.Eq, ReadPrec [ListHsmsResponse]
ReadPrec ListHsmsResponse
Int -> ReadS ListHsmsResponse
ReadS [ListHsmsResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListHsmsResponse]
$creadListPrec :: ReadPrec [ListHsmsResponse]
readPrec :: ReadPrec ListHsmsResponse
$creadPrec :: ReadPrec ListHsmsResponse
readList :: ReadS [ListHsmsResponse]
$creadList :: ReadS [ListHsmsResponse]
readsPrec :: Int -> ReadS ListHsmsResponse
$creadsPrec :: Int -> ReadS ListHsmsResponse
Prelude.Read, Int -> ListHsmsResponse -> ShowS
[ListHsmsResponse] -> ShowS
ListHsmsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListHsmsResponse] -> ShowS
$cshowList :: [ListHsmsResponse] -> ShowS
show :: ListHsmsResponse -> String
$cshow :: ListHsmsResponse -> String
showsPrec :: Int -> ListHsmsResponse -> ShowS
$cshowsPrec :: Int -> ListHsmsResponse -> ShowS
Prelude.Show, forall x. Rep ListHsmsResponse x -> ListHsmsResponse
forall x. ListHsmsResponse -> Rep ListHsmsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListHsmsResponse x -> ListHsmsResponse
$cfrom :: forall x. ListHsmsResponse -> Rep ListHsmsResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListHsmsResponse' 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:
--
-- 'hsmList', 'listHsmsResponse_hsmList' - The list of ARNs that identify the HSMs.
--
-- 'nextToken', 'listHsmsResponse_nextToken' - If not null, more results are available. Pass this value to @ListHsms@
-- to retrieve the next set of items.
--
-- 'httpStatus', 'listHsmsResponse_httpStatus' - The response's http status code.
newListHsmsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListHsmsResponse
newListHsmsResponse :: Int -> ListHsmsResponse
newListHsmsResponse Int
pHttpStatus_ =
  ListHsmsResponse'
    { $sel:hsmList:ListHsmsResponse' :: Maybe [Text]
hsmList = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListHsmsResponse' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListHsmsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The list of ARNs that identify the HSMs.
listHsmsResponse_hsmList :: Lens.Lens' ListHsmsResponse (Prelude.Maybe [Prelude.Text])
listHsmsResponse_hsmList :: Lens' ListHsmsResponse (Maybe [Text])
listHsmsResponse_hsmList = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListHsmsResponse' {Maybe [Text]
hsmList :: Maybe [Text]
$sel:hsmList:ListHsmsResponse' :: ListHsmsResponse -> Maybe [Text]
hsmList} -> Maybe [Text]
hsmList) (\s :: ListHsmsResponse
s@ListHsmsResponse' {} Maybe [Text]
a -> ListHsmsResponse
s {$sel:hsmList:ListHsmsResponse' :: Maybe [Text]
hsmList = Maybe [Text]
a} :: ListHsmsResponse) 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

-- | If not null, more results are available. Pass this value to @ListHsms@
-- to retrieve the next set of items.
listHsmsResponse_nextToken :: Lens.Lens' ListHsmsResponse (Prelude.Maybe Prelude.Text)
listHsmsResponse_nextToken :: Lens' ListHsmsResponse (Maybe Text)
listHsmsResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListHsmsResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListHsmsResponse' :: ListHsmsResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListHsmsResponse
s@ListHsmsResponse' {} Maybe Text
a -> ListHsmsResponse
s {$sel:nextToken:ListHsmsResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListHsmsResponse)

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

instance Prelude.NFData ListHsmsResponse where
  rnf :: ListHsmsResponse -> ()
rnf ListHsmsResponse' {Int
Maybe [Text]
Maybe Text
httpStatus :: Int
nextToken :: Maybe Text
hsmList :: Maybe [Text]
$sel:httpStatus:ListHsmsResponse' :: ListHsmsResponse -> Int
$sel:nextToken:ListHsmsResponse' :: ListHsmsResponse -> Maybe Text
$sel:hsmList:ListHsmsResponse' :: ListHsmsResponse -> Maybe [Text]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Text]
hsmList
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
nextToken
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus