{-# 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.PolicyVersion
-- 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.PolicyVersion where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Contains information about a version of a managed policy.
--
-- This data type is used as a response element in the CreatePolicyVersion,
-- GetPolicyVersion, ListPolicyVersions, 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:/ 'newPolicyVersion' smart constructor.
data PolicyVersion = PolicyVersion'
  { -- | The identifier for the policy version.
    --
    -- Policy version identifiers always begin with @v@ (always lowercase).
    -- When a policy is created, the first policy version is @v1@.
    PolicyVersion -> Maybe Text
versionId :: Prelude.Maybe Prelude.Text,
    -- | The date and time, in
    -- <http://www.iso.org/iso/iso8601 ISO 8601 date-time format>, when the
    -- policy version was created.
    PolicyVersion -> Maybe ISO8601
createDate :: Prelude.Maybe Core.ISO8601,
    -- | The policy document.
    --
    -- The policy document is returned in the response to the GetPolicyVersion
    -- and GetAccountAuthorizationDetails operations. It is not returned in the
    -- response to the CreatePolicyVersion or ListPolicyVersions operations.
    --
    -- The policy document returned in this structure is URL-encoded compliant
    -- with <https://tools.ietf.org/html/rfc3986 RFC 3986>. You can use a URL
    -- decoding method to convert the policy back to plain JSON text. For
    -- example, if you use Java, you can use the @decode@ method of the
    -- @java.net.URLDecoder@ utility class in the Java SDK. Other languages and
    -- SDKs provide similar functionality.
    PolicyVersion -> Maybe Text
document :: Prelude.Maybe Prelude.Text,
    -- | Specifies whether the policy version is set as the policy\'s default
    -- version.
    PolicyVersion -> Maybe Bool
isDefaultVersion :: Prelude.Maybe Prelude.Bool
  }
  deriving (PolicyVersion -> PolicyVersion -> Bool
(PolicyVersion -> PolicyVersion -> Bool)
-> (PolicyVersion -> PolicyVersion -> Bool) -> Eq PolicyVersion
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PolicyVersion -> PolicyVersion -> Bool
$c/= :: PolicyVersion -> PolicyVersion -> Bool
== :: PolicyVersion -> PolicyVersion -> Bool
$c== :: PolicyVersion -> PolicyVersion -> Bool
Prelude.Eq, ReadPrec [PolicyVersion]
ReadPrec PolicyVersion
Int -> ReadS PolicyVersion
ReadS [PolicyVersion]
(Int -> ReadS PolicyVersion)
-> ReadS [PolicyVersion]
-> ReadPrec PolicyVersion
-> ReadPrec [PolicyVersion]
-> Read PolicyVersion
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PolicyVersion]
$creadListPrec :: ReadPrec [PolicyVersion]
readPrec :: ReadPrec PolicyVersion
$creadPrec :: ReadPrec PolicyVersion
readList :: ReadS [PolicyVersion]
$creadList :: ReadS [PolicyVersion]
readsPrec :: Int -> ReadS PolicyVersion
$creadsPrec :: Int -> ReadS PolicyVersion
Prelude.Read, Int -> PolicyVersion -> ShowS
[PolicyVersion] -> ShowS
PolicyVersion -> String
(Int -> PolicyVersion -> ShowS)
-> (PolicyVersion -> String)
-> ([PolicyVersion] -> ShowS)
-> Show PolicyVersion
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PolicyVersion] -> ShowS
$cshowList :: [PolicyVersion] -> ShowS
show :: PolicyVersion -> String
$cshow :: PolicyVersion -> String
showsPrec :: Int -> PolicyVersion -> ShowS
$cshowsPrec :: Int -> PolicyVersion -> ShowS
Prelude.Show, (forall x. PolicyVersion -> Rep PolicyVersion x)
-> (forall x. Rep PolicyVersion x -> PolicyVersion)
-> Generic PolicyVersion
forall x. Rep PolicyVersion x -> PolicyVersion
forall x. PolicyVersion -> Rep PolicyVersion x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PolicyVersion x -> PolicyVersion
$cfrom :: forall x. PolicyVersion -> Rep PolicyVersion x
Prelude.Generic)

-- |
-- Create a value of 'PolicyVersion' 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:
--
-- 'versionId', 'policyVersion_versionId' - The identifier for the policy version.
--
-- Policy version identifiers always begin with @v@ (always lowercase).
-- When a policy is created, the first policy version is @v1@.
--
-- 'createDate', 'policyVersion_createDate' - The date and time, in
-- <http://www.iso.org/iso/iso8601 ISO 8601 date-time format>, when the
-- policy version was created.
--
-- 'document', 'policyVersion_document' - The policy document.
--
-- The policy document is returned in the response to the GetPolicyVersion
-- and GetAccountAuthorizationDetails operations. It is not returned in the
-- response to the CreatePolicyVersion or ListPolicyVersions operations.
--
-- The policy document returned in this structure is URL-encoded compliant
-- with <https://tools.ietf.org/html/rfc3986 RFC 3986>. You can use a URL
-- decoding method to convert the policy back to plain JSON text. For
-- example, if you use Java, you can use the @decode@ method of the
-- @java.net.URLDecoder@ utility class in the Java SDK. Other languages and
-- SDKs provide similar functionality.
--
-- 'isDefaultVersion', 'policyVersion_isDefaultVersion' - Specifies whether the policy version is set as the policy\'s default
-- version.
newPolicyVersion ::
  PolicyVersion
newPolicyVersion :: PolicyVersion
newPolicyVersion =
  PolicyVersion' :: Maybe Text
-> Maybe ISO8601 -> Maybe Text -> Maybe Bool -> PolicyVersion
PolicyVersion'
    { $sel:versionId:PolicyVersion' :: Maybe Text
versionId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:createDate:PolicyVersion' :: Maybe ISO8601
createDate = Maybe ISO8601
forall a. Maybe a
Prelude.Nothing,
      $sel:document:PolicyVersion' :: Maybe Text
document = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:isDefaultVersion:PolicyVersion' :: Maybe Bool
isDefaultVersion = Maybe Bool
forall a. Maybe a
Prelude.Nothing
    }

-- | The identifier for the policy version.
--
-- Policy version identifiers always begin with @v@ (always lowercase).
-- When a policy is created, the first policy version is @v1@.
policyVersion_versionId :: Lens.Lens' PolicyVersion (Prelude.Maybe Prelude.Text)
policyVersion_versionId :: (Maybe Text -> f (Maybe Text)) -> PolicyVersion -> f PolicyVersion
policyVersion_versionId = (PolicyVersion -> Maybe Text)
-> (PolicyVersion -> Maybe Text -> PolicyVersion)
-> Lens PolicyVersion PolicyVersion (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PolicyVersion' {Maybe Text
versionId :: Maybe Text
$sel:versionId:PolicyVersion' :: PolicyVersion -> Maybe Text
versionId} -> Maybe Text
versionId) (\s :: PolicyVersion
s@PolicyVersion' {} Maybe Text
a -> PolicyVersion
s {$sel:versionId:PolicyVersion' :: Maybe Text
versionId = Maybe Text
a} :: PolicyVersion)

-- | The date and time, in
-- <http://www.iso.org/iso/iso8601 ISO 8601 date-time format>, when the
-- policy version was created.
policyVersion_createDate :: Lens.Lens' PolicyVersion (Prelude.Maybe Prelude.UTCTime)
policyVersion_createDate :: (Maybe UTCTime -> f (Maybe UTCTime))
-> PolicyVersion -> f PolicyVersion
policyVersion_createDate = (PolicyVersion -> Maybe ISO8601)
-> (PolicyVersion -> Maybe ISO8601 -> PolicyVersion)
-> Lens PolicyVersion PolicyVersion (Maybe ISO8601) (Maybe ISO8601)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PolicyVersion' {Maybe ISO8601
createDate :: Maybe ISO8601
$sel:createDate:PolicyVersion' :: PolicyVersion -> Maybe ISO8601
createDate} -> Maybe ISO8601
createDate) (\s :: PolicyVersion
s@PolicyVersion' {} Maybe ISO8601
a -> PolicyVersion
s {$sel:createDate:PolicyVersion' :: Maybe ISO8601
createDate = Maybe ISO8601
a} :: PolicyVersion) ((Maybe ISO8601 -> f (Maybe ISO8601))
 -> PolicyVersion -> f PolicyVersion)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe ISO8601 -> f (Maybe ISO8601))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> PolicyVersion
-> f PolicyVersion
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso ISO8601 ISO8601 UTCTime UTCTime
-> Iso
     (Maybe ISO8601) (Maybe ISO8601) (Maybe UTCTime) (Maybe UTCTime)
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 ISO8601 ISO8601 UTCTime UTCTime
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

-- | The policy document.
--
-- The policy document is returned in the response to the GetPolicyVersion
-- and GetAccountAuthorizationDetails operations. It is not returned in the
-- response to the CreatePolicyVersion or ListPolicyVersions operations.
--
-- The policy document returned in this structure is URL-encoded compliant
-- with <https://tools.ietf.org/html/rfc3986 RFC 3986>. You can use a URL
-- decoding method to convert the policy back to plain JSON text. For
-- example, if you use Java, you can use the @decode@ method of the
-- @java.net.URLDecoder@ utility class in the Java SDK. Other languages and
-- SDKs provide similar functionality.
policyVersion_document :: Lens.Lens' PolicyVersion (Prelude.Maybe Prelude.Text)
policyVersion_document :: (Maybe Text -> f (Maybe Text)) -> PolicyVersion -> f PolicyVersion
policyVersion_document = (PolicyVersion -> Maybe Text)
-> (PolicyVersion -> Maybe Text -> PolicyVersion)
-> Lens PolicyVersion PolicyVersion (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PolicyVersion' {Maybe Text
document :: Maybe Text
$sel:document:PolicyVersion' :: PolicyVersion -> Maybe Text
document} -> Maybe Text
document) (\s :: PolicyVersion
s@PolicyVersion' {} Maybe Text
a -> PolicyVersion
s {$sel:document:PolicyVersion' :: Maybe Text
document = Maybe Text
a} :: PolicyVersion)

-- | Specifies whether the policy version is set as the policy\'s default
-- version.
policyVersion_isDefaultVersion :: Lens.Lens' PolicyVersion (Prelude.Maybe Prelude.Bool)
policyVersion_isDefaultVersion :: (Maybe Bool -> f (Maybe Bool)) -> PolicyVersion -> f PolicyVersion
policyVersion_isDefaultVersion = (PolicyVersion -> Maybe Bool)
-> (PolicyVersion -> Maybe Bool -> PolicyVersion)
-> Lens PolicyVersion PolicyVersion (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PolicyVersion' {Maybe Bool
isDefaultVersion :: Maybe Bool
$sel:isDefaultVersion:PolicyVersion' :: PolicyVersion -> Maybe Bool
isDefaultVersion} -> Maybe Bool
isDefaultVersion) (\s :: PolicyVersion
s@PolicyVersion' {} Maybe Bool
a -> PolicyVersion
s {$sel:isDefaultVersion:PolicyVersion' :: Maybe Bool
isDefaultVersion = Maybe Bool
a} :: PolicyVersion)

instance Core.FromXML PolicyVersion where
  parseXML :: [Node] -> Either String PolicyVersion
parseXML [Node]
x =
    Maybe Text
-> Maybe ISO8601 -> Maybe Text -> Maybe Bool -> PolicyVersion
PolicyVersion'
      (Maybe Text
 -> Maybe ISO8601 -> Maybe Text -> Maybe Bool -> PolicyVersion)
-> Either String (Maybe Text)
-> Either
     String (Maybe ISO8601 -> Maybe Text -> Maybe Bool -> PolicyVersion)
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
"VersionId")
      Either
  String (Maybe ISO8601 -> Maybe Text -> Maybe Bool -> PolicyVersion)
-> Either String (Maybe ISO8601)
-> Either String (Maybe Text -> Maybe Bool -> PolicyVersion)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe ISO8601)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"CreateDate")
      Either String (Maybe Text -> Maybe Bool -> PolicyVersion)
-> Either String (Maybe Text)
-> Either String (Maybe Bool -> PolicyVersion)
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
"Document")
      Either String (Maybe Bool -> PolicyVersion)
-> Either String (Maybe Bool) -> Either String PolicyVersion
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Bool)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"IsDefaultVersion")

instance Prelude.Hashable PolicyVersion

instance Prelude.NFData PolicyVersion