{-# 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.MediaPackageVOD.Types.SpekeKeyProvider
-- 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.MediaPackageVOD.Types.SpekeKeyProvider where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A configuration for accessing an external Secure Packager and Encoder
-- Key Exchange (SPEKE) service that will provide encryption keys.
--
-- /See:/ 'newSpekeKeyProvider' smart constructor.
data SpekeKeyProvider = SpekeKeyProvider'
  { -- | The system IDs to include in key requests.
    SpekeKeyProvider -> [Text]
systemIds :: [Prelude.Text],
    -- | The URL of the external key provider service.
    SpekeKeyProvider -> Text
url :: Prelude.Text,
    -- | An Amazon Resource Name (ARN) of an IAM role that AWS Elemental
    -- MediaPackage will assume when accessing the key provider service.
    SpekeKeyProvider -> Text
roleArn :: Prelude.Text
  }
  deriving (SpekeKeyProvider -> SpekeKeyProvider -> Bool
(SpekeKeyProvider -> SpekeKeyProvider -> Bool)
-> (SpekeKeyProvider -> SpekeKeyProvider -> Bool)
-> Eq SpekeKeyProvider
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SpekeKeyProvider -> SpekeKeyProvider -> Bool
$c/= :: SpekeKeyProvider -> SpekeKeyProvider -> Bool
== :: SpekeKeyProvider -> SpekeKeyProvider -> Bool
$c== :: SpekeKeyProvider -> SpekeKeyProvider -> Bool
Prelude.Eq, ReadPrec [SpekeKeyProvider]
ReadPrec SpekeKeyProvider
Int -> ReadS SpekeKeyProvider
ReadS [SpekeKeyProvider]
(Int -> ReadS SpekeKeyProvider)
-> ReadS [SpekeKeyProvider]
-> ReadPrec SpekeKeyProvider
-> ReadPrec [SpekeKeyProvider]
-> Read SpekeKeyProvider
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SpekeKeyProvider]
$creadListPrec :: ReadPrec [SpekeKeyProvider]
readPrec :: ReadPrec SpekeKeyProvider
$creadPrec :: ReadPrec SpekeKeyProvider
readList :: ReadS [SpekeKeyProvider]
$creadList :: ReadS [SpekeKeyProvider]
readsPrec :: Int -> ReadS SpekeKeyProvider
$creadsPrec :: Int -> ReadS SpekeKeyProvider
Prelude.Read, Int -> SpekeKeyProvider -> ShowS
[SpekeKeyProvider] -> ShowS
SpekeKeyProvider -> String
(Int -> SpekeKeyProvider -> ShowS)
-> (SpekeKeyProvider -> String)
-> ([SpekeKeyProvider] -> ShowS)
-> Show SpekeKeyProvider
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SpekeKeyProvider] -> ShowS
$cshowList :: [SpekeKeyProvider] -> ShowS
show :: SpekeKeyProvider -> String
$cshow :: SpekeKeyProvider -> String
showsPrec :: Int -> SpekeKeyProvider -> ShowS
$cshowsPrec :: Int -> SpekeKeyProvider -> ShowS
Prelude.Show, (forall x. SpekeKeyProvider -> Rep SpekeKeyProvider x)
-> (forall x. Rep SpekeKeyProvider x -> SpekeKeyProvider)
-> Generic SpekeKeyProvider
forall x. Rep SpekeKeyProvider x -> SpekeKeyProvider
forall x. SpekeKeyProvider -> Rep SpekeKeyProvider x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SpekeKeyProvider x -> SpekeKeyProvider
$cfrom :: forall x. SpekeKeyProvider -> Rep SpekeKeyProvider x
Prelude.Generic)

-- |
-- Create a value of 'SpekeKeyProvider' 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:
--
-- 'systemIds', 'spekeKeyProvider_systemIds' - The system IDs to include in key requests.
--
-- 'url', 'spekeKeyProvider_url' - The URL of the external key provider service.
--
-- 'roleArn', 'spekeKeyProvider_roleArn' - An Amazon Resource Name (ARN) of an IAM role that AWS Elemental
-- MediaPackage will assume when accessing the key provider service.
newSpekeKeyProvider ::
  -- | 'url'
  Prelude.Text ->
  -- | 'roleArn'
  Prelude.Text ->
  SpekeKeyProvider
newSpekeKeyProvider :: Text -> Text -> SpekeKeyProvider
newSpekeKeyProvider Text
pUrl_ Text
pRoleArn_ =
  SpekeKeyProvider' :: [Text] -> Text -> Text -> SpekeKeyProvider
SpekeKeyProvider'
    { $sel:systemIds:SpekeKeyProvider' :: [Text]
systemIds = [Text]
forall a. Monoid a => a
Prelude.mempty,
      $sel:url:SpekeKeyProvider' :: Text
url = Text
pUrl_,
      $sel:roleArn:SpekeKeyProvider' :: Text
roleArn = Text
pRoleArn_
    }

-- | The system IDs to include in key requests.
spekeKeyProvider_systemIds :: Lens.Lens' SpekeKeyProvider [Prelude.Text]
spekeKeyProvider_systemIds :: ([Text] -> f [Text]) -> SpekeKeyProvider -> f SpekeKeyProvider
spekeKeyProvider_systemIds = (SpekeKeyProvider -> [Text])
-> (SpekeKeyProvider -> [Text] -> SpekeKeyProvider)
-> Lens SpekeKeyProvider SpekeKeyProvider [Text] [Text]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SpekeKeyProvider' {[Text]
systemIds :: [Text]
$sel:systemIds:SpekeKeyProvider' :: SpekeKeyProvider -> [Text]
systemIds} -> [Text]
systemIds) (\s :: SpekeKeyProvider
s@SpekeKeyProvider' {} [Text]
a -> SpekeKeyProvider
s {$sel:systemIds:SpekeKeyProvider' :: [Text]
systemIds = [Text]
a} :: SpekeKeyProvider) (([Text] -> f [Text]) -> SpekeKeyProvider -> f SpekeKeyProvider)
-> (([Text] -> f [Text]) -> [Text] -> f [Text])
-> ([Text] -> f [Text])
-> SpekeKeyProvider
-> f SpekeKeyProvider
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Text] -> f [Text]) -> [Text] -> f [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The URL of the external key provider service.
spekeKeyProvider_url :: Lens.Lens' SpekeKeyProvider Prelude.Text
spekeKeyProvider_url :: (Text -> f Text) -> SpekeKeyProvider -> f SpekeKeyProvider
spekeKeyProvider_url = (SpekeKeyProvider -> Text)
-> (SpekeKeyProvider -> Text -> SpekeKeyProvider)
-> Lens SpekeKeyProvider SpekeKeyProvider Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SpekeKeyProvider' {Text
url :: Text
$sel:url:SpekeKeyProvider' :: SpekeKeyProvider -> Text
url} -> Text
url) (\s :: SpekeKeyProvider
s@SpekeKeyProvider' {} Text
a -> SpekeKeyProvider
s {$sel:url:SpekeKeyProvider' :: Text
url = Text
a} :: SpekeKeyProvider)

-- | An Amazon Resource Name (ARN) of an IAM role that AWS Elemental
-- MediaPackage will assume when accessing the key provider service.
spekeKeyProvider_roleArn :: Lens.Lens' SpekeKeyProvider Prelude.Text
spekeKeyProvider_roleArn :: (Text -> f Text) -> SpekeKeyProvider -> f SpekeKeyProvider
spekeKeyProvider_roleArn = (SpekeKeyProvider -> Text)
-> (SpekeKeyProvider -> Text -> SpekeKeyProvider)
-> Lens SpekeKeyProvider SpekeKeyProvider Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SpekeKeyProvider' {Text
roleArn :: Text
$sel:roleArn:SpekeKeyProvider' :: SpekeKeyProvider -> Text
roleArn} -> Text
roleArn) (\s :: SpekeKeyProvider
s@SpekeKeyProvider' {} Text
a -> SpekeKeyProvider
s {$sel:roleArn:SpekeKeyProvider' :: Text
roleArn = Text
a} :: SpekeKeyProvider)

instance Core.FromJSON SpekeKeyProvider where
  parseJSON :: Value -> Parser SpekeKeyProvider
parseJSON =
    String
-> (Object -> Parser SpekeKeyProvider)
-> Value
-> Parser SpekeKeyProvider
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"SpekeKeyProvider"
      ( \Object
x ->
          [Text] -> Text -> Text -> SpekeKeyProvider
SpekeKeyProvider'
            ([Text] -> Text -> Text -> SpekeKeyProvider)
-> Parser [Text] -> Parser (Text -> Text -> SpekeKeyProvider)
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
"systemIds" Parser (Maybe [Text]) -> [Text] -> Parser [Text]
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= [Text]
forall a. Monoid a => a
Prelude.mempty)
            Parser (Text -> Text -> SpekeKeyProvider)
-> Parser Text -> Parser (Text -> SpekeKeyProvider)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"url")
            Parser (Text -> SpekeKeyProvider)
-> Parser Text -> Parser SpekeKeyProvider
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"roleArn")
      )

instance Prelude.Hashable SpekeKeyProvider

instance Prelude.NFData SpekeKeyProvider

instance Core.ToJSON SpekeKeyProvider where
  toJSON :: SpekeKeyProvider -> Value
toJSON SpekeKeyProvider' {[Text]
Text
roleArn :: Text
url :: Text
systemIds :: [Text]
$sel:roleArn:SpekeKeyProvider' :: SpekeKeyProvider -> Text
$sel:url:SpekeKeyProvider' :: SpekeKeyProvider -> Text
$sel:systemIds:SpekeKeyProvider' :: SpekeKeyProvider -> [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
"systemIds" Text -> [Text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [Text]
systemIds),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"url" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
url),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"roleArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
roleArn)
          ]
      )