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

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

-- | An AWS CodeArtifact resource policy that contains a resource ARN,
-- document details, and a revision.
--
-- /See:/ 'newResourcePolicy' smart constructor.
data ResourcePolicy = ResourcePolicy'
  { -- | The ARN of the resource associated with the resource policy
    ResourcePolicy -> Maybe Text
resourceArn :: Prelude.Maybe Prelude.Text,
    -- | The resource policy formatted in JSON.
    ResourcePolicy -> Maybe Text
document :: Prelude.Maybe Prelude.Text,
    -- | The current revision of the resource policy.
    ResourcePolicy -> Maybe Text
revision :: Prelude.Maybe Prelude.Text
  }
  deriving (ResourcePolicy -> ResourcePolicy -> Bool
(ResourcePolicy -> ResourcePolicy -> Bool)
-> (ResourcePolicy -> ResourcePolicy -> Bool) -> Eq ResourcePolicy
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]
(Int -> ReadS ResourcePolicy)
-> ReadS [ResourcePolicy]
-> ReadPrec ResourcePolicy
-> ReadPrec [ResourcePolicy]
-> Read 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
(Int -> ResourcePolicy -> ShowS)
-> (ResourcePolicy -> String)
-> ([ResourcePolicy] -> ShowS)
-> Show ResourcePolicy
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. ResourcePolicy -> Rep ResourcePolicy x)
-> (forall x. Rep ResourcePolicy x -> ResourcePolicy)
-> Generic ResourcePolicy
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:
--
-- 'resourceArn', 'resourcePolicy_resourceArn' - The ARN of the resource associated with the resource policy
--
-- 'document', 'resourcePolicy_document' - The resource policy formatted in JSON.
--
-- 'revision', 'resourcePolicy_revision' - The current revision of the resource policy.
newResourcePolicy ::
  ResourcePolicy
newResourcePolicy :: ResourcePolicy
newResourcePolicy =
  ResourcePolicy' :: Maybe Text -> Maybe Text -> Maybe Text -> ResourcePolicy
ResourcePolicy'
    { $sel:resourceArn:ResourcePolicy' :: Maybe Text
resourceArn = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:document:ResourcePolicy' :: Maybe Text
document = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:revision:ResourcePolicy' :: Maybe Text
revision = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The ARN of the resource associated with the resource policy
resourcePolicy_resourceArn :: Lens.Lens' ResourcePolicy (Prelude.Maybe Prelude.Text)
resourcePolicy_resourceArn :: (Maybe Text -> f (Maybe Text))
-> ResourcePolicy -> f ResourcePolicy
resourcePolicy_resourceArn = (ResourcePolicy -> Maybe Text)
-> (ResourcePolicy -> Maybe Text -> ResourcePolicy)
-> Lens ResourcePolicy ResourcePolicy (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResourcePolicy' {Maybe Text
resourceArn :: Maybe Text
$sel:resourceArn:ResourcePolicy' :: ResourcePolicy -> Maybe Text
resourceArn} -> Maybe Text
resourceArn) (\s :: ResourcePolicy
s@ResourcePolicy' {} Maybe Text
a -> ResourcePolicy
s {$sel:resourceArn:ResourcePolicy' :: Maybe Text
resourceArn = Maybe Text
a} :: ResourcePolicy)

-- | The resource policy formatted in JSON.
resourcePolicy_document :: Lens.Lens' ResourcePolicy (Prelude.Maybe Prelude.Text)
resourcePolicy_document :: (Maybe Text -> f (Maybe Text))
-> ResourcePolicy -> f ResourcePolicy
resourcePolicy_document = (ResourcePolicy -> Maybe Text)
-> (ResourcePolicy -> Maybe Text -> ResourcePolicy)
-> Lens ResourcePolicy ResourcePolicy (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResourcePolicy' {Maybe Text
document :: Maybe Text
$sel:document:ResourcePolicy' :: ResourcePolicy -> Maybe Text
document} -> Maybe Text
document) (\s :: ResourcePolicy
s@ResourcePolicy' {} Maybe Text
a -> ResourcePolicy
s {$sel:document:ResourcePolicy' :: Maybe Text
document = Maybe Text
a} :: ResourcePolicy)

-- | The current revision of the resource policy.
resourcePolicy_revision :: Lens.Lens' ResourcePolicy (Prelude.Maybe Prelude.Text)
resourcePolicy_revision :: (Maybe Text -> f (Maybe Text))
-> ResourcePolicy -> f ResourcePolicy
resourcePolicy_revision = (ResourcePolicy -> Maybe Text)
-> (ResourcePolicy -> Maybe Text -> ResourcePolicy)
-> Lens ResourcePolicy ResourcePolicy (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResourcePolicy' {Maybe Text
revision :: Maybe Text
$sel:revision:ResourcePolicy' :: ResourcePolicy -> Maybe Text
revision} -> Maybe Text
revision) (\s :: ResourcePolicy
s@ResourcePolicy' {} Maybe Text
a -> ResourcePolicy
s {$sel:revision:ResourcePolicy' :: Maybe Text
revision = Maybe Text
a} :: ResourcePolicy)

instance Core.FromJSON ResourcePolicy where
  parseJSON :: Value -> Parser ResourcePolicy
parseJSON =
    String
-> (Object -> Parser ResourcePolicy)
-> Value
-> Parser ResourcePolicy
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ResourcePolicy"
      ( \Object
x ->
          Maybe Text -> Maybe Text -> Maybe Text -> ResourcePolicy
ResourcePolicy'
            (Maybe Text -> Maybe Text -> Maybe Text -> ResourcePolicy)
-> Parser (Maybe Text)
-> Parser (Maybe Text -> Maybe Text -> ResourcePolicy)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"resourceArn")
            Parser (Maybe Text -> Maybe Text -> ResourcePolicy)
-> Parser (Maybe Text) -> Parser (Maybe Text -> ResourcePolicy)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"document")
            Parser (Maybe Text -> ResourcePolicy)
-> Parser (Maybe Text) -> Parser ResourcePolicy
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"revision")
      )

instance Prelude.Hashable ResourcePolicy

instance Prelude.NFData ResourcePolicy