{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude

-- | Permissions designate which private CA actions can be performed by an
-- Amazon Web Services 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/privateca/latest/APIReference/API_CreatePermission.html CreatePermission>
-- action, removed with the
-- <https://docs.aws.amazon.com/privateca/latest/APIReference/API_DeletePermission.html DeletePermission>
-- action, and listed with the
-- <https://docs.aws.amazon.com/privateca/latest/APIReference/API_ListPermissions.html ListPermissions>
-- action.
--
-- /See:/ 'newPermission' smart constructor.
data Permission = Permission'
  { -- | The private CA actions that can be performed by the designated Amazon
    -- Web Services service.
    Permission -> Maybe (NonEmpty ActionType)
actions :: Prelude.Maybe (Prelude.NonEmpty ActionType),
    -- | The Amazon Resource Number (ARN) of the private CA from which the
    -- permission was issued.
    Permission -> Maybe Text
certificateAuthorityArn :: Prelude.Maybe Prelude.Text,
    -- | The time at which the permission was created.
    Permission -> Maybe POSIX
createdAt :: Prelude.Maybe Data.POSIX,
    -- | The name of the policy that is associated with the permission.
    Permission -> Maybe Text
policy :: Prelude.Maybe Prelude.Text,
    -- | The Amazon Web Services 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 ID of the account that assigned the permission.
    Permission -> Maybe Text
sourceAccount :: Prelude.Maybe Prelude.Text
  }
  deriving (Permission -> Permission -> Bool
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]
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
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. 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:
--
-- 'actions', 'permission_actions' - The private CA actions that can be performed by the designated Amazon
-- Web Services service.
--
-- 'certificateAuthorityArn', 'permission_certificateAuthorityArn' - The Amazon Resource Number (ARN) of the private CA from which the
-- permission was issued.
--
-- 'createdAt', 'permission_createdAt' - The time at which the permission was created.
--
-- 'policy', 'permission_policy' - The name of the policy that is associated with the permission.
--
-- 'principal', 'permission_principal' - The Amazon Web Services service or entity that holds the permission. At
-- this time, the only valid principal is @acm.amazonaws.com@.
--
-- 'sourceAccount', 'permission_sourceAccount' - The ID of the account that assigned the permission.
newPermission ::
  Permission
newPermission :: Permission
newPermission =
  Permission'
    { $sel:actions:Permission' :: Maybe (NonEmpty ActionType)
actions = forall a. Maybe a
Prelude.Nothing,
      $sel:certificateAuthorityArn:Permission' :: Maybe Text
certificateAuthorityArn = forall a. Maybe a
Prelude.Nothing,
      $sel:createdAt:Permission' :: Maybe POSIX
createdAt = forall a. Maybe a
Prelude.Nothing,
      $sel:policy:Permission' :: Maybe Text
policy = forall a. Maybe a
Prelude.Nothing,
      $sel:principal:Permission' :: Maybe Text
principal = forall a. Maybe a
Prelude.Nothing,
      $sel:sourceAccount:Permission' :: Maybe Text
sourceAccount = forall a. Maybe a
Prelude.Nothing
    }

-- | The private CA actions that can be performed by the designated Amazon
-- Web Services service.
permission_actions :: Lens.Lens' Permission (Prelude.Maybe (Prelude.NonEmpty ActionType))
permission_actions :: Lens' Permission (Maybe (NonEmpty ActionType))
permission_actions = 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) 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 s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | 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 :: Lens' Permission (Maybe Text)
permission_certificateAuthorityArn = 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)

-- | The time at which the permission was created.
permission_createdAt :: Lens.Lens' Permission (Prelude.Maybe Prelude.UTCTime)
permission_createdAt :: Lens' Permission (Maybe UTCTime)
permission_createdAt = 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) 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 name of the policy that is associated with the permission.
permission_policy :: Lens.Lens' Permission (Prelude.Maybe Prelude.Text)
permission_policy :: Lens' Permission (Maybe Text)
permission_policy = 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 Web Services 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 :: Lens' Permission (Maybe Text)
permission_principal = 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 ID of the account that assigned the permission.
permission_sourceAccount :: Lens.Lens' Permission (Prelude.Maybe Prelude.Text)
permission_sourceAccount :: Lens' Permission (Maybe Text)
permission_sourceAccount = 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)

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

instance Prelude.Hashable Permission where
  hashWithSalt :: Int -> Permission -> Int
hashWithSalt Int
_salt Permission' {Maybe (NonEmpty ActionType)
Maybe Text
Maybe POSIX
sourceAccount :: Maybe Text
principal :: Maybe Text
policy :: Maybe Text
createdAt :: Maybe POSIX
certificateAuthorityArn :: Maybe Text
actions :: Maybe (NonEmpty ActionType)
$sel:sourceAccount:Permission' :: Permission -> Maybe Text
$sel:principal:Permission' :: Permission -> Maybe Text
$sel:policy:Permission' :: Permission -> Maybe Text
$sel:createdAt:Permission' :: Permission -> Maybe POSIX
$sel:certificateAuthorityArn:Permission' :: Permission -> Maybe Text
$sel:actions:Permission' :: Permission -> Maybe (NonEmpty ActionType)
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (NonEmpty ActionType)
actions
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
certificateAuthorityArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe POSIX
createdAt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
policy
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
principal
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
sourceAccount

instance Prelude.NFData Permission where
  rnf :: Permission -> ()
rnf Permission' {Maybe (NonEmpty ActionType)
Maybe Text
Maybe POSIX
sourceAccount :: Maybe Text
principal :: Maybe Text
policy :: Maybe Text
createdAt :: Maybe POSIX
certificateAuthorityArn :: Maybe Text
actions :: Maybe (NonEmpty ActionType)
$sel:sourceAccount:Permission' :: Permission -> Maybe Text
$sel:principal:Permission' :: Permission -> Maybe Text
$sel:policy:Permission' :: Permission -> Maybe Text
$sel:createdAt:Permission' :: Permission -> Maybe POSIX
$sel:certificateAuthorityArn:Permission' :: Permission -> Maybe Text
$sel:actions:Permission' :: Permission -> Maybe (NonEmpty ActionType)
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (NonEmpty ActionType)
actions
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
certificateAuthorityArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe POSIX
createdAt
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
policy
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
principal
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
sourceAccount