{-# 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-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)
module Amazonka.IAM.Types.AttachedPolicy where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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'
  { -- | The friendly name of the attached policy.
    AttachedPolicy -> Maybe Text
policyName :: Prelude.Maybe Prelude.Text,
    AttachedPolicy -> Maybe Text
policyArn :: Prelude.Maybe Prelude.Text
  }
  deriving (AttachedPolicy -> AttachedPolicy -> Bool
(AttachedPolicy -> AttachedPolicy -> Bool)
-> (AttachedPolicy -> AttachedPolicy -> Bool) -> Eq AttachedPolicy
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]
(Int -> ReadS AttachedPolicy)
-> ReadS [AttachedPolicy]
-> ReadPrec AttachedPolicy
-> ReadPrec [AttachedPolicy]
-> Read 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
(Int -> AttachedPolicy -> ShowS)
-> (AttachedPolicy -> String)
-> ([AttachedPolicy] -> ShowS)
-> Show AttachedPolicy
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. AttachedPolicy -> Rep AttachedPolicy x)
-> (forall x. Rep AttachedPolicy x -> AttachedPolicy)
-> Generic AttachedPolicy
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:
--
-- 'policyName', 'attachedPolicy_policyName' - The friendly name of the attached policy.
--
-- 'policyArn', 'attachedPolicy_policyArn' - Undocumented member.
newAttachedPolicy ::
  AttachedPolicy
newAttachedPolicy :: AttachedPolicy
newAttachedPolicy =
  AttachedPolicy' :: Maybe Text -> Maybe Text -> AttachedPolicy
AttachedPolicy'
    { $sel:policyName:AttachedPolicy' :: Maybe Text
policyName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:policyArn:AttachedPolicy' :: Maybe Text
policyArn = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The friendly name of the attached policy.
attachedPolicy_policyName :: Lens.Lens' AttachedPolicy (Prelude.Maybe Prelude.Text)
attachedPolicy_policyName :: (Maybe Text -> f (Maybe Text))
-> AttachedPolicy -> f AttachedPolicy
attachedPolicy_policyName = (AttachedPolicy -> Maybe Text)
-> (AttachedPolicy -> Maybe Text -> AttachedPolicy)
-> Lens AttachedPolicy AttachedPolicy (Maybe Text) (Maybe Text)
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)

-- | Undocumented member.
attachedPolicy_policyArn :: Lens.Lens' AttachedPolicy (Prelude.Maybe Prelude.Text)
attachedPolicy_policyArn :: (Maybe Text -> f (Maybe Text))
-> AttachedPolicy -> f AttachedPolicy
attachedPolicy_policyArn = (AttachedPolicy -> Maybe Text)
-> (AttachedPolicy -> Maybe Text -> AttachedPolicy)
-> Lens AttachedPolicy AttachedPolicy (Maybe Text) (Maybe Text)
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)

instance Core.FromXML AttachedPolicy where
  parseXML :: [Node] -> Either String AttachedPolicy
parseXML [Node]
x =
    Maybe Text -> Maybe Text -> AttachedPolicy
AttachedPolicy'
      (Maybe Text -> Maybe Text -> AttachedPolicy)
-> Either String (Maybe Text)
-> Either String (Maybe Text -> AttachedPolicy)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"PolicyName")
      Either String (Maybe Text -> AttachedPolicy)
-> Either String (Maybe Text) -> Either String AttachedPolicy
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"PolicyArn")

instance Prelude.Hashable AttachedPolicy

instance Prelude.NFData AttachedPolicy