{-# 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.XRay.ListResourcePolicies
-- 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 the list of resource policies in the target Amazon Web Services
-- account.
--
-- This operation returns paginated results.
module Amazonka.XRay.ListResourcePolicies
  ( -- * Creating a Request
    ListResourcePolicies (..),
    newListResourcePolicies,

    -- * Request Lenses
    listResourcePolicies_nextToken,

    -- * Destructuring the Response
    ListResourcePoliciesResponse (..),
    newListResourcePoliciesResponse,

    -- * Response Lenses
    listResourcePoliciesResponse_nextToken,
    listResourcePoliciesResponse_resourcePolicies,
    listResourcePoliciesResponse_httpStatus,
  )
where

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
import Amazonka.XRay.Types

-- | /See:/ 'newListResourcePolicies' smart constructor.
data ListResourcePolicies = ListResourcePolicies'
  { -- | Not currently supported.
    ListResourcePolicies -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text
  }
  deriving (ListResourcePolicies -> ListResourcePolicies -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListResourcePolicies -> ListResourcePolicies -> Bool
$c/= :: ListResourcePolicies -> ListResourcePolicies -> Bool
== :: ListResourcePolicies -> ListResourcePolicies -> Bool
$c== :: ListResourcePolicies -> ListResourcePolicies -> Bool
Prelude.Eq, ReadPrec [ListResourcePolicies]
ReadPrec ListResourcePolicies
Int -> ReadS ListResourcePolicies
ReadS [ListResourcePolicies]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListResourcePolicies]
$creadListPrec :: ReadPrec [ListResourcePolicies]
readPrec :: ReadPrec ListResourcePolicies
$creadPrec :: ReadPrec ListResourcePolicies
readList :: ReadS [ListResourcePolicies]
$creadList :: ReadS [ListResourcePolicies]
readsPrec :: Int -> ReadS ListResourcePolicies
$creadsPrec :: Int -> ReadS ListResourcePolicies
Prelude.Read, Int -> ListResourcePolicies -> ShowS
[ListResourcePolicies] -> ShowS
ListResourcePolicies -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListResourcePolicies] -> ShowS
$cshowList :: [ListResourcePolicies] -> ShowS
show :: ListResourcePolicies -> String
$cshow :: ListResourcePolicies -> String
showsPrec :: Int -> ListResourcePolicies -> ShowS
$cshowsPrec :: Int -> ListResourcePolicies -> ShowS
Prelude.Show, forall x. Rep ListResourcePolicies x -> ListResourcePolicies
forall x. ListResourcePolicies -> Rep ListResourcePolicies x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListResourcePolicies x -> ListResourcePolicies
$cfrom :: forall x. ListResourcePolicies -> Rep ListResourcePolicies x
Prelude.Generic)

-- |
-- Create a value of 'ListResourcePolicies' 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', 'listResourcePolicies_nextToken' - Not currently supported.
newListResourcePolicies ::
  ListResourcePolicies
newListResourcePolicies :: ListResourcePolicies
newListResourcePolicies =
  ListResourcePolicies' {$sel:nextToken:ListResourcePolicies' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing}

-- | Not currently supported.
listResourcePolicies_nextToken :: Lens.Lens' ListResourcePolicies (Prelude.Maybe Prelude.Text)
listResourcePolicies_nextToken :: Lens' ListResourcePolicies (Maybe Text)
listResourcePolicies_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListResourcePolicies' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListResourcePolicies' :: ListResourcePolicies -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListResourcePolicies
s@ListResourcePolicies' {} Maybe Text
a -> ListResourcePolicies
s {$sel:nextToken:ListResourcePolicies' :: Maybe Text
nextToken = Maybe Text
a} :: ListResourcePolicies)

instance Core.AWSPager ListResourcePolicies where
  page :: ListResourcePolicies
-> AWSResponse ListResourcePolicies -> Maybe ListResourcePolicies
page ListResourcePolicies
rq AWSResponse ListResourcePolicies
rs
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListResourcePolicies
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListResourcePoliciesResponse (Maybe Text)
listResourcePoliciesResponse_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 ListResourcePolicies
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListResourcePoliciesResponse (Maybe [ResourcePolicy])
listResourcePoliciesResponse_resourcePolicies
            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.$ ListResourcePolicies
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' ListResourcePolicies (Maybe Text)
listResourcePolicies_nextToken
          forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse ListResourcePolicies
rs
          forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListResourcePoliciesResponse (Maybe Text)
listResourcePoliciesResponse_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 ListResourcePolicies where
  type
    AWSResponse ListResourcePolicies =
      ListResourcePoliciesResponse
  request :: (Service -> Service)
-> ListResourcePolicies -> Request ListResourcePolicies
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 ListResourcePolicies
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse ListResourcePolicies)))
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 [ResourcePolicy] -> Int -> ListResourcePoliciesResponse
ListResourcePoliciesResponse'
            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.<*> ( Object
x
                            forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"ResourcePolicies"
                            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.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

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

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

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

instance Data.ToJSON ListResourcePolicies where
  toJSON :: ListResourcePolicies -> Value
toJSON ListResourcePolicies' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListResourcePolicies' :: ListResourcePolicies -> 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 ListResourcePolicies where
  toPath :: ListResourcePolicies -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/ListResourcePolicies"

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

-- | /See:/ 'newListResourcePoliciesResponse' smart constructor.
data ListResourcePoliciesResponse = ListResourcePoliciesResponse'
  { -- | Pagination token. Not currently supported.
    ListResourcePoliciesResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The list of resource policies in the target Amazon Web Services account.
    ListResourcePoliciesResponse -> Maybe [ResourcePolicy]
resourcePolicies :: Prelude.Maybe [ResourcePolicy],
    -- | The response's http status code.
    ListResourcePoliciesResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ListResourcePoliciesResponse
-> ListResourcePoliciesResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListResourcePoliciesResponse
-> ListResourcePoliciesResponse -> Bool
$c/= :: ListResourcePoliciesResponse
-> ListResourcePoliciesResponse -> Bool
== :: ListResourcePoliciesResponse
-> ListResourcePoliciesResponse -> Bool
$c== :: ListResourcePoliciesResponse
-> ListResourcePoliciesResponse -> Bool
Prelude.Eq, ReadPrec [ListResourcePoliciesResponse]
ReadPrec ListResourcePoliciesResponse
Int -> ReadS ListResourcePoliciesResponse
ReadS [ListResourcePoliciesResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListResourcePoliciesResponse]
$creadListPrec :: ReadPrec [ListResourcePoliciesResponse]
readPrec :: ReadPrec ListResourcePoliciesResponse
$creadPrec :: ReadPrec ListResourcePoliciesResponse
readList :: ReadS [ListResourcePoliciesResponse]
$creadList :: ReadS [ListResourcePoliciesResponse]
readsPrec :: Int -> ReadS ListResourcePoliciesResponse
$creadsPrec :: Int -> ReadS ListResourcePoliciesResponse
Prelude.Read, Int -> ListResourcePoliciesResponse -> ShowS
[ListResourcePoliciesResponse] -> ShowS
ListResourcePoliciesResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListResourcePoliciesResponse] -> ShowS
$cshowList :: [ListResourcePoliciesResponse] -> ShowS
show :: ListResourcePoliciesResponse -> String
$cshow :: ListResourcePoliciesResponse -> String
showsPrec :: Int -> ListResourcePoliciesResponse -> ShowS
$cshowsPrec :: Int -> ListResourcePoliciesResponse -> ShowS
Prelude.Show, forall x.
Rep ListResourcePoliciesResponse x -> ListResourcePoliciesResponse
forall x.
ListResourcePoliciesResponse -> Rep ListResourcePoliciesResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ListResourcePoliciesResponse x -> ListResourcePoliciesResponse
$cfrom :: forall x.
ListResourcePoliciesResponse -> Rep ListResourcePoliciesResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListResourcePoliciesResponse' 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', 'listResourcePoliciesResponse_nextToken' - Pagination token. Not currently supported.
--
-- 'resourcePolicies', 'listResourcePoliciesResponse_resourcePolicies' - The list of resource policies in the target Amazon Web Services account.
--
-- 'httpStatus', 'listResourcePoliciesResponse_httpStatus' - The response's http status code.
newListResourcePoliciesResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListResourcePoliciesResponse
newListResourcePoliciesResponse :: Int -> ListResourcePoliciesResponse
newListResourcePoliciesResponse Int
pHttpStatus_ =
  ListResourcePoliciesResponse'
    { $sel:nextToken:ListResourcePoliciesResponse' :: Maybe Text
nextToken =
        forall a. Maybe a
Prelude.Nothing,
      $sel:resourcePolicies:ListResourcePoliciesResponse' :: Maybe [ResourcePolicy]
resourcePolicies = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListResourcePoliciesResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Pagination token. Not currently supported.
listResourcePoliciesResponse_nextToken :: Lens.Lens' ListResourcePoliciesResponse (Prelude.Maybe Prelude.Text)
listResourcePoliciesResponse_nextToken :: Lens' ListResourcePoliciesResponse (Maybe Text)
listResourcePoliciesResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListResourcePoliciesResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListResourcePoliciesResponse' :: ListResourcePoliciesResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListResourcePoliciesResponse
s@ListResourcePoliciesResponse' {} Maybe Text
a -> ListResourcePoliciesResponse
s {$sel:nextToken:ListResourcePoliciesResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListResourcePoliciesResponse)

-- | The list of resource policies in the target Amazon Web Services account.
listResourcePoliciesResponse_resourcePolicies :: Lens.Lens' ListResourcePoliciesResponse (Prelude.Maybe [ResourcePolicy])
listResourcePoliciesResponse_resourcePolicies :: Lens' ListResourcePoliciesResponse (Maybe [ResourcePolicy])
listResourcePoliciesResponse_resourcePolicies = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListResourcePoliciesResponse' {Maybe [ResourcePolicy]
resourcePolicies :: Maybe [ResourcePolicy]
$sel:resourcePolicies:ListResourcePoliciesResponse' :: ListResourcePoliciesResponse -> Maybe [ResourcePolicy]
resourcePolicies} -> Maybe [ResourcePolicy]
resourcePolicies) (\s :: ListResourcePoliciesResponse
s@ListResourcePoliciesResponse' {} Maybe [ResourcePolicy]
a -> ListResourcePoliciesResponse
s {$sel:resourcePolicies:ListResourcePoliciesResponse' :: Maybe [ResourcePolicy]
resourcePolicies = Maybe [ResourcePolicy]
a} :: ListResourcePoliciesResponse) 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.
listResourcePoliciesResponse_httpStatus :: Lens.Lens' ListResourcePoliciesResponse Prelude.Int
listResourcePoliciesResponse_httpStatus :: Lens' ListResourcePoliciesResponse Int
listResourcePoliciesResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListResourcePoliciesResponse' {Int
httpStatus :: Int
$sel:httpStatus:ListResourcePoliciesResponse' :: ListResourcePoliciesResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: ListResourcePoliciesResponse
s@ListResourcePoliciesResponse' {} Int
a -> ListResourcePoliciesResponse
s {$sel:httpStatus:ListResourcePoliciesResponse' :: Int
httpStatus = Int
a} :: ListResourcePoliciesResponse)

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