{-# 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.Redshift.Types.SnapshotCopyGrant
-- 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.Redshift.Types.SnapshotCopyGrant where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.Redshift.Internal
import Amazonka.Redshift.Types.Tag

-- | The snapshot copy grant that grants Amazon Redshift permission to
-- encrypt copied snapshots with the specified customer master key (CMK)
-- from Amazon Web Services KMS in the destination region.
--
-- For more information about managing snapshot copy grants, go to
-- <https://docs.aws.amazon.com/redshift/latest/mgmt/working-with-db-encryption.html Amazon Redshift Database Encryption>
-- in the /Amazon Redshift Cluster Management Guide/.
--
-- /See:/ 'newSnapshotCopyGrant' smart constructor.
data SnapshotCopyGrant = SnapshotCopyGrant'
  { -- | The unique identifier of the customer master key (CMK) in Amazon Web
    -- Services KMS to which Amazon Redshift is granted permission.
    SnapshotCopyGrant -> Maybe Text
kmsKeyId :: Prelude.Maybe Prelude.Text,
    -- | The name of the snapshot copy grant.
    SnapshotCopyGrant -> Maybe Text
snapshotCopyGrantName :: Prelude.Maybe Prelude.Text,
    -- | A list of tag instances.
    SnapshotCopyGrant -> Maybe [Tag]
tags :: Prelude.Maybe [Tag]
  }
  deriving (SnapshotCopyGrant -> SnapshotCopyGrant -> Bool
(SnapshotCopyGrant -> SnapshotCopyGrant -> Bool)
-> (SnapshotCopyGrant -> SnapshotCopyGrant -> Bool)
-> Eq SnapshotCopyGrant
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SnapshotCopyGrant -> SnapshotCopyGrant -> Bool
$c/= :: SnapshotCopyGrant -> SnapshotCopyGrant -> Bool
== :: SnapshotCopyGrant -> SnapshotCopyGrant -> Bool
$c== :: SnapshotCopyGrant -> SnapshotCopyGrant -> Bool
Prelude.Eq, ReadPrec [SnapshotCopyGrant]
ReadPrec SnapshotCopyGrant
Int -> ReadS SnapshotCopyGrant
ReadS [SnapshotCopyGrant]
(Int -> ReadS SnapshotCopyGrant)
-> ReadS [SnapshotCopyGrant]
-> ReadPrec SnapshotCopyGrant
-> ReadPrec [SnapshotCopyGrant]
-> Read SnapshotCopyGrant
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SnapshotCopyGrant]
$creadListPrec :: ReadPrec [SnapshotCopyGrant]
readPrec :: ReadPrec SnapshotCopyGrant
$creadPrec :: ReadPrec SnapshotCopyGrant
readList :: ReadS [SnapshotCopyGrant]
$creadList :: ReadS [SnapshotCopyGrant]
readsPrec :: Int -> ReadS SnapshotCopyGrant
$creadsPrec :: Int -> ReadS SnapshotCopyGrant
Prelude.Read, Int -> SnapshotCopyGrant -> ShowS
[SnapshotCopyGrant] -> ShowS
SnapshotCopyGrant -> String
(Int -> SnapshotCopyGrant -> ShowS)
-> (SnapshotCopyGrant -> String)
-> ([SnapshotCopyGrant] -> ShowS)
-> Show SnapshotCopyGrant
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SnapshotCopyGrant] -> ShowS
$cshowList :: [SnapshotCopyGrant] -> ShowS
show :: SnapshotCopyGrant -> String
$cshow :: SnapshotCopyGrant -> String
showsPrec :: Int -> SnapshotCopyGrant -> ShowS
$cshowsPrec :: Int -> SnapshotCopyGrant -> ShowS
Prelude.Show, (forall x. SnapshotCopyGrant -> Rep SnapshotCopyGrant x)
-> (forall x. Rep SnapshotCopyGrant x -> SnapshotCopyGrant)
-> Generic SnapshotCopyGrant
forall x. Rep SnapshotCopyGrant x -> SnapshotCopyGrant
forall x. SnapshotCopyGrant -> Rep SnapshotCopyGrant x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SnapshotCopyGrant x -> SnapshotCopyGrant
$cfrom :: forall x. SnapshotCopyGrant -> Rep SnapshotCopyGrant x
Prelude.Generic)

-- |
-- Create a value of 'SnapshotCopyGrant' 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:
--
-- 'kmsKeyId', 'snapshotCopyGrant_kmsKeyId' - The unique identifier of the customer master key (CMK) in Amazon Web
-- Services KMS to which Amazon Redshift is granted permission.
--
-- 'snapshotCopyGrantName', 'snapshotCopyGrant_snapshotCopyGrantName' - The name of the snapshot copy grant.
--
-- 'tags', 'snapshotCopyGrant_tags' - A list of tag instances.
newSnapshotCopyGrant ::
  SnapshotCopyGrant
newSnapshotCopyGrant :: SnapshotCopyGrant
newSnapshotCopyGrant =
  SnapshotCopyGrant' :: Maybe Text -> Maybe Text -> Maybe [Tag] -> SnapshotCopyGrant
SnapshotCopyGrant'
    { $sel:kmsKeyId:SnapshotCopyGrant' :: Maybe Text
kmsKeyId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:snapshotCopyGrantName:SnapshotCopyGrant' :: Maybe Text
snapshotCopyGrantName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:tags:SnapshotCopyGrant' :: Maybe [Tag]
tags = Maybe [Tag]
forall a. Maybe a
Prelude.Nothing
    }

-- | The unique identifier of the customer master key (CMK) in Amazon Web
-- Services KMS to which Amazon Redshift is granted permission.
snapshotCopyGrant_kmsKeyId :: Lens.Lens' SnapshotCopyGrant (Prelude.Maybe Prelude.Text)
snapshotCopyGrant_kmsKeyId :: (Maybe Text -> f (Maybe Text))
-> SnapshotCopyGrant -> f SnapshotCopyGrant
snapshotCopyGrant_kmsKeyId = (SnapshotCopyGrant -> Maybe Text)
-> (SnapshotCopyGrant -> Maybe Text -> SnapshotCopyGrant)
-> Lens
     SnapshotCopyGrant SnapshotCopyGrant (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SnapshotCopyGrant' {Maybe Text
kmsKeyId :: Maybe Text
$sel:kmsKeyId:SnapshotCopyGrant' :: SnapshotCopyGrant -> Maybe Text
kmsKeyId} -> Maybe Text
kmsKeyId) (\s :: SnapshotCopyGrant
s@SnapshotCopyGrant' {} Maybe Text
a -> SnapshotCopyGrant
s {$sel:kmsKeyId:SnapshotCopyGrant' :: Maybe Text
kmsKeyId = Maybe Text
a} :: SnapshotCopyGrant)

-- | The name of the snapshot copy grant.
snapshotCopyGrant_snapshotCopyGrantName :: Lens.Lens' SnapshotCopyGrant (Prelude.Maybe Prelude.Text)
snapshotCopyGrant_snapshotCopyGrantName :: (Maybe Text -> f (Maybe Text))
-> SnapshotCopyGrant -> f SnapshotCopyGrant
snapshotCopyGrant_snapshotCopyGrantName = (SnapshotCopyGrant -> Maybe Text)
-> (SnapshotCopyGrant -> Maybe Text -> SnapshotCopyGrant)
-> Lens
     SnapshotCopyGrant SnapshotCopyGrant (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SnapshotCopyGrant' {Maybe Text
snapshotCopyGrantName :: Maybe Text
$sel:snapshotCopyGrantName:SnapshotCopyGrant' :: SnapshotCopyGrant -> Maybe Text
snapshotCopyGrantName} -> Maybe Text
snapshotCopyGrantName) (\s :: SnapshotCopyGrant
s@SnapshotCopyGrant' {} Maybe Text
a -> SnapshotCopyGrant
s {$sel:snapshotCopyGrantName:SnapshotCopyGrant' :: Maybe Text
snapshotCopyGrantName = Maybe Text
a} :: SnapshotCopyGrant)

-- | A list of tag instances.
snapshotCopyGrant_tags :: Lens.Lens' SnapshotCopyGrant (Prelude.Maybe [Tag])
snapshotCopyGrant_tags :: (Maybe [Tag] -> f (Maybe [Tag]))
-> SnapshotCopyGrant -> f SnapshotCopyGrant
snapshotCopyGrant_tags = (SnapshotCopyGrant -> Maybe [Tag])
-> (SnapshotCopyGrant -> Maybe [Tag] -> SnapshotCopyGrant)
-> Lens
     SnapshotCopyGrant SnapshotCopyGrant (Maybe [Tag]) (Maybe [Tag])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SnapshotCopyGrant' {Maybe [Tag]
tags :: Maybe [Tag]
$sel:tags:SnapshotCopyGrant' :: SnapshotCopyGrant -> Maybe [Tag]
tags} -> Maybe [Tag]
tags) (\s :: SnapshotCopyGrant
s@SnapshotCopyGrant' {} Maybe [Tag]
a -> SnapshotCopyGrant
s {$sel:tags:SnapshotCopyGrant' :: Maybe [Tag]
tags = Maybe [Tag]
a} :: SnapshotCopyGrant) ((Maybe [Tag] -> f (Maybe [Tag]))
 -> SnapshotCopyGrant -> f SnapshotCopyGrant)
-> ((Maybe [Tag] -> f (Maybe [Tag]))
    -> Maybe [Tag] -> f (Maybe [Tag]))
-> (Maybe [Tag] -> f (Maybe [Tag]))
-> SnapshotCopyGrant
-> f SnapshotCopyGrant
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Tag] [Tag] [Tag] [Tag]
-> Iso (Maybe [Tag]) (Maybe [Tag]) (Maybe [Tag]) (Maybe [Tag])
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 [Tag] [Tag] [Tag] [Tag]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromXML SnapshotCopyGrant where
  parseXML :: [Node] -> Either String SnapshotCopyGrant
parseXML [Node]
x =
    Maybe Text -> Maybe Text -> Maybe [Tag] -> SnapshotCopyGrant
SnapshotCopyGrant'
      (Maybe Text -> Maybe Text -> Maybe [Tag] -> SnapshotCopyGrant)
-> Either String (Maybe Text)
-> Either String (Maybe Text -> Maybe [Tag] -> SnapshotCopyGrant)
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
"KmsKeyId")
      Either String (Maybe Text -> Maybe [Tag] -> SnapshotCopyGrant)
-> Either String (Maybe Text)
-> Either String (Maybe [Tag] -> SnapshotCopyGrant)
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
"SnapshotCopyGrantName")
      Either String (Maybe [Tag] -> SnapshotCopyGrant)
-> Either String (Maybe [Tag]) -> Either String SnapshotCopyGrant
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( [Node]
x [Node] -> Text -> Either String (Maybe [Node])
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Tags" Either String (Maybe [Node]) -> [Node] -> Either String [Node]
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ [Node]
forall a. Monoid a => a
Prelude.mempty
                      Either String [Node]
-> ([Node] -> Either String (Maybe [Tag]))
-> Either String (Maybe [Tag])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= ([Node] -> Either String [Tag])
-> [Node] -> Either String (Maybe [Tag])
forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (Text -> [Node] -> Either String [Tag]
forall a. FromXML a => Text -> [Node] -> Either String [a]
Core.parseXMLList Text
"Tag")
                  )

instance Prelude.Hashable SnapshotCopyGrant

instance Prelude.NFData SnapshotCopyGrant