{-# 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.Organizations.ListPoliciesForTarget
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Lists the policies that are directly attached to the specified target
-- root, organizational unit (OU), or account. You must specify the policy
-- type that you want included in the returned list.
--
-- Always check the @NextToken@ response parameter for a @null@ value when
-- calling a @List*@ operation. These operations can occasionally return an
-- empty set of results even when there are more results available. The
-- @NextToken@ response parameter value is @null@ /only/ when there are no
-- more results to display.
--
-- This operation can be called only from the organization\'s management
-- account or by a member account that is a delegated administrator for an
-- AWS service.
--
-- This operation returns paginated results.
module Amazonka.Organizations.ListPoliciesForTarget
  ( -- * Creating a Request
    ListPoliciesForTarget (..),
    newListPoliciesForTarget,

    -- * Request Lenses
    listPoliciesForTarget_nextToken,
    listPoliciesForTarget_maxResults,
    listPoliciesForTarget_targetId,
    listPoliciesForTarget_filter,

    -- * Destructuring the Response
    ListPoliciesForTargetResponse (..),
    newListPoliciesForTargetResponse,

    -- * Response Lenses
    listPoliciesForTargetResponse_nextToken,
    listPoliciesForTargetResponse_policies,
    listPoliciesForTargetResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.Organizations.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newListPoliciesForTarget' smart constructor.
data ListPoliciesForTarget = ListPoliciesForTarget'
  { -- | The parameter for receiving additional results if you receive a
    -- @NextToken@ response in a previous request. A @NextToken@ response
    -- indicates that more output is available. Set this parameter to the value
    -- of the previous call\'s @NextToken@ response to indicate where the
    -- output should continue from.
    ListPoliciesForTarget -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The total number of results that you want included on each page of the
    -- response. If you do not include this parameter, it defaults to a value
    -- that is specific to the operation. If additional items exist beyond the
    -- maximum you specify, the @NextToken@ response element is present and has
    -- a value (is not null). Include that value as the @NextToken@ request
    -- parameter in the next call to the operation to get the next part of the
    -- results. Note that Organizations might return fewer results than the
    -- maximum even when there are more results available. You should check
    -- @NextToken@ after every operation to ensure that you receive all of the
    -- results.
    ListPoliciesForTarget -> Maybe Natural
maxResults :: Prelude.Maybe Prelude.Natural,
    -- | The unique identifier (ID) of the root, organizational unit, or account
    -- whose policies you want to list.
    --
    -- The <http://wikipedia.org/wiki/regex regex pattern> for a target ID
    -- string requires one of the following:
    --
    -- -   __Root__ - A string that begins with \"r-\" followed by from 4 to 32
    --     lowercase letters or digits.
    --
    -- -   __Account__ - A string that consists of exactly 12 digits.
    --
    -- -   __Organizational unit (OU)__ - A string that begins with \"ou-\"
    --     followed by from 4 to 32 lowercase letters or digits (the ID of the
    --     root that the OU is in). This string is followed by a second \"-\"
    --     dash and from 8 to 32 additional lowercase letters or digits.
    ListPoliciesForTarget -> Text
targetId :: Prelude.Text,
    -- | The type of policy that you want to include in the returned list. You
    -- must specify one of the following values:
    --
    -- -   <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_ai-opt-out.html AISERVICES_OPT_OUT_POLICY>
    --
    -- -   <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_backup.html BACKUP_POLICY>
    --
    -- -   <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_scp.html SERVICE_CONTROL_POLICY>
    --
    -- -   <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_tag-policies.html TAG_POLICY>
    ListPoliciesForTarget -> PolicyType
filter' :: PolicyType
  }
  deriving (ListPoliciesForTarget -> ListPoliciesForTarget -> Bool
(ListPoliciesForTarget -> ListPoliciesForTarget -> Bool)
-> (ListPoliciesForTarget -> ListPoliciesForTarget -> Bool)
-> Eq ListPoliciesForTarget
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListPoliciesForTarget -> ListPoliciesForTarget -> Bool
$c/= :: ListPoliciesForTarget -> ListPoliciesForTarget -> Bool
== :: ListPoliciesForTarget -> ListPoliciesForTarget -> Bool
$c== :: ListPoliciesForTarget -> ListPoliciesForTarget -> Bool
Prelude.Eq, ReadPrec [ListPoliciesForTarget]
ReadPrec ListPoliciesForTarget
Int -> ReadS ListPoliciesForTarget
ReadS [ListPoliciesForTarget]
(Int -> ReadS ListPoliciesForTarget)
-> ReadS [ListPoliciesForTarget]
-> ReadPrec ListPoliciesForTarget
-> ReadPrec [ListPoliciesForTarget]
-> Read ListPoliciesForTarget
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListPoliciesForTarget]
$creadListPrec :: ReadPrec [ListPoliciesForTarget]
readPrec :: ReadPrec ListPoliciesForTarget
$creadPrec :: ReadPrec ListPoliciesForTarget
readList :: ReadS [ListPoliciesForTarget]
$creadList :: ReadS [ListPoliciesForTarget]
readsPrec :: Int -> ReadS ListPoliciesForTarget
$creadsPrec :: Int -> ReadS ListPoliciesForTarget
Prelude.Read, Int -> ListPoliciesForTarget -> ShowS
[ListPoliciesForTarget] -> ShowS
ListPoliciesForTarget -> String
(Int -> ListPoliciesForTarget -> ShowS)
-> (ListPoliciesForTarget -> String)
-> ([ListPoliciesForTarget] -> ShowS)
-> Show ListPoliciesForTarget
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListPoliciesForTarget] -> ShowS
$cshowList :: [ListPoliciesForTarget] -> ShowS
show :: ListPoliciesForTarget -> String
$cshow :: ListPoliciesForTarget -> String
showsPrec :: Int -> ListPoliciesForTarget -> ShowS
$cshowsPrec :: Int -> ListPoliciesForTarget -> ShowS
Prelude.Show, (forall x. ListPoliciesForTarget -> Rep ListPoliciesForTarget x)
-> (forall x. Rep ListPoliciesForTarget x -> ListPoliciesForTarget)
-> Generic ListPoliciesForTarget
forall x. Rep ListPoliciesForTarget x -> ListPoliciesForTarget
forall x. ListPoliciesForTarget -> Rep ListPoliciesForTarget x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListPoliciesForTarget x -> ListPoliciesForTarget
$cfrom :: forall x. ListPoliciesForTarget -> Rep ListPoliciesForTarget x
Prelude.Generic)

-- |
-- Create a value of 'ListPoliciesForTarget' 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', 'listPoliciesForTarget_nextToken' - The parameter for receiving additional results if you receive a
-- @NextToken@ response in a previous request. A @NextToken@ response
-- indicates that more output is available. Set this parameter to the value
-- of the previous call\'s @NextToken@ response to indicate where the
-- output should continue from.
--
-- 'maxResults', 'listPoliciesForTarget_maxResults' - The total number of results that you want included on each page of the
-- response. If you do not include this parameter, it defaults to a value
-- that is specific to the operation. If additional items exist beyond the
-- maximum you specify, the @NextToken@ response element is present and has
-- a value (is not null). Include that value as the @NextToken@ request
-- parameter in the next call to the operation to get the next part of the
-- results. Note that Organizations might return fewer results than the
-- maximum even when there are more results available. You should check
-- @NextToken@ after every operation to ensure that you receive all of the
-- results.
--
-- 'targetId', 'listPoliciesForTarget_targetId' - The unique identifier (ID) of the root, organizational unit, or account
-- whose policies you want to list.
--
-- The <http://wikipedia.org/wiki/regex regex pattern> for a target ID
-- string requires one of the following:
--
-- -   __Root__ - A string that begins with \"r-\" followed by from 4 to 32
--     lowercase letters or digits.
--
-- -   __Account__ - A string that consists of exactly 12 digits.
--
-- -   __Organizational unit (OU)__ - A string that begins with \"ou-\"
--     followed by from 4 to 32 lowercase letters or digits (the ID of the
--     root that the OU is in). This string is followed by a second \"-\"
--     dash and from 8 to 32 additional lowercase letters or digits.
--
-- 'filter'', 'listPoliciesForTarget_filter' - The type of policy that you want to include in the returned list. You
-- must specify one of the following values:
--
-- -   <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_ai-opt-out.html AISERVICES_OPT_OUT_POLICY>
--
-- -   <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_backup.html BACKUP_POLICY>
--
-- -   <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_scp.html SERVICE_CONTROL_POLICY>
--
-- -   <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_tag-policies.html TAG_POLICY>
newListPoliciesForTarget ::
  -- | 'targetId'
  Prelude.Text ->
  -- | 'filter''
  PolicyType ->
  ListPoliciesForTarget
newListPoliciesForTarget :: Text -> PolicyType -> ListPoliciesForTarget
newListPoliciesForTarget Text
pTargetId_ PolicyType
pFilter_ =
  ListPoliciesForTarget' :: Maybe Text
-> Maybe Natural -> Text -> PolicyType -> ListPoliciesForTarget
ListPoliciesForTarget'
    { $sel:nextToken:ListPoliciesForTarget' :: Maybe Text
nextToken = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:maxResults:ListPoliciesForTarget' :: Maybe Natural
maxResults = Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:targetId:ListPoliciesForTarget' :: Text
targetId = Text
pTargetId_,
      $sel:filter':ListPoliciesForTarget' :: PolicyType
filter' = PolicyType
pFilter_
    }

-- | The parameter for receiving additional results if you receive a
-- @NextToken@ response in a previous request. A @NextToken@ response
-- indicates that more output is available. Set this parameter to the value
-- of the previous call\'s @NextToken@ response to indicate where the
-- output should continue from.
listPoliciesForTarget_nextToken :: Lens.Lens' ListPoliciesForTarget (Prelude.Maybe Prelude.Text)
listPoliciesForTarget_nextToken :: (Maybe Text -> f (Maybe Text))
-> ListPoliciesForTarget -> f ListPoliciesForTarget
listPoliciesForTarget_nextToken = (ListPoliciesForTarget -> Maybe Text)
-> (ListPoliciesForTarget -> Maybe Text -> ListPoliciesForTarget)
-> Lens
     ListPoliciesForTarget
     ListPoliciesForTarget
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListPoliciesForTarget' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListPoliciesForTarget' :: ListPoliciesForTarget -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListPoliciesForTarget
s@ListPoliciesForTarget' {} Maybe Text
a -> ListPoliciesForTarget
s {$sel:nextToken:ListPoliciesForTarget' :: Maybe Text
nextToken = Maybe Text
a} :: ListPoliciesForTarget)

-- | The total number of results that you want included on each page of the
-- response. If you do not include this parameter, it defaults to a value
-- that is specific to the operation. If additional items exist beyond the
-- maximum you specify, the @NextToken@ response element is present and has
-- a value (is not null). Include that value as the @NextToken@ request
-- parameter in the next call to the operation to get the next part of the
-- results. Note that Organizations might return fewer results than the
-- maximum even when there are more results available. You should check
-- @NextToken@ after every operation to ensure that you receive all of the
-- results.
listPoliciesForTarget_maxResults :: Lens.Lens' ListPoliciesForTarget (Prelude.Maybe Prelude.Natural)
listPoliciesForTarget_maxResults :: (Maybe Natural -> f (Maybe Natural))
-> ListPoliciesForTarget -> f ListPoliciesForTarget
listPoliciesForTarget_maxResults = (ListPoliciesForTarget -> Maybe Natural)
-> (ListPoliciesForTarget
    -> Maybe Natural -> ListPoliciesForTarget)
-> Lens
     ListPoliciesForTarget
     ListPoliciesForTarget
     (Maybe Natural)
     (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListPoliciesForTarget' {Maybe Natural
maxResults :: Maybe Natural
$sel:maxResults:ListPoliciesForTarget' :: ListPoliciesForTarget -> Maybe Natural
maxResults} -> Maybe Natural
maxResults) (\s :: ListPoliciesForTarget
s@ListPoliciesForTarget' {} Maybe Natural
a -> ListPoliciesForTarget
s {$sel:maxResults:ListPoliciesForTarget' :: Maybe Natural
maxResults = Maybe Natural
a} :: ListPoliciesForTarget)

-- | The unique identifier (ID) of the root, organizational unit, or account
-- whose policies you want to list.
--
-- The <http://wikipedia.org/wiki/regex regex pattern> for a target ID
-- string requires one of the following:
--
-- -   __Root__ - A string that begins with \"r-\" followed by from 4 to 32
--     lowercase letters or digits.
--
-- -   __Account__ - A string that consists of exactly 12 digits.
--
-- -   __Organizational unit (OU)__ - A string that begins with \"ou-\"
--     followed by from 4 to 32 lowercase letters or digits (the ID of the
--     root that the OU is in). This string is followed by a second \"-\"
--     dash and from 8 to 32 additional lowercase letters or digits.
listPoliciesForTarget_targetId :: Lens.Lens' ListPoliciesForTarget Prelude.Text
listPoliciesForTarget_targetId :: (Text -> f Text)
-> ListPoliciesForTarget -> f ListPoliciesForTarget
listPoliciesForTarget_targetId = (ListPoliciesForTarget -> Text)
-> (ListPoliciesForTarget -> Text -> ListPoliciesForTarget)
-> Lens ListPoliciesForTarget ListPoliciesForTarget Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListPoliciesForTarget' {Text
targetId :: Text
$sel:targetId:ListPoliciesForTarget' :: ListPoliciesForTarget -> Text
targetId} -> Text
targetId) (\s :: ListPoliciesForTarget
s@ListPoliciesForTarget' {} Text
a -> ListPoliciesForTarget
s {$sel:targetId:ListPoliciesForTarget' :: Text
targetId = Text
a} :: ListPoliciesForTarget)

-- | The type of policy that you want to include in the returned list. You
-- must specify one of the following values:
--
-- -   <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_ai-opt-out.html AISERVICES_OPT_OUT_POLICY>
--
-- -   <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_backup.html BACKUP_POLICY>
--
-- -   <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_scp.html SERVICE_CONTROL_POLICY>
--
-- -   <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_tag-policies.html TAG_POLICY>
listPoliciesForTarget_filter :: Lens.Lens' ListPoliciesForTarget PolicyType
listPoliciesForTarget_filter :: (PolicyType -> f PolicyType)
-> ListPoliciesForTarget -> f ListPoliciesForTarget
listPoliciesForTarget_filter = (ListPoliciesForTarget -> PolicyType)
-> (ListPoliciesForTarget -> PolicyType -> ListPoliciesForTarget)
-> Lens
     ListPoliciesForTarget ListPoliciesForTarget PolicyType PolicyType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListPoliciesForTarget' {PolicyType
filter' :: PolicyType
$sel:filter':ListPoliciesForTarget' :: ListPoliciesForTarget -> PolicyType
filter'} -> PolicyType
filter') (\s :: ListPoliciesForTarget
s@ListPoliciesForTarget' {} PolicyType
a -> ListPoliciesForTarget
s {$sel:filter':ListPoliciesForTarget' :: PolicyType
filter' = PolicyType
a} :: ListPoliciesForTarget)

instance Core.AWSPager ListPoliciesForTarget where
  page :: ListPoliciesForTarget
-> AWSResponse ListPoliciesForTarget -> Maybe ListPoliciesForTarget
page ListPoliciesForTarget
rq AWSResponse ListPoliciesForTarget
rs
    | Maybe Text -> Bool
forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListPoliciesForTarget
ListPoliciesForTargetResponse
rs
            ListPoliciesForTargetResponse
-> Getting (First Text) ListPoliciesForTargetResponse Text
-> Maybe Text
forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? (Maybe Text -> Const (First Text) (Maybe Text))
-> ListPoliciesForTargetResponse
-> Const (First Text) ListPoliciesForTargetResponse
Lens' ListPoliciesForTargetResponse (Maybe Text)
listPoliciesForTargetResponse_nextToken
              ((Maybe Text -> Const (First Text) (Maybe Text))
 -> ListPoliciesForTargetResponse
 -> Const (First Text) ListPoliciesForTargetResponse)
-> ((Text -> Const (First Text) Text)
    -> Maybe Text -> Const (First Text) (Maybe Text))
-> Getting (First Text) ListPoliciesForTargetResponse Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (Text -> Const (First Text) Text)
-> Maybe Text -> Const (First Text) (Maybe Text)
forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just
        ) =
      Maybe ListPoliciesForTarget
forall a. Maybe a
Prelude.Nothing
    | Maybe [PolicySummary] -> Bool
forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListPoliciesForTarget
ListPoliciesForTargetResponse
rs
            ListPoliciesForTargetResponse
-> Getting
     (First [PolicySummary])
     ListPoliciesForTargetResponse
     [PolicySummary]
-> Maybe [PolicySummary]
forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? (Maybe [PolicySummary]
 -> Const (First [PolicySummary]) (Maybe [PolicySummary]))
-> ListPoliciesForTargetResponse
-> Const (First [PolicySummary]) ListPoliciesForTargetResponse
Lens' ListPoliciesForTargetResponse (Maybe [PolicySummary])
listPoliciesForTargetResponse_policies
              ((Maybe [PolicySummary]
  -> Const (First [PolicySummary]) (Maybe [PolicySummary]))
 -> ListPoliciesForTargetResponse
 -> Const (First [PolicySummary]) ListPoliciesForTargetResponse)
-> (([PolicySummary]
     -> Const (First [PolicySummary]) [PolicySummary])
    -> Maybe [PolicySummary]
    -> Const (First [PolicySummary]) (Maybe [PolicySummary]))
-> Getting
     (First [PolicySummary])
     ListPoliciesForTargetResponse
     [PolicySummary]
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([PolicySummary] -> Const (First [PolicySummary]) [PolicySummary])
-> Maybe [PolicySummary]
-> Const (First [PolicySummary]) (Maybe [PolicySummary])
forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just
        ) =
      Maybe ListPoliciesForTarget
forall a. Maybe a
Prelude.Nothing
    | Bool
Prelude.otherwise =
      ListPoliciesForTarget -> Maybe ListPoliciesForTarget
forall a. a -> Maybe a
Prelude.Just (ListPoliciesForTarget -> Maybe ListPoliciesForTarget)
-> ListPoliciesForTarget -> Maybe ListPoliciesForTarget
forall a b. (a -> b) -> a -> b
Prelude.$
        ListPoliciesForTarget
rq
          ListPoliciesForTarget
-> (ListPoliciesForTarget -> ListPoliciesForTarget)
-> ListPoliciesForTarget
forall a b. a -> (a -> b) -> b
Prelude.& (Maybe Text -> Identity (Maybe Text))
-> ListPoliciesForTarget -> Identity ListPoliciesForTarget
Lens
  ListPoliciesForTarget
  ListPoliciesForTarget
  (Maybe Text)
  (Maybe Text)
listPoliciesForTarget_nextToken
          ((Maybe Text -> Identity (Maybe Text))
 -> ListPoliciesForTarget -> Identity ListPoliciesForTarget)
-> Maybe Text -> ListPoliciesForTarget -> ListPoliciesForTarget
forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse ListPoliciesForTarget
ListPoliciesForTargetResponse
rs
          ListPoliciesForTargetResponse
-> Getting (First Text) ListPoliciesForTargetResponse Text
-> Maybe Text
forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? (Maybe Text -> Const (First Text) (Maybe Text))
-> ListPoliciesForTargetResponse
-> Const (First Text) ListPoliciesForTargetResponse
Lens' ListPoliciesForTargetResponse (Maybe Text)
listPoliciesForTargetResponse_nextToken
            ((Maybe Text -> Const (First Text) (Maybe Text))
 -> ListPoliciesForTargetResponse
 -> Const (First Text) ListPoliciesForTargetResponse)
-> ((Text -> Const (First Text) Text)
    -> Maybe Text -> Const (First Text) (Maybe Text))
-> Getting (First Text) ListPoliciesForTargetResponse Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (Text -> Const (First Text) Text)
-> Maybe Text -> Const (First Text) (Maybe Text)
forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just

instance Core.AWSRequest ListPoliciesForTarget where
  type
    AWSResponse ListPoliciesForTarget =
      ListPoliciesForTargetResponse
  request :: ListPoliciesForTarget -> Request ListPoliciesForTarget
request = Service -> ListPoliciesForTarget -> Request ListPoliciesForTarget
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy ListPoliciesForTarget
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse ListPoliciesForTarget)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse ListPoliciesForTarget))
-> Logger
-> Service
-> Proxy ListPoliciesForTarget
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse ListPoliciesForTarget)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Text
-> Maybe [PolicySummary] -> Int -> ListPoliciesForTargetResponse
ListPoliciesForTargetResponse'
            (Maybe Text
 -> Maybe [PolicySummary] -> Int -> ListPoliciesForTargetResponse)
-> Either String (Maybe Text)
-> Either
     String
     (Maybe [PolicySummary] -> Int -> ListPoliciesForTargetResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"NextToken")
            Either
  String
  (Maybe [PolicySummary] -> Int -> ListPoliciesForTargetResponse)
-> Either String (Maybe [PolicySummary])
-> Either String (Int -> ListPoliciesForTargetResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Maybe (Maybe [PolicySummary]))
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"Policies" Either String (Maybe (Maybe [PolicySummary]))
-> Maybe [PolicySummary] -> Either String (Maybe [PolicySummary])
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ Maybe [PolicySummary]
forall a. Monoid a => a
Prelude.mempty)
            Either String (Int -> ListPoliciesForTargetResponse)
-> Either String Int -> Either String ListPoliciesForTargetResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable ListPoliciesForTarget

instance Prelude.NFData ListPoliciesForTarget

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

instance Core.ToJSON ListPoliciesForTarget where
  toJSON :: ListPoliciesForTarget -> Value
toJSON ListPoliciesForTarget' {Maybe Natural
Maybe Text
Text
PolicyType
filter' :: PolicyType
targetId :: Text
maxResults :: Maybe Natural
nextToken :: Maybe Text
$sel:filter':ListPoliciesForTarget' :: ListPoliciesForTarget -> PolicyType
$sel:targetId:ListPoliciesForTarget' :: ListPoliciesForTarget -> Text
$sel:maxResults:ListPoliciesForTarget' :: ListPoliciesForTarget -> Maybe Natural
$sel:nextToken:ListPoliciesForTarget' :: ListPoliciesForTarget -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"NextToken" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
nextToken,
            (Text
"MaxResults" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Natural -> Pair) -> Maybe Natural -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
maxResults,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"TargetId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
targetId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Filter" Text -> PolicyType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= PolicyType
filter')
          ]
      )

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

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

-- | /See:/ 'newListPoliciesForTargetResponse' smart constructor.
data ListPoliciesForTargetResponse = ListPoliciesForTargetResponse'
  { -- | If present, indicates that more output is available than is included in
    -- the current response. Use this value in the @NextToken@ request
    -- parameter in a subsequent call to the operation to get the next part of
    -- the output. You should repeat this until the @NextToken@ response
    -- element comes back as @null@.
    ListPoliciesForTargetResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The list of policies that match the criteria in the request.
    ListPoliciesForTargetResponse -> Maybe [PolicySummary]
policies :: Prelude.Maybe [PolicySummary],
    -- | The response's http status code.
    ListPoliciesForTargetResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ListPoliciesForTargetResponse
-> ListPoliciesForTargetResponse -> Bool
(ListPoliciesForTargetResponse
 -> ListPoliciesForTargetResponse -> Bool)
-> (ListPoliciesForTargetResponse
    -> ListPoliciesForTargetResponse -> Bool)
-> Eq ListPoliciesForTargetResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListPoliciesForTargetResponse
-> ListPoliciesForTargetResponse -> Bool
$c/= :: ListPoliciesForTargetResponse
-> ListPoliciesForTargetResponse -> Bool
== :: ListPoliciesForTargetResponse
-> ListPoliciesForTargetResponse -> Bool
$c== :: ListPoliciesForTargetResponse
-> ListPoliciesForTargetResponse -> Bool
Prelude.Eq, ReadPrec [ListPoliciesForTargetResponse]
ReadPrec ListPoliciesForTargetResponse
Int -> ReadS ListPoliciesForTargetResponse
ReadS [ListPoliciesForTargetResponse]
(Int -> ReadS ListPoliciesForTargetResponse)
-> ReadS [ListPoliciesForTargetResponse]
-> ReadPrec ListPoliciesForTargetResponse
-> ReadPrec [ListPoliciesForTargetResponse]
-> Read ListPoliciesForTargetResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListPoliciesForTargetResponse]
$creadListPrec :: ReadPrec [ListPoliciesForTargetResponse]
readPrec :: ReadPrec ListPoliciesForTargetResponse
$creadPrec :: ReadPrec ListPoliciesForTargetResponse
readList :: ReadS [ListPoliciesForTargetResponse]
$creadList :: ReadS [ListPoliciesForTargetResponse]
readsPrec :: Int -> ReadS ListPoliciesForTargetResponse
$creadsPrec :: Int -> ReadS ListPoliciesForTargetResponse
Prelude.Read, Int -> ListPoliciesForTargetResponse -> ShowS
[ListPoliciesForTargetResponse] -> ShowS
ListPoliciesForTargetResponse -> String
(Int -> ListPoliciesForTargetResponse -> ShowS)
-> (ListPoliciesForTargetResponse -> String)
-> ([ListPoliciesForTargetResponse] -> ShowS)
-> Show ListPoliciesForTargetResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListPoliciesForTargetResponse] -> ShowS
$cshowList :: [ListPoliciesForTargetResponse] -> ShowS
show :: ListPoliciesForTargetResponse -> String
$cshow :: ListPoliciesForTargetResponse -> String
showsPrec :: Int -> ListPoliciesForTargetResponse -> ShowS
$cshowsPrec :: Int -> ListPoliciesForTargetResponse -> ShowS
Prelude.Show, (forall x.
 ListPoliciesForTargetResponse
 -> Rep ListPoliciesForTargetResponse x)
-> (forall x.
    Rep ListPoliciesForTargetResponse x
    -> ListPoliciesForTargetResponse)
-> Generic ListPoliciesForTargetResponse
forall x.
Rep ListPoliciesForTargetResponse x
-> ListPoliciesForTargetResponse
forall x.
ListPoliciesForTargetResponse
-> Rep ListPoliciesForTargetResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ListPoliciesForTargetResponse x
-> ListPoliciesForTargetResponse
$cfrom :: forall x.
ListPoliciesForTargetResponse
-> Rep ListPoliciesForTargetResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListPoliciesForTargetResponse' 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', 'listPoliciesForTargetResponse_nextToken' - If present, indicates that more output is available than is included in
-- the current response. Use this value in the @NextToken@ request
-- parameter in a subsequent call to the operation to get the next part of
-- the output. You should repeat this until the @NextToken@ response
-- element comes back as @null@.
--
-- 'policies', 'listPoliciesForTargetResponse_policies' - The list of policies that match the criteria in the request.
--
-- 'httpStatus', 'listPoliciesForTargetResponse_httpStatus' - The response's http status code.
newListPoliciesForTargetResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListPoliciesForTargetResponse
newListPoliciesForTargetResponse :: Int -> ListPoliciesForTargetResponse
newListPoliciesForTargetResponse Int
pHttpStatus_ =
  ListPoliciesForTargetResponse' :: Maybe Text
-> Maybe [PolicySummary] -> Int -> ListPoliciesForTargetResponse
ListPoliciesForTargetResponse'
    { $sel:nextToken:ListPoliciesForTargetResponse' :: Maybe Text
nextToken =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:policies:ListPoliciesForTargetResponse' :: Maybe [PolicySummary]
policies = Maybe [PolicySummary]
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListPoliciesForTargetResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | If present, indicates that more output is available than is included in
-- the current response. Use this value in the @NextToken@ request
-- parameter in a subsequent call to the operation to get the next part of
-- the output. You should repeat this until the @NextToken@ response
-- element comes back as @null@.
listPoliciesForTargetResponse_nextToken :: Lens.Lens' ListPoliciesForTargetResponse (Prelude.Maybe Prelude.Text)
listPoliciesForTargetResponse_nextToken :: (Maybe Text -> f (Maybe Text))
-> ListPoliciesForTargetResponse -> f ListPoliciesForTargetResponse
listPoliciesForTargetResponse_nextToken = (ListPoliciesForTargetResponse -> Maybe Text)
-> (ListPoliciesForTargetResponse
    -> Maybe Text -> ListPoliciesForTargetResponse)
-> Lens' ListPoliciesForTargetResponse (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListPoliciesForTargetResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListPoliciesForTargetResponse' :: ListPoliciesForTargetResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListPoliciesForTargetResponse
s@ListPoliciesForTargetResponse' {} Maybe Text
a -> ListPoliciesForTargetResponse
s {$sel:nextToken:ListPoliciesForTargetResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListPoliciesForTargetResponse)

-- | The list of policies that match the criteria in the request.
listPoliciesForTargetResponse_policies :: Lens.Lens' ListPoliciesForTargetResponse (Prelude.Maybe [PolicySummary])
listPoliciesForTargetResponse_policies :: (Maybe [PolicySummary] -> f (Maybe [PolicySummary]))
-> ListPoliciesForTargetResponse -> f ListPoliciesForTargetResponse
listPoliciesForTargetResponse_policies = (ListPoliciesForTargetResponse -> Maybe [PolicySummary])
-> (ListPoliciesForTargetResponse
    -> Maybe [PolicySummary] -> ListPoliciesForTargetResponse)
-> Lens' ListPoliciesForTargetResponse (Maybe [PolicySummary])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListPoliciesForTargetResponse' {Maybe [PolicySummary]
policies :: Maybe [PolicySummary]
$sel:policies:ListPoliciesForTargetResponse' :: ListPoliciesForTargetResponse -> Maybe [PolicySummary]
policies} -> Maybe [PolicySummary]
policies) (\s :: ListPoliciesForTargetResponse
s@ListPoliciesForTargetResponse' {} Maybe [PolicySummary]
a -> ListPoliciesForTargetResponse
s {$sel:policies:ListPoliciesForTargetResponse' :: Maybe [PolicySummary]
policies = Maybe [PolicySummary]
a} :: ListPoliciesForTargetResponse) ((Maybe [PolicySummary] -> f (Maybe [PolicySummary]))
 -> ListPoliciesForTargetResponse
 -> f ListPoliciesForTargetResponse)
-> ((Maybe [PolicySummary] -> f (Maybe [PolicySummary]))
    -> Maybe [PolicySummary] -> f (Maybe [PolicySummary]))
-> (Maybe [PolicySummary] -> f (Maybe [PolicySummary]))
-> ListPoliciesForTargetResponse
-> f ListPoliciesForTargetResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [PolicySummary] [PolicySummary] [PolicySummary] [PolicySummary]
-> Iso
     (Maybe [PolicySummary])
     (Maybe [PolicySummary])
     (Maybe [PolicySummary])
     (Maybe [PolicySummary])
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 AnIso
  [PolicySummary] [PolicySummary] [PolicySummary] [PolicySummary]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.NFData ListPoliciesForTargetResponse