{-# 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.XRay.Types.ResourcePolicy
-- 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.XRay.Types.ResourcePolicy 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

-- | A resource policy grants one or more Amazon Web Services services and
-- accounts permissions to access X-Ray. Each resource policy is associated
-- with a specific Amazon Web Services account.
--
-- /See:/ 'newResourcePolicy' smart constructor.
data ResourcePolicy = ResourcePolicy'
  { -- | When the policy was last updated, in Unix time seconds.
    ResourcePolicy -> Maybe POSIX
lastUpdatedTime :: Prelude.Maybe Data.POSIX,
    -- | The resource policy document, which can be up to 5kb in size.
    ResourcePolicy -> Maybe Text
policyDocument :: Prelude.Maybe Prelude.Text,
    -- | The name of the resource policy. Must be unique within a specific Amazon
    -- Web Services account.
    ResourcePolicy -> Maybe Text
policyName :: Prelude.Maybe Prelude.Text,
    -- | Returns the current policy revision id for this policy name.
    ResourcePolicy -> Maybe Text
policyRevisionId :: Prelude.Maybe Prelude.Text
  }
  deriving (ResourcePolicy -> ResourcePolicy -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ResourcePolicy -> ResourcePolicy -> Bool
$c/= :: ResourcePolicy -> ResourcePolicy -> Bool
== :: ResourcePolicy -> ResourcePolicy -> Bool
$c== :: ResourcePolicy -> ResourcePolicy -> Bool
Prelude.Eq, ReadPrec [ResourcePolicy]
ReadPrec ResourcePolicy
Int -> ReadS ResourcePolicy
ReadS [ResourcePolicy]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ResourcePolicy]
$creadListPrec :: ReadPrec [ResourcePolicy]
readPrec :: ReadPrec ResourcePolicy
$creadPrec :: ReadPrec ResourcePolicy
readList :: ReadS [ResourcePolicy]
$creadList :: ReadS [ResourcePolicy]
readsPrec :: Int -> ReadS ResourcePolicy
$creadsPrec :: Int -> ReadS ResourcePolicy
Prelude.Read, Int -> ResourcePolicy -> ShowS
[ResourcePolicy] -> ShowS
ResourcePolicy -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ResourcePolicy] -> ShowS
$cshowList :: [ResourcePolicy] -> ShowS
show :: ResourcePolicy -> String
$cshow :: ResourcePolicy -> String
showsPrec :: Int -> ResourcePolicy -> ShowS
$cshowsPrec :: Int -> ResourcePolicy -> ShowS
Prelude.Show, forall x. Rep ResourcePolicy x -> ResourcePolicy
forall x. ResourcePolicy -> Rep ResourcePolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ResourcePolicy x -> ResourcePolicy
$cfrom :: forall x. ResourcePolicy -> Rep ResourcePolicy x
Prelude.Generic)

-- |
-- Create a value of 'ResourcePolicy' 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:
--
-- 'lastUpdatedTime', 'resourcePolicy_lastUpdatedTime' - When the policy was last updated, in Unix time seconds.
--
-- 'policyDocument', 'resourcePolicy_policyDocument' - The resource policy document, which can be up to 5kb in size.
--
-- 'policyName', 'resourcePolicy_policyName' - The name of the resource policy. Must be unique within a specific Amazon
-- Web Services account.
--
-- 'policyRevisionId', 'resourcePolicy_policyRevisionId' - Returns the current policy revision id for this policy name.
newResourcePolicy ::
  ResourcePolicy
newResourcePolicy :: ResourcePolicy
newResourcePolicy =
  ResourcePolicy'
    { $sel:lastUpdatedTime:ResourcePolicy' :: Maybe POSIX
lastUpdatedTime = forall a. Maybe a
Prelude.Nothing,
      $sel:policyDocument:ResourcePolicy' :: Maybe Text
policyDocument = forall a. Maybe a
Prelude.Nothing,
      $sel:policyName:ResourcePolicy' :: Maybe Text
policyName = forall a. Maybe a
Prelude.Nothing,
      $sel:policyRevisionId:ResourcePolicy' :: Maybe Text
policyRevisionId = forall a. Maybe a
Prelude.Nothing
    }

-- | When the policy was last updated, in Unix time seconds.
resourcePolicy_lastUpdatedTime :: Lens.Lens' ResourcePolicy (Prelude.Maybe Prelude.UTCTime)
resourcePolicy_lastUpdatedTime :: Lens' ResourcePolicy (Maybe UTCTime)
resourcePolicy_lastUpdatedTime = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResourcePolicy' {Maybe POSIX
lastUpdatedTime :: Maybe POSIX
$sel:lastUpdatedTime:ResourcePolicy' :: ResourcePolicy -> Maybe POSIX
lastUpdatedTime} -> Maybe POSIX
lastUpdatedTime) (\s :: ResourcePolicy
s@ResourcePolicy' {} Maybe POSIX
a -> ResourcePolicy
s {$sel:lastUpdatedTime:ResourcePolicy' :: Maybe POSIX
lastUpdatedTime = Maybe POSIX
a} :: ResourcePolicy) 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 (a :: Format). Iso' (Time a) UTCTime
Data._Time

-- | The resource policy document, which can be up to 5kb in size.
resourcePolicy_policyDocument :: Lens.Lens' ResourcePolicy (Prelude.Maybe Prelude.Text)
resourcePolicy_policyDocument :: Lens' ResourcePolicy (Maybe Text)
resourcePolicy_policyDocument = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResourcePolicy' {Maybe Text
policyDocument :: Maybe Text
$sel:policyDocument:ResourcePolicy' :: ResourcePolicy -> Maybe Text
policyDocument} -> Maybe Text
policyDocument) (\s :: ResourcePolicy
s@ResourcePolicy' {} Maybe Text
a -> ResourcePolicy
s {$sel:policyDocument:ResourcePolicy' :: Maybe Text
policyDocument = Maybe Text
a} :: ResourcePolicy)

-- | The name of the resource policy. Must be unique within a specific Amazon
-- Web Services account.
resourcePolicy_policyName :: Lens.Lens' ResourcePolicy (Prelude.Maybe Prelude.Text)
resourcePolicy_policyName :: Lens' ResourcePolicy (Maybe Text)
resourcePolicy_policyName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResourcePolicy' {Maybe Text
policyName :: Maybe Text
$sel:policyName:ResourcePolicy' :: ResourcePolicy -> Maybe Text
policyName} -> Maybe Text
policyName) (\s :: ResourcePolicy
s@ResourcePolicy' {} Maybe Text
a -> ResourcePolicy
s {$sel:policyName:ResourcePolicy' :: Maybe Text
policyName = Maybe Text
a} :: ResourcePolicy)

-- | Returns the current policy revision id for this policy name.
resourcePolicy_policyRevisionId :: Lens.Lens' ResourcePolicy (Prelude.Maybe Prelude.Text)
resourcePolicy_policyRevisionId :: Lens' ResourcePolicy (Maybe Text)
resourcePolicy_policyRevisionId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResourcePolicy' {Maybe Text
policyRevisionId :: Maybe Text
$sel:policyRevisionId:ResourcePolicy' :: ResourcePolicy -> Maybe Text
policyRevisionId} -> Maybe Text
policyRevisionId) (\s :: ResourcePolicy
s@ResourcePolicy' {} Maybe Text
a -> ResourcePolicy
s {$sel:policyRevisionId:ResourcePolicy' :: Maybe Text
policyRevisionId = Maybe Text
a} :: ResourcePolicy)

instance Data.FromJSON ResourcePolicy where
  parseJSON :: Value -> Parser ResourcePolicy
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ResourcePolicy"
      ( \Object
x ->
          Maybe POSIX
-> Maybe Text -> Maybe Text -> Maybe Text -> ResourcePolicy
ResourcePolicy'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"LastUpdatedTime")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"PolicyDocument")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"PolicyName")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"PolicyRevisionId")
      )

instance Prelude.Hashable ResourcePolicy where
  hashWithSalt :: Int -> ResourcePolicy -> Int
hashWithSalt Int
_salt ResourcePolicy' {Maybe Text
Maybe POSIX
policyRevisionId :: Maybe Text
policyName :: Maybe Text
policyDocument :: Maybe Text
lastUpdatedTime :: Maybe POSIX
$sel:policyRevisionId:ResourcePolicy' :: ResourcePolicy -> Maybe Text
$sel:policyName:ResourcePolicy' :: ResourcePolicy -> Maybe Text
$sel:policyDocument:ResourcePolicy' :: ResourcePolicy -> Maybe Text
$sel:lastUpdatedTime:ResourcePolicy' :: ResourcePolicy -> Maybe POSIX
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe POSIX
lastUpdatedTime
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
policyDocument
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
policyName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
policyRevisionId

instance Prelude.NFData ResourcePolicy where
  rnf :: ResourcePolicy -> ()
rnf ResourcePolicy' {Maybe Text
Maybe POSIX
policyRevisionId :: Maybe Text
policyName :: Maybe Text
policyDocument :: Maybe Text
lastUpdatedTime :: Maybe POSIX
$sel:policyRevisionId:ResourcePolicy' :: ResourcePolicy -> Maybe Text
$sel:policyName:ResourcePolicy' :: ResourcePolicy -> Maybe Text
$sel:policyDocument:ResourcePolicy' :: ResourcePolicy -> Maybe Text
$sel:lastUpdatedTime:ResourcePolicy' :: ResourcePolicy -> Maybe POSIX
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe POSIX
lastUpdatedTime
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
policyDocument
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
policyName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
policyRevisionId