{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# 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.Types.AttachedPolicy
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.IAM.Types.AttachedPolicy 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

-- | Contains information about an attached policy.
--
-- An attached policy is a managed policy that has been attached to a user,
-- group, or role. This data type is used as a response element in the
-- ListAttachedGroupPolicies, ListAttachedRolePolicies,
-- ListAttachedUserPolicies, and GetAccountAuthorizationDetails operations.
--
-- For more information about managed policies, refer to
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/policies-managed-vs-inline.html Managed policies and inline policies>
-- in the /IAM User Guide/.
--
-- /See:/ 'newAttachedPolicy' smart constructor.
data AttachedPolicy = AttachedPolicy'
  { AttachedPolicy -> Maybe Text
policyArn :: Prelude.Maybe Prelude.Text,
    -- | The friendly name of the attached policy.
    AttachedPolicy -> Maybe Text
policyName :: Prelude.Maybe Prelude.Text
  }
  deriving (AttachedPolicy -> AttachedPolicy -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AttachedPolicy -> AttachedPolicy -> Bool
$c/= :: AttachedPolicy -> AttachedPolicy -> Bool
== :: AttachedPolicy -> AttachedPolicy -> Bool
$c== :: AttachedPolicy -> AttachedPolicy -> Bool
Prelude.Eq, ReadPrec [AttachedPolicy]
ReadPrec AttachedPolicy
Int -> ReadS AttachedPolicy
ReadS [AttachedPolicy]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AttachedPolicy]
$creadListPrec :: ReadPrec [AttachedPolicy]
readPrec :: ReadPrec AttachedPolicy
$creadPrec :: ReadPrec AttachedPolicy
readList :: ReadS [AttachedPolicy]
$creadList :: ReadS [AttachedPolicy]
readsPrec :: Int -> ReadS AttachedPolicy
$creadsPrec :: Int -> ReadS AttachedPolicy
Prelude.Read, Int -> AttachedPolicy -> ShowS
[AttachedPolicy] -> ShowS
AttachedPolicy -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AttachedPolicy] -> ShowS
$cshowList :: [AttachedPolicy] -> ShowS
show :: AttachedPolicy -> String
$cshow :: AttachedPolicy -> String
showsPrec :: Int -> AttachedPolicy -> ShowS
$cshowsPrec :: Int -> AttachedPolicy -> ShowS
Prelude.Show, forall x. Rep AttachedPolicy x -> AttachedPolicy
forall x. AttachedPolicy -> Rep AttachedPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AttachedPolicy x -> AttachedPolicy
$cfrom :: forall x. AttachedPolicy -> Rep AttachedPolicy x
Prelude.Generic)

-- |
-- Create a value of 'AttachedPolicy' 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:
--
-- 'policyArn', 'attachedPolicy_policyArn' - Undocumented member.
--
-- 'policyName', 'attachedPolicy_policyName' - The friendly name of the attached policy.
newAttachedPolicy ::
  AttachedPolicy
newAttachedPolicy :: AttachedPolicy
newAttachedPolicy =
  AttachedPolicy'
    { $sel:policyArn:AttachedPolicy' :: Maybe Text
policyArn = forall a. Maybe a
Prelude.Nothing,
      $sel:policyName:AttachedPolicy' :: Maybe Text
policyName = forall a. Maybe a
Prelude.Nothing
    }

-- | Undocumented member.
attachedPolicy_policyArn :: Lens.Lens' AttachedPolicy (Prelude.Maybe Prelude.Text)
attachedPolicy_policyArn :: Lens' AttachedPolicy (Maybe Text)
attachedPolicy_policyArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttachedPolicy' {Maybe Text
policyArn :: Maybe Text
$sel:policyArn:AttachedPolicy' :: AttachedPolicy -> Maybe Text
policyArn} -> Maybe Text
policyArn) (\s :: AttachedPolicy
s@AttachedPolicy' {} Maybe Text
a -> AttachedPolicy
s {$sel:policyArn:AttachedPolicy' :: Maybe Text
policyArn = Maybe Text
a} :: AttachedPolicy)

-- | The friendly name of the attached policy.
attachedPolicy_policyName :: Lens.Lens' AttachedPolicy (Prelude.Maybe Prelude.Text)
attachedPolicy_policyName :: Lens' AttachedPolicy (Maybe Text)
attachedPolicy_policyName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttachedPolicy' {Maybe Text
policyName :: Maybe Text
$sel:policyName:AttachedPolicy' :: AttachedPolicy -> Maybe Text
policyName} -> Maybe Text
policyName) (\s :: AttachedPolicy
s@AttachedPolicy' {} Maybe Text
a -> AttachedPolicy
s {$sel:policyName:AttachedPolicy' :: Maybe Text
policyName = Maybe Text
a} :: AttachedPolicy)

instance Data.FromXML AttachedPolicy where
  parseXML :: [Node] -> Either String AttachedPolicy
parseXML [Node]
x =
    Maybe Text -> Maybe Text -> AttachedPolicy
AttachedPolicy'
      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
"PolicyArn")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"PolicyName")

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

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