{-# 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.CloudFront.Types.EncryptionEntity
-- 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.CloudFront.Types.EncryptionEntity where

import Amazonka.CloudFront.Types.FieldPatterns
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Complex data type for field-level encryption profiles that includes the
-- encryption key and field pattern specifications.
--
-- /See:/ 'newEncryptionEntity' smart constructor.
data EncryptionEntity = EncryptionEntity'
  { -- | The public key associated with a set of field-level encryption patterns,
    -- to be used when encrypting the fields that match the patterns.
    EncryptionEntity -> Text
publicKeyId :: Prelude.Text,
    -- | The provider associated with the public key being used for encryption.
    -- This value must also be provided with the private key for applications
    -- to be able to decrypt data.
    EncryptionEntity -> Text
providerId :: Prelude.Text,
    -- | Field patterns in a field-level encryption content type profile specify
    -- the fields that you want to be encrypted. You can provide the full field
    -- name, or any beginning characters followed by a wildcard (*). You can\'t
    -- overlap field patterns. For example, you can\'t have both ABC* and AB*.
    -- Note that field patterns are case-sensitive.
    EncryptionEntity -> FieldPatterns
fieldPatterns :: FieldPatterns
  }
  deriving (EncryptionEntity -> EncryptionEntity -> Bool
(EncryptionEntity -> EncryptionEntity -> Bool)
-> (EncryptionEntity -> EncryptionEntity -> Bool)
-> Eq EncryptionEntity
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EncryptionEntity -> EncryptionEntity -> Bool
$c/= :: EncryptionEntity -> EncryptionEntity -> Bool
== :: EncryptionEntity -> EncryptionEntity -> Bool
$c== :: EncryptionEntity -> EncryptionEntity -> Bool
Prelude.Eq, ReadPrec [EncryptionEntity]
ReadPrec EncryptionEntity
Int -> ReadS EncryptionEntity
ReadS [EncryptionEntity]
(Int -> ReadS EncryptionEntity)
-> ReadS [EncryptionEntity]
-> ReadPrec EncryptionEntity
-> ReadPrec [EncryptionEntity]
-> Read EncryptionEntity
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [EncryptionEntity]
$creadListPrec :: ReadPrec [EncryptionEntity]
readPrec :: ReadPrec EncryptionEntity
$creadPrec :: ReadPrec EncryptionEntity
readList :: ReadS [EncryptionEntity]
$creadList :: ReadS [EncryptionEntity]
readsPrec :: Int -> ReadS EncryptionEntity
$creadsPrec :: Int -> ReadS EncryptionEntity
Prelude.Read, Int -> EncryptionEntity -> ShowS
[EncryptionEntity] -> ShowS
EncryptionEntity -> String
(Int -> EncryptionEntity -> ShowS)
-> (EncryptionEntity -> String)
-> ([EncryptionEntity] -> ShowS)
-> Show EncryptionEntity
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EncryptionEntity] -> ShowS
$cshowList :: [EncryptionEntity] -> ShowS
show :: EncryptionEntity -> String
$cshow :: EncryptionEntity -> String
showsPrec :: Int -> EncryptionEntity -> ShowS
$cshowsPrec :: Int -> EncryptionEntity -> ShowS
Prelude.Show, (forall x. EncryptionEntity -> Rep EncryptionEntity x)
-> (forall x. Rep EncryptionEntity x -> EncryptionEntity)
-> Generic EncryptionEntity
forall x. Rep EncryptionEntity x -> EncryptionEntity
forall x. EncryptionEntity -> Rep EncryptionEntity x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep EncryptionEntity x -> EncryptionEntity
$cfrom :: forall x. EncryptionEntity -> Rep EncryptionEntity x
Prelude.Generic)

-- |
-- Create a value of 'EncryptionEntity' 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:
--
-- 'publicKeyId', 'encryptionEntity_publicKeyId' - The public key associated with a set of field-level encryption patterns,
-- to be used when encrypting the fields that match the patterns.
--
-- 'providerId', 'encryptionEntity_providerId' - The provider associated with the public key being used for encryption.
-- This value must also be provided with the private key for applications
-- to be able to decrypt data.
--
-- 'fieldPatterns', 'encryptionEntity_fieldPatterns' - Field patterns in a field-level encryption content type profile specify
-- the fields that you want to be encrypted. You can provide the full field
-- name, or any beginning characters followed by a wildcard (*). You can\'t
-- overlap field patterns. For example, you can\'t have both ABC* and AB*.
-- Note that field patterns are case-sensitive.
newEncryptionEntity ::
  -- | 'publicKeyId'
  Prelude.Text ->
  -- | 'providerId'
  Prelude.Text ->
  -- | 'fieldPatterns'
  FieldPatterns ->
  EncryptionEntity
newEncryptionEntity :: Text -> Text -> FieldPatterns -> EncryptionEntity
newEncryptionEntity
  Text
pPublicKeyId_
  Text
pProviderId_
  FieldPatterns
pFieldPatterns_ =
    EncryptionEntity' :: Text -> Text -> FieldPatterns -> EncryptionEntity
EncryptionEntity'
      { $sel:publicKeyId:EncryptionEntity' :: Text
publicKeyId = Text
pPublicKeyId_,
        $sel:providerId:EncryptionEntity' :: Text
providerId = Text
pProviderId_,
        $sel:fieldPatterns:EncryptionEntity' :: FieldPatterns
fieldPatterns = FieldPatterns
pFieldPatterns_
      }

-- | The public key associated with a set of field-level encryption patterns,
-- to be used when encrypting the fields that match the patterns.
encryptionEntity_publicKeyId :: Lens.Lens' EncryptionEntity Prelude.Text
encryptionEntity_publicKeyId :: (Text -> f Text) -> EncryptionEntity -> f EncryptionEntity
encryptionEntity_publicKeyId = (EncryptionEntity -> Text)
-> (EncryptionEntity -> Text -> EncryptionEntity)
-> Lens EncryptionEntity EncryptionEntity Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EncryptionEntity' {Text
publicKeyId :: Text
$sel:publicKeyId:EncryptionEntity' :: EncryptionEntity -> Text
publicKeyId} -> Text
publicKeyId) (\s :: EncryptionEntity
s@EncryptionEntity' {} Text
a -> EncryptionEntity
s {$sel:publicKeyId:EncryptionEntity' :: Text
publicKeyId = Text
a} :: EncryptionEntity)

-- | The provider associated with the public key being used for encryption.
-- This value must also be provided with the private key for applications
-- to be able to decrypt data.
encryptionEntity_providerId :: Lens.Lens' EncryptionEntity Prelude.Text
encryptionEntity_providerId :: (Text -> f Text) -> EncryptionEntity -> f EncryptionEntity
encryptionEntity_providerId = (EncryptionEntity -> Text)
-> (EncryptionEntity -> Text -> EncryptionEntity)
-> Lens EncryptionEntity EncryptionEntity Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EncryptionEntity' {Text
providerId :: Text
$sel:providerId:EncryptionEntity' :: EncryptionEntity -> Text
providerId} -> Text
providerId) (\s :: EncryptionEntity
s@EncryptionEntity' {} Text
a -> EncryptionEntity
s {$sel:providerId:EncryptionEntity' :: Text
providerId = Text
a} :: EncryptionEntity)

-- | Field patterns in a field-level encryption content type profile specify
-- the fields that you want to be encrypted. You can provide the full field
-- name, or any beginning characters followed by a wildcard (*). You can\'t
-- overlap field patterns. For example, you can\'t have both ABC* and AB*.
-- Note that field patterns are case-sensitive.
encryptionEntity_fieldPatterns :: Lens.Lens' EncryptionEntity FieldPatterns
encryptionEntity_fieldPatterns :: (FieldPatterns -> f FieldPatterns)
-> EncryptionEntity -> f EncryptionEntity
encryptionEntity_fieldPatterns = (EncryptionEntity -> FieldPatterns)
-> (EncryptionEntity -> FieldPatterns -> EncryptionEntity)
-> Lens
     EncryptionEntity EncryptionEntity FieldPatterns FieldPatterns
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EncryptionEntity' {FieldPatterns
fieldPatterns :: FieldPatterns
$sel:fieldPatterns:EncryptionEntity' :: EncryptionEntity -> FieldPatterns
fieldPatterns} -> FieldPatterns
fieldPatterns) (\s :: EncryptionEntity
s@EncryptionEntity' {} FieldPatterns
a -> EncryptionEntity
s {$sel:fieldPatterns:EncryptionEntity' :: FieldPatterns
fieldPatterns = FieldPatterns
a} :: EncryptionEntity)

instance Core.FromXML EncryptionEntity where
  parseXML :: [Node] -> Either String EncryptionEntity
parseXML [Node]
x =
    Text -> Text -> FieldPatterns -> EncryptionEntity
EncryptionEntity'
      (Text -> Text -> FieldPatterns -> EncryptionEntity)
-> Either String Text
-> Either String (Text -> FieldPatterns -> EncryptionEntity)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String Text
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"PublicKeyId")
      Either String (Text -> FieldPatterns -> EncryptionEntity)
-> Either String Text
-> Either String (FieldPatterns -> EncryptionEntity)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Text
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"ProviderId")
      Either String (FieldPatterns -> EncryptionEntity)
-> Either String FieldPatterns -> Either String EncryptionEntity
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String FieldPatterns
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"FieldPatterns")

instance Prelude.Hashable EncryptionEntity

instance Prelude.NFData EncryptionEntity

instance Core.ToXML EncryptionEntity where
  toXML :: EncryptionEntity -> XML
toXML EncryptionEntity' {Text
FieldPatterns
fieldPatterns :: FieldPatterns
providerId :: Text
publicKeyId :: Text
$sel:fieldPatterns:EncryptionEntity' :: EncryptionEntity -> FieldPatterns
$sel:providerId:EncryptionEntity' :: EncryptionEntity -> Text
$sel:publicKeyId:EncryptionEntity' :: EncryptionEntity -> Text
..} =
    [XML] -> XML
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ Name
"PublicKeyId" Name -> Text -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Text
publicKeyId,
        Name
"ProviderId" Name -> Text -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Text
providerId,
        Name
"FieldPatterns" Name -> FieldPatterns -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= FieldPatterns
fieldPatterns
      ]