{-# 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.CodePipeline.Types.EncryptionKey
-- 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.CodePipeline.Types.EncryptionKey where

import Amazonka.CodePipeline.Types.EncryptionKeyType
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Represents information about the key used to encrypt data in the
-- artifact store, such as an AWS Key Management Service (AWS KMS) key.
--
-- /See:/ 'newEncryptionKey' smart constructor.
data EncryptionKey = EncryptionKey'
  { -- | The ID used to identify the key. For an AWS KMS key, you can use the key
    -- ID, the key ARN, or the alias ARN.
    --
    -- Aliases are recognized only in the account that created the customer
    -- master key (CMK). For cross-account actions, you can only use the key ID
    -- or key ARN to identify the key.
    EncryptionKey -> Text
id :: Prelude.Text,
    -- | The type of encryption key, such as an AWS Key Management Service (AWS
    -- KMS) key. When creating or updating a pipeline, the value must be set to
    -- \'KMS\'.
    EncryptionKey -> EncryptionKeyType
type' :: EncryptionKeyType
  }
  deriving (EncryptionKey -> EncryptionKey -> Bool
(EncryptionKey -> EncryptionKey -> Bool)
-> (EncryptionKey -> EncryptionKey -> Bool) -> Eq EncryptionKey
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EncryptionKey -> EncryptionKey -> Bool
$c/= :: EncryptionKey -> EncryptionKey -> Bool
== :: EncryptionKey -> EncryptionKey -> Bool
$c== :: EncryptionKey -> EncryptionKey -> Bool
Prelude.Eq, ReadPrec [EncryptionKey]
ReadPrec EncryptionKey
Int -> ReadS EncryptionKey
ReadS [EncryptionKey]
(Int -> ReadS EncryptionKey)
-> ReadS [EncryptionKey]
-> ReadPrec EncryptionKey
-> ReadPrec [EncryptionKey]
-> Read EncryptionKey
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [EncryptionKey]
$creadListPrec :: ReadPrec [EncryptionKey]
readPrec :: ReadPrec EncryptionKey
$creadPrec :: ReadPrec EncryptionKey
readList :: ReadS [EncryptionKey]
$creadList :: ReadS [EncryptionKey]
readsPrec :: Int -> ReadS EncryptionKey
$creadsPrec :: Int -> ReadS EncryptionKey
Prelude.Read, Int -> EncryptionKey -> ShowS
[EncryptionKey] -> ShowS
EncryptionKey -> String
(Int -> EncryptionKey -> ShowS)
-> (EncryptionKey -> String)
-> ([EncryptionKey] -> ShowS)
-> Show EncryptionKey
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EncryptionKey] -> ShowS
$cshowList :: [EncryptionKey] -> ShowS
show :: EncryptionKey -> String
$cshow :: EncryptionKey -> String
showsPrec :: Int -> EncryptionKey -> ShowS
$cshowsPrec :: Int -> EncryptionKey -> ShowS
Prelude.Show, (forall x. EncryptionKey -> Rep EncryptionKey x)
-> (forall x. Rep EncryptionKey x -> EncryptionKey)
-> Generic EncryptionKey
forall x. Rep EncryptionKey x -> EncryptionKey
forall x. EncryptionKey -> Rep EncryptionKey x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep EncryptionKey x -> EncryptionKey
$cfrom :: forall x. EncryptionKey -> Rep EncryptionKey x
Prelude.Generic)

-- |
-- Create a value of 'EncryptionKey' 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:
--
-- 'id', 'encryptionKey_id' - The ID used to identify the key. For an AWS KMS key, you can use the key
-- ID, the key ARN, or the alias ARN.
--
-- Aliases are recognized only in the account that created the customer
-- master key (CMK). For cross-account actions, you can only use the key ID
-- or key ARN to identify the key.
--
-- 'type'', 'encryptionKey_type' - The type of encryption key, such as an AWS Key Management Service (AWS
-- KMS) key. When creating or updating a pipeline, the value must be set to
-- \'KMS\'.
newEncryptionKey ::
  -- | 'id'
  Prelude.Text ->
  -- | 'type''
  EncryptionKeyType ->
  EncryptionKey
newEncryptionKey :: Text -> EncryptionKeyType -> EncryptionKey
newEncryptionKey Text
pId_ EncryptionKeyType
pType_ =
  EncryptionKey' :: Text -> EncryptionKeyType -> EncryptionKey
EncryptionKey' {$sel:id:EncryptionKey' :: Text
id = Text
pId_, $sel:type':EncryptionKey' :: EncryptionKeyType
type' = EncryptionKeyType
pType_}

-- | The ID used to identify the key. For an AWS KMS key, you can use the key
-- ID, the key ARN, or the alias ARN.
--
-- Aliases are recognized only in the account that created the customer
-- master key (CMK). For cross-account actions, you can only use the key ID
-- or key ARN to identify the key.
encryptionKey_id :: Lens.Lens' EncryptionKey Prelude.Text
encryptionKey_id :: (Text -> f Text) -> EncryptionKey -> f EncryptionKey
encryptionKey_id = (EncryptionKey -> Text)
-> (EncryptionKey -> Text -> EncryptionKey)
-> Lens EncryptionKey EncryptionKey Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EncryptionKey' {Text
id :: Text
$sel:id:EncryptionKey' :: EncryptionKey -> Text
id} -> Text
id) (\s :: EncryptionKey
s@EncryptionKey' {} Text
a -> EncryptionKey
s {$sel:id:EncryptionKey' :: Text
id = Text
a} :: EncryptionKey)

-- | The type of encryption key, such as an AWS Key Management Service (AWS
-- KMS) key. When creating or updating a pipeline, the value must be set to
-- \'KMS\'.
encryptionKey_type :: Lens.Lens' EncryptionKey EncryptionKeyType
encryptionKey_type :: (EncryptionKeyType -> f EncryptionKeyType)
-> EncryptionKey -> f EncryptionKey
encryptionKey_type = (EncryptionKey -> EncryptionKeyType)
-> (EncryptionKey -> EncryptionKeyType -> EncryptionKey)
-> Lens
     EncryptionKey EncryptionKey EncryptionKeyType EncryptionKeyType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EncryptionKey' {EncryptionKeyType
type' :: EncryptionKeyType
$sel:type':EncryptionKey' :: EncryptionKey -> EncryptionKeyType
type'} -> EncryptionKeyType
type') (\s :: EncryptionKey
s@EncryptionKey' {} EncryptionKeyType
a -> EncryptionKey
s {$sel:type':EncryptionKey' :: EncryptionKeyType
type' = EncryptionKeyType
a} :: EncryptionKey)

instance Core.FromJSON EncryptionKey where
  parseJSON :: Value -> Parser EncryptionKey
parseJSON =
    String
-> (Object -> Parser EncryptionKey)
-> Value
-> Parser EncryptionKey
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"EncryptionKey"
      ( \Object
x ->
          Text -> EncryptionKeyType -> EncryptionKey
EncryptionKey'
            (Text -> EncryptionKeyType -> EncryptionKey)
-> Parser Text -> Parser (EncryptionKeyType -> EncryptionKey)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"id") Parser (EncryptionKeyType -> EncryptionKey)
-> Parser EncryptionKeyType -> Parser EncryptionKey
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser EncryptionKeyType
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"type")
      )

instance Prelude.Hashable EncryptionKey

instance Prelude.NFData EncryptionKey

instance Core.ToJSON EncryptionKey where
  toJSON :: EncryptionKey -> Value
toJSON EncryptionKey' {Text
EncryptionKeyType
type' :: EncryptionKeyType
id :: Text
$sel:type':EncryptionKey' :: EncryptionKey -> EncryptionKeyType
$sel:id:EncryptionKey' :: EncryptionKey -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"id" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
id),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"type" Text -> EncryptionKeyType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= EncryptionKeyType
type')
          ]
      )