{-# 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.GuardDuty.ListIPSets
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Lists the IPSets of the GuardDuty service specified by the detector ID.
-- If you use this operation from a member account, the IPSets returned are
-- the IPSets from the associated administrator account.
--
-- This operation returns paginated results.
module Amazonka.GuardDuty.ListIPSets
  ( -- * Creating a Request
    ListIPSets (..),
    newListIPSets,

    -- * Request Lenses
    listIPSets_maxResults,
    listIPSets_nextToken,
    listIPSets_detectorId,

    -- * Destructuring the Response
    ListIPSetsResponse (..),
    newListIPSetsResponse,

    -- * Response Lenses
    listIPSetsResponse_nextToken,
    listIPSetsResponse_httpStatus,
    listIPSetsResponse_ipSetIds,
  )
where

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

-- | /See:/ 'newListIPSets' smart constructor.
data ListIPSets = ListIPSets'
  { -- | You can use this parameter to indicate the maximum number of items you
    -- want in the response. The default value is 50. The maximum value is 50.
    ListIPSets -> Maybe Natural
maxResults :: Prelude.Maybe Prelude.Natural,
    -- | You can use this parameter when paginating results. Set the value of
    -- this parameter to null on your first call to the list action. For
    -- subsequent calls to the action, fill nextToken in the request with the
    -- value of NextToken from the previous response to continue listing data.
    ListIPSets -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The unique ID of the detector that the IPSet is associated with.
    ListIPSets -> Text
detectorId :: Prelude.Text
  }
  deriving (ListIPSets -> ListIPSets -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListIPSets -> ListIPSets -> Bool
$c/= :: ListIPSets -> ListIPSets -> Bool
== :: ListIPSets -> ListIPSets -> Bool
$c== :: ListIPSets -> ListIPSets -> Bool
Prelude.Eq, ReadPrec [ListIPSets]
ReadPrec ListIPSets
Int -> ReadS ListIPSets
ReadS [ListIPSets]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListIPSets]
$creadListPrec :: ReadPrec [ListIPSets]
readPrec :: ReadPrec ListIPSets
$creadPrec :: ReadPrec ListIPSets
readList :: ReadS [ListIPSets]
$creadList :: ReadS [ListIPSets]
readsPrec :: Int -> ReadS ListIPSets
$creadsPrec :: Int -> ReadS ListIPSets
Prelude.Read, Int -> ListIPSets -> ShowS
[ListIPSets] -> ShowS
ListIPSets -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListIPSets] -> ShowS
$cshowList :: [ListIPSets] -> ShowS
show :: ListIPSets -> String
$cshow :: ListIPSets -> String
showsPrec :: Int -> ListIPSets -> ShowS
$cshowsPrec :: Int -> ListIPSets -> ShowS
Prelude.Show, forall x. Rep ListIPSets x -> ListIPSets
forall x. ListIPSets -> Rep ListIPSets x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListIPSets x -> ListIPSets
$cfrom :: forall x. ListIPSets -> Rep ListIPSets x
Prelude.Generic)

-- |
-- Create a value of 'ListIPSets' 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:
--
-- 'maxResults', 'listIPSets_maxResults' - You can use this parameter to indicate the maximum number of items you
-- want in the response. The default value is 50. The maximum value is 50.
--
-- 'nextToken', 'listIPSets_nextToken' - You can use this parameter when paginating results. Set the value of
-- this parameter to null on your first call to the list action. For
-- subsequent calls to the action, fill nextToken in the request with the
-- value of NextToken from the previous response to continue listing data.
--
-- 'detectorId', 'listIPSets_detectorId' - The unique ID of the detector that the IPSet is associated with.
newListIPSets ::
  -- | 'detectorId'
  Prelude.Text ->
  ListIPSets
newListIPSets :: Text -> ListIPSets
newListIPSets Text
pDetectorId_ =
  ListIPSets'
    { $sel:maxResults:ListIPSets' :: Maybe Natural
maxResults = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListIPSets' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:detectorId:ListIPSets' :: Text
detectorId = Text
pDetectorId_
    }

-- | You can use this parameter to indicate the maximum number of items you
-- want in the response. The default value is 50. The maximum value is 50.
listIPSets_maxResults :: Lens.Lens' ListIPSets (Prelude.Maybe Prelude.Natural)
listIPSets_maxResults :: Lens' ListIPSets (Maybe Natural)
listIPSets_maxResults = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListIPSets' {Maybe Natural
maxResults :: Maybe Natural
$sel:maxResults:ListIPSets' :: ListIPSets -> Maybe Natural
maxResults} -> Maybe Natural
maxResults) (\s :: ListIPSets
s@ListIPSets' {} Maybe Natural
a -> ListIPSets
s {$sel:maxResults:ListIPSets' :: Maybe Natural
maxResults = Maybe Natural
a} :: ListIPSets)

-- | You can use this parameter when paginating results. Set the value of
-- this parameter to null on your first call to the list action. For
-- subsequent calls to the action, fill nextToken in the request with the
-- value of NextToken from the previous response to continue listing data.
listIPSets_nextToken :: Lens.Lens' ListIPSets (Prelude.Maybe Prelude.Text)
listIPSets_nextToken :: Lens' ListIPSets (Maybe Text)
listIPSets_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListIPSets' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListIPSets' :: ListIPSets -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListIPSets
s@ListIPSets' {} Maybe Text
a -> ListIPSets
s {$sel:nextToken:ListIPSets' :: Maybe Text
nextToken = Maybe Text
a} :: ListIPSets)

-- | The unique ID of the detector that the IPSet is associated with.
listIPSets_detectorId :: Lens.Lens' ListIPSets Prelude.Text
listIPSets_detectorId :: Lens' ListIPSets Text
listIPSets_detectorId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListIPSets' {Text
detectorId :: Text
$sel:detectorId:ListIPSets' :: ListIPSets -> Text
detectorId} -> Text
detectorId) (\s :: ListIPSets
s@ListIPSets' {} Text
a -> ListIPSets
s {$sel:detectorId:ListIPSets' :: Text
detectorId = Text
a} :: ListIPSets)

instance Core.AWSPager ListIPSets where
  page :: ListIPSets -> AWSResponse ListIPSets -> Maybe ListIPSets
page ListIPSets
rq AWSResponse ListIPSets
rs
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListIPSets
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListIPSetsResponse (Maybe Text)
listIPSetsResponse_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 ListIPSets
rs forall s a. s -> Getting a s a -> a
Lens.^. Lens' ListIPSetsResponse [Text]
listIPSetsResponse_ipSetIds) =
        forall a. Maybe a
Prelude.Nothing
    | Bool
Prelude.otherwise =
        forall a. a -> Maybe a
Prelude.Just
          forall a b. (a -> b) -> a -> b
Prelude.$ ListIPSets
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' ListIPSets (Maybe Text)
listIPSets_nextToken
          forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse ListIPSets
rs
          forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListIPSetsResponse (Maybe Text)
listIPSetsResponse_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 ListIPSets where
  type AWSResponse ListIPSets = ListIPSetsResponse
  request :: (Service -> Service) -> ListIPSets -> Request ListIPSets
request Service -> Service
overrides =
    forall a. ToRequest a => Service -> a -> Request a
Request.get (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy ListIPSets
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ListIPSets)))
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 -> Int -> [Text] -> ListIPSetsResponse
ListIPSetsResponse'
            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
"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))
            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
"ipSetIds" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable ListIPSets where
  hashWithSalt :: Int -> ListIPSets -> Int
hashWithSalt Int
_salt ListIPSets' {Maybe Natural
Maybe Text
Text
detectorId :: Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:detectorId:ListIPSets' :: ListIPSets -> Text
$sel:nextToken:ListIPSets' :: ListIPSets -> Maybe Text
$sel:maxResults:ListIPSets' :: ListIPSets -> Maybe Natural
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
maxResults
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
nextToken
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
detectorId

instance Prelude.NFData ListIPSets where
  rnf :: ListIPSets -> ()
rnf ListIPSets' {Maybe Natural
Maybe Text
Text
detectorId :: Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:detectorId:ListIPSets' :: ListIPSets -> Text
$sel:nextToken:ListIPSets' :: ListIPSets -> Maybe Text
$sel:maxResults:ListIPSets' :: ListIPSets -> Maybe Natural
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
maxResults
      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 Text
detectorId

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

instance Data.ToPath ListIPSets where
  toPath :: ListIPSets -> ByteString
toPath ListIPSets' {Maybe Natural
Maybe Text
Text
detectorId :: Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:detectorId:ListIPSets' :: ListIPSets -> Text
$sel:nextToken:ListIPSets' :: ListIPSets -> Maybe Text
$sel:maxResults:ListIPSets' :: ListIPSets -> Maybe Natural
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/detector/", forall a. ToByteString a => a -> ByteString
Data.toBS Text
detectorId, ByteString
"/ipset"]

instance Data.ToQuery ListIPSets where
  toQuery :: ListIPSets -> QueryString
toQuery ListIPSets' {Maybe Natural
Maybe Text
Text
detectorId :: Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:detectorId:ListIPSets' :: ListIPSets -> Text
$sel:nextToken:ListIPSets' :: ListIPSets -> Maybe Text
$sel:maxResults:ListIPSets' :: ListIPSets -> Maybe Natural
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"maxResults" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Natural
maxResults,
        ByteString
"nextToken" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Text
nextToken
      ]

-- | /See:/ 'newListIPSetsResponse' smart constructor.
data ListIPSetsResponse = ListIPSetsResponse'
  { -- | The pagination parameter to be used on the next list operation to
    -- retrieve more items.
    ListIPSetsResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    ListIPSetsResponse -> Int
httpStatus :: Prelude.Int,
    -- | The IDs of the IPSet resources.
    ListIPSetsResponse -> [Text]
ipSetIds :: [Prelude.Text]
  }
  deriving (ListIPSetsResponse -> ListIPSetsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListIPSetsResponse -> ListIPSetsResponse -> Bool
$c/= :: ListIPSetsResponse -> ListIPSetsResponse -> Bool
== :: ListIPSetsResponse -> ListIPSetsResponse -> Bool
$c== :: ListIPSetsResponse -> ListIPSetsResponse -> Bool
Prelude.Eq, ReadPrec [ListIPSetsResponse]
ReadPrec ListIPSetsResponse
Int -> ReadS ListIPSetsResponse
ReadS [ListIPSetsResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListIPSetsResponse]
$creadListPrec :: ReadPrec [ListIPSetsResponse]
readPrec :: ReadPrec ListIPSetsResponse
$creadPrec :: ReadPrec ListIPSetsResponse
readList :: ReadS [ListIPSetsResponse]
$creadList :: ReadS [ListIPSetsResponse]
readsPrec :: Int -> ReadS ListIPSetsResponse
$creadsPrec :: Int -> ReadS ListIPSetsResponse
Prelude.Read, Int -> ListIPSetsResponse -> ShowS
[ListIPSetsResponse] -> ShowS
ListIPSetsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListIPSetsResponse] -> ShowS
$cshowList :: [ListIPSetsResponse] -> ShowS
show :: ListIPSetsResponse -> String
$cshow :: ListIPSetsResponse -> String
showsPrec :: Int -> ListIPSetsResponse -> ShowS
$cshowsPrec :: Int -> ListIPSetsResponse -> ShowS
Prelude.Show, forall x. Rep ListIPSetsResponse x -> ListIPSetsResponse
forall x. ListIPSetsResponse -> Rep ListIPSetsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListIPSetsResponse x -> ListIPSetsResponse
$cfrom :: forall x. ListIPSetsResponse -> Rep ListIPSetsResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListIPSetsResponse' 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', 'listIPSetsResponse_nextToken' - The pagination parameter to be used on the next list operation to
-- retrieve more items.
--
-- 'httpStatus', 'listIPSetsResponse_httpStatus' - The response's http status code.
--
-- 'ipSetIds', 'listIPSetsResponse_ipSetIds' - The IDs of the IPSet resources.
newListIPSetsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListIPSetsResponse
newListIPSetsResponse :: Int -> ListIPSetsResponse
newListIPSetsResponse Int
pHttpStatus_ =
  ListIPSetsResponse'
    { $sel:nextToken:ListIPSetsResponse' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListIPSetsResponse' :: Int
httpStatus = Int
pHttpStatus_,
      $sel:ipSetIds:ListIPSetsResponse' :: [Text]
ipSetIds = forall a. Monoid a => a
Prelude.mempty
    }

-- | The pagination parameter to be used on the next list operation to
-- retrieve more items.
listIPSetsResponse_nextToken :: Lens.Lens' ListIPSetsResponse (Prelude.Maybe Prelude.Text)
listIPSetsResponse_nextToken :: Lens' ListIPSetsResponse (Maybe Text)
listIPSetsResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListIPSetsResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListIPSetsResponse' :: ListIPSetsResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListIPSetsResponse
s@ListIPSetsResponse' {} Maybe Text
a -> ListIPSetsResponse
s {$sel:nextToken:ListIPSetsResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListIPSetsResponse)

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

-- | The IDs of the IPSet resources.
listIPSetsResponse_ipSetIds :: Lens.Lens' ListIPSetsResponse [Prelude.Text]
listIPSetsResponse_ipSetIds :: Lens' ListIPSetsResponse [Text]
listIPSetsResponse_ipSetIds = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListIPSetsResponse' {[Text]
ipSetIds :: [Text]
$sel:ipSetIds:ListIPSetsResponse' :: ListIPSetsResponse -> [Text]
ipSetIds} -> [Text]
ipSetIds) (\s :: ListIPSetsResponse
s@ListIPSetsResponse' {} [Text]
a -> ListIPSetsResponse
s {$sel:ipSetIds:ListIPSetsResponse' :: [Text]
ipSetIds = [Text]
a} :: ListIPSetsResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Prelude.NFData ListIPSetsResponse where
  rnf :: ListIPSetsResponse -> ()
rnf ListIPSetsResponse' {Int
[Text]
Maybe Text
ipSetIds :: [Text]
httpStatus :: Int
nextToken :: Maybe Text
$sel:ipSetIds:ListIPSetsResponse' :: ListIPSetsResponse -> [Text]
$sel:httpStatus:ListIPSetsResponse' :: ListIPSetsResponse -> Int
$sel:nextToken:ListIPSetsResponse' :: ListIPSetsResponse -> Maybe Text
..} =
    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
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [Text]
ipSetIds