{-# 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.CertificateManagerPCA.Types.Permission
-- 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.CertificateManagerPCA.Types.Permission where

import Amazonka.CertificateManagerPCA.Types.ActionType
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Permissions designate which private CA actions can be performed by an
-- AWS service or entity. In order for ACM to automatically renew private
-- certificates, you must give the ACM service principal all available
-- permissions (@IssueCertificate@, @GetCertificate@, and
-- @ListPermissions@). Permissions can be assigned with the
-- <https://docs.aws.amazon.com/acm-pca/latest/APIReference/API_CreatePermission.html CreatePermission>
-- action, removed with the
-- <https://docs.aws.amazon.com/acm-pca/latest/APIReference/API_DeletePermission.html DeletePermission>
-- action, and listed with the
-- <https://docs.aws.amazon.com/acm-pca/latest/APIReference/API_ListPermissions.html ListPermissions>
-- action.
--
-- /See:/ 'newPermission' smart constructor.
data Permission = Permission'
  { -- | The ID of the account that assigned the permission.
    Permission -> Maybe Text
sourceAccount :: Prelude.Maybe Prelude.Text,
    -- | The private CA actions that can be performed by the designated AWS
    -- service.
    Permission -> Maybe (NonEmpty ActionType)
actions :: Prelude.Maybe (Prelude.NonEmpty ActionType),
    -- | The time at which the permission was created.
    Permission -> Maybe POSIX
createdAt :: Prelude.Maybe Core.POSIX,
    -- | The AWS service or entity that holds the permission. At this time, the
    -- only valid principal is @acm.amazonaws.com@.
    Permission -> Maybe Text
principal :: Prelude.Maybe Prelude.Text,
    -- | The name of the policy that is associated with the permission.
    Permission -> Maybe Text
policy :: Prelude.Maybe Prelude.Text,
    -- | The Amazon Resource Number (ARN) of the private CA from which the
    -- permission was issued.
    Permission -> Maybe Text
certificateAuthorityArn :: Prelude.Maybe Prelude.Text
  }
  deriving (Permission -> Permission -> Bool
(Permission -> Permission -> Bool)
-> (Permission -> Permission -> Bool) -> Eq Permission
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Permission -> Permission -> Bool
$c/= :: Permission -> Permission -> Bool
== :: Permission -> Permission -> Bool
$c== :: Permission -> Permission -> Bool
Prelude.Eq, ReadPrec [Permission]
ReadPrec Permission
Int -> ReadS Permission
ReadS [Permission]
(Int -> ReadS Permission)
-> ReadS [Permission]
-> ReadPrec Permission
-> ReadPrec [Permission]
-> Read Permission
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Permission]
$creadListPrec :: ReadPrec [Permission]
readPrec :: ReadPrec Permission
$creadPrec :: ReadPrec Permission
readList :: ReadS [Permission]
$creadList :: ReadS [Permission]
readsPrec :: Int -> ReadS Permission
$creadsPrec :: Int -> ReadS Permission
Prelude.Read, Int -> Permission -> ShowS
[Permission] -> ShowS
Permission -> String
(Int -> Permission -> ShowS)
-> (Permission -> String)
-> ([Permission] -> ShowS)
-> Show Permission
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Permission] -> ShowS
$cshowList :: [Permission] -> ShowS
show :: Permission -> String
$cshow :: Permission -> String
showsPrec :: Int -> Permission -> ShowS
$cshowsPrec :: Int -> Permission -> ShowS
Prelude.Show, (forall x. Permission -> Rep Permission x)
-> (forall x. Rep Permission x -> Permission) -> Generic Permission
forall x. Rep Permission x -> Permission
forall x. Permission -> Rep Permission x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Permission x -> Permission
$cfrom :: forall x. Permission -> Rep Permission x
Prelude.Generic)

-- |
-- Create a value of 'Permission' 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:
--
-- 'sourceAccount', 'permission_sourceAccount' - The ID of the account that assigned the permission.
--
-- 'actions', 'permission_actions' - The private CA actions that can be performed by the designated AWS
-- service.
--
-- 'createdAt', 'permission_createdAt' - The time at which the permission was created.
--
-- 'principal', 'permission_principal' - The AWS service or entity that holds the permission. At this time, the
-- only valid principal is @acm.amazonaws.com@.
--
-- 'policy', 'permission_policy' - The name of the policy that is associated with the permission.
--
-- 'certificateAuthorityArn', 'permission_certificateAuthorityArn' - The Amazon Resource Number (ARN) of the private CA from which the
-- permission was issued.
newPermission ::
  Permission
newPermission :: Permission
newPermission =
  Permission' :: Maybe Text
-> Maybe (NonEmpty ActionType)
-> Maybe POSIX
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Permission
Permission'
    { $sel:sourceAccount:Permission' :: Maybe Text
sourceAccount = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:actions:Permission' :: Maybe (NonEmpty ActionType)
actions = Maybe (NonEmpty ActionType)
forall a. Maybe a
Prelude.Nothing,
      $sel:createdAt:Permission' :: Maybe POSIX
createdAt = Maybe POSIX
forall a. Maybe a
Prelude.Nothing,
      $sel:principal:Permission' :: Maybe Text
principal = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:policy:Permission' :: Maybe Text
policy = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:certificateAuthorityArn:Permission' :: Maybe Text
certificateAuthorityArn = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The ID of the account that assigned the permission.
permission_sourceAccount :: Lens.Lens' Permission (Prelude.Maybe Prelude.Text)
permission_sourceAccount :: (Maybe Text -> f (Maybe Text)) -> Permission -> f Permission
permission_sourceAccount = (Permission -> Maybe Text)
-> (Permission -> Maybe Text -> Permission)
-> Lens Permission Permission (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Permission' {Maybe Text
sourceAccount :: Maybe Text
$sel:sourceAccount:Permission' :: Permission -> Maybe Text
sourceAccount} -> Maybe Text
sourceAccount) (\s :: Permission
s@Permission' {} Maybe Text
a -> Permission
s {$sel:sourceAccount:Permission' :: Maybe Text
sourceAccount = Maybe Text
a} :: Permission)

-- | The private CA actions that can be performed by the designated AWS
-- service.
permission_actions :: Lens.Lens' Permission (Prelude.Maybe (Prelude.NonEmpty ActionType))
permission_actions :: (Maybe (NonEmpty ActionType) -> f (Maybe (NonEmpty ActionType)))
-> Permission -> f Permission
permission_actions = (Permission -> Maybe (NonEmpty ActionType))
-> (Permission -> Maybe (NonEmpty ActionType) -> Permission)
-> Lens
     Permission
     Permission
     (Maybe (NonEmpty ActionType))
     (Maybe (NonEmpty ActionType))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Permission' {Maybe (NonEmpty ActionType)
actions :: Maybe (NonEmpty ActionType)
$sel:actions:Permission' :: Permission -> Maybe (NonEmpty ActionType)
actions} -> Maybe (NonEmpty ActionType)
actions) (\s :: Permission
s@Permission' {} Maybe (NonEmpty ActionType)
a -> Permission
s {$sel:actions:Permission' :: Maybe (NonEmpty ActionType)
actions = Maybe (NonEmpty ActionType)
a} :: Permission) ((Maybe (NonEmpty ActionType) -> f (Maybe (NonEmpty ActionType)))
 -> Permission -> f Permission)
-> ((Maybe (NonEmpty ActionType)
     -> f (Maybe (NonEmpty ActionType)))
    -> Maybe (NonEmpty ActionType) -> f (Maybe (NonEmpty ActionType)))
-> (Maybe (NonEmpty ActionType) -> f (Maybe (NonEmpty ActionType)))
-> Permission
-> f Permission
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (NonEmpty ActionType)
  (NonEmpty ActionType)
  (NonEmpty ActionType)
  (NonEmpty ActionType)
-> Iso
     (Maybe (NonEmpty ActionType))
     (Maybe (NonEmpty ActionType))
     (Maybe (NonEmpty ActionType))
     (Maybe (NonEmpty ActionType))
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
  (NonEmpty ActionType)
  (NonEmpty ActionType)
  (NonEmpty ActionType)
  (NonEmpty ActionType)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The time at which the permission was created.
permission_createdAt :: Lens.Lens' Permission (Prelude.Maybe Prelude.UTCTime)
permission_createdAt :: (Maybe UTCTime -> f (Maybe UTCTime)) -> Permission -> f Permission
permission_createdAt = (Permission -> Maybe POSIX)
-> (Permission -> Maybe POSIX -> Permission)
-> Lens Permission Permission (Maybe POSIX) (Maybe POSIX)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Permission' {Maybe POSIX
createdAt :: Maybe POSIX
$sel:createdAt:Permission' :: Permission -> Maybe POSIX
createdAt} -> Maybe POSIX
createdAt) (\s :: Permission
s@Permission' {} Maybe POSIX
a -> Permission
s {$sel:createdAt:Permission' :: Maybe POSIX
createdAt = Maybe POSIX
a} :: Permission) ((Maybe POSIX -> f (Maybe POSIX)) -> Permission -> f Permission)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe POSIX -> f (Maybe POSIX))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> Permission
-> f Permission
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso POSIX POSIX UTCTime UTCTime
-> Iso (Maybe POSIX) (Maybe POSIX) (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 POSIX POSIX UTCTime UTCTime
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

-- | The AWS service or entity that holds the permission. At this time, the
-- only valid principal is @acm.amazonaws.com@.
permission_principal :: Lens.Lens' Permission (Prelude.Maybe Prelude.Text)
permission_principal :: (Maybe Text -> f (Maybe Text)) -> Permission -> f Permission
permission_principal = (Permission -> Maybe Text)
-> (Permission -> Maybe Text -> Permission)
-> Lens Permission Permission (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Permission' {Maybe Text
principal :: Maybe Text
$sel:principal:Permission' :: Permission -> Maybe Text
principal} -> Maybe Text
principal) (\s :: Permission
s@Permission' {} Maybe Text
a -> Permission
s {$sel:principal:Permission' :: Maybe Text
principal = Maybe Text
a} :: Permission)

-- | The name of the policy that is associated with the permission.
permission_policy :: Lens.Lens' Permission (Prelude.Maybe Prelude.Text)
permission_policy :: (Maybe Text -> f (Maybe Text)) -> Permission -> f Permission
permission_policy = (Permission -> Maybe Text)
-> (Permission -> Maybe Text -> Permission)
-> Lens Permission Permission (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Permission' {Maybe Text
policy :: Maybe Text
$sel:policy:Permission' :: Permission -> Maybe Text
policy} -> Maybe Text
policy) (\s :: Permission
s@Permission' {} Maybe Text
a -> Permission
s {$sel:policy:Permission' :: Maybe Text
policy = Maybe Text
a} :: Permission)

-- | The Amazon Resource Number (ARN) of the private CA from which the
-- permission was issued.
permission_certificateAuthorityArn :: Lens.Lens' Permission (Prelude.Maybe Prelude.Text)
permission_certificateAuthorityArn :: (Maybe Text -> f (Maybe Text)) -> Permission -> f Permission
permission_certificateAuthorityArn = (Permission -> Maybe Text)
-> (Permission -> Maybe Text -> Permission)
-> Lens Permission Permission (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Permission' {Maybe Text
certificateAuthorityArn :: Maybe Text
$sel:certificateAuthorityArn:Permission' :: Permission -> Maybe Text
certificateAuthorityArn} -> Maybe Text
certificateAuthorityArn) (\s :: Permission
s@Permission' {} Maybe Text
a -> Permission
s {$sel:certificateAuthorityArn:Permission' :: Maybe Text
certificateAuthorityArn = Maybe Text
a} :: Permission)

instance Core.FromJSON Permission where
  parseJSON :: Value -> Parser Permission
parseJSON =
    String
-> (Object -> Parser Permission) -> Value -> Parser Permission
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Permission"
      ( \Object
x ->
          Maybe Text
-> Maybe (NonEmpty ActionType)
-> Maybe POSIX
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Permission
Permission'
            (Maybe Text
 -> Maybe (NonEmpty ActionType)
 -> Maybe POSIX
 -> Maybe Text
 -> Maybe Text
 -> Maybe Text
 -> Permission)
-> Parser (Maybe Text)
-> Parser
     (Maybe (NonEmpty ActionType)
      -> Maybe POSIX
      -> Maybe Text
      -> Maybe Text
      -> Maybe Text
      -> Permission)
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
"SourceAccount")
            Parser
  (Maybe (NonEmpty ActionType)
   -> Maybe POSIX
   -> Maybe Text
   -> Maybe Text
   -> Maybe Text
   -> Permission)
-> Parser (Maybe (NonEmpty ActionType))
-> Parser
     (Maybe POSIX
      -> Maybe Text -> Maybe Text -> Maybe Text -> Permission)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (NonEmpty ActionType))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Actions")
            Parser
  (Maybe POSIX
   -> Maybe Text -> Maybe Text -> Maybe Text -> Permission)
-> Parser (Maybe POSIX)
-> Parser (Maybe Text -> Maybe Text -> Maybe Text -> Permission)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe POSIX)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"CreatedAt")
            Parser (Maybe Text -> Maybe Text -> Maybe Text -> Permission)
-> Parser (Maybe Text)
-> Parser (Maybe Text -> Maybe Text -> Permission)
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
"Principal")
            Parser (Maybe Text -> Maybe Text -> Permission)
-> Parser (Maybe Text) -> Parser (Maybe Text -> Permission)
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
"Policy")
            Parser (Maybe Text -> Permission)
-> Parser (Maybe Text) -> Parser Permission
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
"CertificateAuthorityArn")
      )

instance Prelude.Hashable Permission

instance Prelude.NFData Permission