{-# 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.Grafana.Types.IdpMetadata
-- 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.Grafana.Types.IdpMetadata where

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

-- | A structure containing the identity provider (IdP) metadata used to
-- integrate the identity provider with this workspace. You can specify the
-- metadata either by providing a URL to its location in the @url@
-- parameter, or by specifying the full metadata in XML format in the @xml@
-- parameter.
--
-- /See:/ 'newIdpMetadata' smart constructor.
data IdpMetadata = IdpMetadata'
  { -- | The URL of the location containing the metadata.
    IdpMetadata -> Maybe Text
url :: Prelude.Maybe Prelude.Text,
    -- | The actual full metadata file, in XML format.
    IdpMetadata -> Maybe Text
xml :: Prelude.Maybe Prelude.Text
  }
  deriving (IdpMetadata -> IdpMetadata -> Bool
(IdpMetadata -> IdpMetadata -> Bool)
-> (IdpMetadata -> IdpMetadata -> Bool) -> Eq IdpMetadata
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: IdpMetadata -> IdpMetadata -> Bool
$c/= :: IdpMetadata -> IdpMetadata -> Bool
== :: IdpMetadata -> IdpMetadata -> Bool
$c== :: IdpMetadata -> IdpMetadata -> Bool
Prelude.Eq, ReadPrec [IdpMetadata]
ReadPrec IdpMetadata
Int -> ReadS IdpMetadata
ReadS [IdpMetadata]
(Int -> ReadS IdpMetadata)
-> ReadS [IdpMetadata]
-> ReadPrec IdpMetadata
-> ReadPrec [IdpMetadata]
-> Read IdpMetadata
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [IdpMetadata]
$creadListPrec :: ReadPrec [IdpMetadata]
readPrec :: ReadPrec IdpMetadata
$creadPrec :: ReadPrec IdpMetadata
readList :: ReadS [IdpMetadata]
$creadList :: ReadS [IdpMetadata]
readsPrec :: Int -> ReadS IdpMetadata
$creadsPrec :: Int -> ReadS IdpMetadata
Prelude.Read, Int -> IdpMetadata -> ShowS
[IdpMetadata] -> ShowS
IdpMetadata -> String
(Int -> IdpMetadata -> ShowS)
-> (IdpMetadata -> String)
-> ([IdpMetadata] -> ShowS)
-> Show IdpMetadata
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IdpMetadata] -> ShowS
$cshowList :: [IdpMetadata] -> ShowS
show :: IdpMetadata -> String
$cshow :: IdpMetadata -> String
showsPrec :: Int -> IdpMetadata -> ShowS
$cshowsPrec :: Int -> IdpMetadata -> ShowS
Prelude.Show, (forall x. IdpMetadata -> Rep IdpMetadata x)
-> (forall x. Rep IdpMetadata x -> IdpMetadata)
-> Generic IdpMetadata
forall x. Rep IdpMetadata x -> IdpMetadata
forall x. IdpMetadata -> Rep IdpMetadata x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep IdpMetadata x -> IdpMetadata
$cfrom :: forall x. IdpMetadata -> Rep IdpMetadata x
Prelude.Generic)

-- |
-- Create a value of 'IdpMetadata' 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:
--
-- 'url', 'idpMetadata_url' - The URL of the location containing the metadata.
--
-- 'xml', 'idpMetadata_xml' - The actual full metadata file, in XML format.
newIdpMetadata ::
  IdpMetadata
newIdpMetadata :: IdpMetadata
newIdpMetadata =
  IdpMetadata' :: Maybe Text -> Maybe Text -> IdpMetadata
IdpMetadata'
    { $sel:url:IdpMetadata' :: Maybe Text
url = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:xml:IdpMetadata' :: Maybe Text
xml = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The URL of the location containing the metadata.
idpMetadata_url :: Lens.Lens' IdpMetadata (Prelude.Maybe Prelude.Text)
idpMetadata_url :: (Maybe Text -> f (Maybe Text)) -> IdpMetadata -> f IdpMetadata
idpMetadata_url = (IdpMetadata -> Maybe Text)
-> (IdpMetadata -> Maybe Text -> IdpMetadata)
-> Lens IdpMetadata IdpMetadata (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IdpMetadata' {Maybe Text
url :: Maybe Text
$sel:url:IdpMetadata' :: IdpMetadata -> Maybe Text
url} -> Maybe Text
url) (\s :: IdpMetadata
s@IdpMetadata' {} Maybe Text
a -> IdpMetadata
s {$sel:url:IdpMetadata' :: Maybe Text
url = Maybe Text
a} :: IdpMetadata)

-- | The actual full metadata file, in XML format.
idpMetadata_xml :: Lens.Lens' IdpMetadata (Prelude.Maybe Prelude.Text)
idpMetadata_xml :: (Maybe Text -> f (Maybe Text)) -> IdpMetadata -> f IdpMetadata
idpMetadata_xml = (IdpMetadata -> Maybe Text)
-> (IdpMetadata -> Maybe Text -> IdpMetadata)
-> Lens IdpMetadata IdpMetadata (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IdpMetadata' {Maybe Text
xml :: Maybe Text
$sel:xml:IdpMetadata' :: IdpMetadata -> Maybe Text
xml} -> Maybe Text
xml) (\s :: IdpMetadata
s@IdpMetadata' {} Maybe Text
a -> IdpMetadata
s {$sel:xml:IdpMetadata' :: Maybe Text
xml = Maybe Text
a} :: IdpMetadata)

instance Core.FromJSON IdpMetadata where
  parseJSON :: Value -> Parser IdpMetadata
parseJSON =
    String
-> (Object -> Parser IdpMetadata) -> Value -> Parser IdpMetadata
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"IdpMetadata"
      ( \Object
x ->
          Maybe Text -> Maybe Text -> IdpMetadata
IdpMetadata'
            (Maybe Text -> Maybe Text -> IdpMetadata)
-> Parser (Maybe Text) -> Parser (Maybe Text -> IdpMetadata)
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
"url") Parser (Maybe Text -> IdpMetadata)
-> Parser (Maybe Text) -> Parser IdpMetadata
forall (f :: * -> *) a b. Applicative f => 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
"xml")
      )

instance Prelude.Hashable IdpMetadata

instance Prelude.NFData IdpMetadata

instance Core.ToJSON IdpMetadata where
  toJSON :: IdpMetadata -> Value
toJSON IdpMetadata' {Maybe Text
xml :: Maybe Text
url :: Maybe Text
$sel:xml:IdpMetadata' :: IdpMetadata -> Maybe Text
$sel:url:IdpMetadata' :: IdpMetadata -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"url" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
url,
            (Text
"xml" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
xml
          ]
      )