{-# 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.OpenSearch.Types.CognitoOptions
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.OpenSearch.Types.CognitoOptions where

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

-- | Container for the parameters required to enable Cognito authentication
-- for an OpenSearch Service domain. For more information, see
-- <https://docs.aws.amazon.com/opensearch-service/latest/developerguide/cognito-auth.html Configuring Amazon Cognito authentication for OpenSearch Dashboards>.
--
-- /See:/ 'newCognitoOptions' smart constructor.
data CognitoOptions = CognitoOptions'
  { -- | Whether to enable or disable Amazon Cognito authentication for
    -- OpenSearch Dashboards.
    CognitoOptions -> Maybe Bool
enabled :: Prelude.Maybe Prelude.Bool,
    -- | The Amazon Cognito identity pool ID that you want OpenSearch Service to
    -- use for OpenSearch Dashboards authentication.
    CognitoOptions -> Maybe Text
identityPoolId :: Prelude.Maybe Prelude.Text,
    -- | The @AmazonOpenSearchServiceCognitoAccess@ role that allows OpenSearch
    -- Service to configure your user pool and identity pool.
    CognitoOptions -> Maybe Text
roleArn :: Prelude.Maybe Prelude.Text,
    -- | The Amazon Cognito user pool ID that you want OpenSearch Service to use
    -- for OpenSearch Dashboards authentication.
    CognitoOptions -> Maybe Text
userPoolId :: Prelude.Maybe Prelude.Text
  }
  deriving (CognitoOptions -> CognitoOptions -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CognitoOptions -> CognitoOptions -> Bool
$c/= :: CognitoOptions -> CognitoOptions -> Bool
== :: CognitoOptions -> CognitoOptions -> Bool
$c== :: CognitoOptions -> CognitoOptions -> Bool
Prelude.Eq, ReadPrec [CognitoOptions]
ReadPrec CognitoOptions
Int -> ReadS CognitoOptions
ReadS [CognitoOptions]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CognitoOptions]
$creadListPrec :: ReadPrec [CognitoOptions]
readPrec :: ReadPrec CognitoOptions
$creadPrec :: ReadPrec CognitoOptions
readList :: ReadS [CognitoOptions]
$creadList :: ReadS [CognitoOptions]
readsPrec :: Int -> ReadS CognitoOptions
$creadsPrec :: Int -> ReadS CognitoOptions
Prelude.Read, Int -> CognitoOptions -> ShowS
[CognitoOptions] -> ShowS
CognitoOptions -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CognitoOptions] -> ShowS
$cshowList :: [CognitoOptions] -> ShowS
show :: CognitoOptions -> String
$cshow :: CognitoOptions -> String
showsPrec :: Int -> CognitoOptions -> ShowS
$cshowsPrec :: Int -> CognitoOptions -> ShowS
Prelude.Show, forall x. Rep CognitoOptions x -> CognitoOptions
forall x. CognitoOptions -> Rep CognitoOptions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CognitoOptions x -> CognitoOptions
$cfrom :: forall x. CognitoOptions -> Rep CognitoOptions x
Prelude.Generic)

-- |
-- Create a value of 'CognitoOptions' 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:
--
-- 'enabled', 'cognitoOptions_enabled' - Whether to enable or disable Amazon Cognito authentication for
-- OpenSearch Dashboards.
--
-- 'identityPoolId', 'cognitoOptions_identityPoolId' - The Amazon Cognito identity pool ID that you want OpenSearch Service to
-- use for OpenSearch Dashboards authentication.
--
-- 'roleArn', 'cognitoOptions_roleArn' - The @AmazonOpenSearchServiceCognitoAccess@ role that allows OpenSearch
-- Service to configure your user pool and identity pool.
--
-- 'userPoolId', 'cognitoOptions_userPoolId' - The Amazon Cognito user pool ID that you want OpenSearch Service to use
-- for OpenSearch Dashboards authentication.
newCognitoOptions ::
  CognitoOptions
newCognitoOptions :: CognitoOptions
newCognitoOptions =
  CognitoOptions'
    { $sel:enabled:CognitoOptions' :: Maybe Bool
enabled = forall a. Maybe a
Prelude.Nothing,
      $sel:identityPoolId:CognitoOptions' :: Maybe Text
identityPoolId = forall a. Maybe a
Prelude.Nothing,
      $sel:roleArn:CognitoOptions' :: Maybe Text
roleArn = forall a. Maybe a
Prelude.Nothing,
      $sel:userPoolId:CognitoOptions' :: Maybe Text
userPoolId = forall a. Maybe a
Prelude.Nothing
    }

-- | Whether to enable or disable Amazon Cognito authentication for
-- OpenSearch Dashboards.
cognitoOptions_enabled :: Lens.Lens' CognitoOptions (Prelude.Maybe Prelude.Bool)
cognitoOptions_enabled :: Lens' CognitoOptions (Maybe Bool)
cognitoOptions_enabled = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CognitoOptions' {Maybe Bool
enabled :: Maybe Bool
$sel:enabled:CognitoOptions' :: CognitoOptions -> Maybe Bool
enabled} -> Maybe Bool
enabled) (\s :: CognitoOptions
s@CognitoOptions' {} Maybe Bool
a -> CognitoOptions
s {$sel:enabled:CognitoOptions' :: Maybe Bool
enabled = Maybe Bool
a} :: CognitoOptions)

-- | The Amazon Cognito identity pool ID that you want OpenSearch Service to
-- use for OpenSearch Dashboards authentication.
cognitoOptions_identityPoolId :: Lens.Lens' CognitoOptions (Prelude.Maybe Prelude.Text)
cognitoOptions_identityPoolId :: Lens' CognitoOptions (Maybe Text)
cognitoOptions_identityPoolId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CognitoOptions' {Maybe Text
identityPoolId :: Maybe Text
$sel:identityPoolId:CognitoOptions' :: CognitoOptions -> Maybe Text
identityPoolId} -> Maybe Text
identityPoolId) (\s :: CognitoOptions
s@CognitoOptions' {} Maybe Text
a -> CognitoOptions
s {$sel:identityPoolId:CognitoOptions' :: Maybe Text
identityPoolId = Maybe Text
a} :: CognitoOptions)

-- | The @AmazonOpenSearchServiceCognitoAccess@ role that allows OpenSearch
-- Service to configure your user pool and identity pool.
cognitoOptions_roleArn :: Lens.Lens' CognitoOptions (Prelude.Maybe Prelude.Text)
cognitoOptions_roleArn :: Lens' CognitoOptions (Maybe Text)
cognitoOptions_roleArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CognitoOptions' {Maybe Text
roleArn :: Maybe Text
$sel:roleArn:CognitoOptions' :: CognitoOptions -> Maybe Text
roleArn} -> Maybe Text
roleArn) (\s :: CognitoOptions
s@CognitoOptions' {} Maybe Text
a -> CognitoOptions
s {$sel:roleArn:CognitoOptions' :: Maybe Text
roleArn = Maybe Text
a} :: CognitoOptions)

-- | The Amazon Cognito user pool ID that you want OpenSearch Service to use
-- for OpenSearch Dashboards authentication.
cognitoOptions_userPoolId :: Lens.Lens' CognitoOptions (Prelude.Maybe Prelude.Text)
cognitoOptions_userPoolId :: Lens' CognitoOptions (Maybe Text)
cognitoOptions_userPoolId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CognitoOptions' {Maybe Text
userPoolId :: Maybe Text
$sel:userPoolId:CognitoOptions' :: CognitoOptions -> Maybe Text
userPoolId} -> Maybe Text
userPoolId) (\s :: CognitoOptions
s@CognitoOptions' {} Maybe Text
a -> CognitoOptions
s {$sel:userPoolId:CognitoOptions' :: Maybe Text
userPoolId = Maybe Text
a} :: CognitoOptions)

instance Data.FromJSON CognitoOptions where
  parseJSON :: Value -> Parser CognitoOptions
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"CognitoOptions"
      ( \Object
x ->
          Maybe Bool
-> Maybe Text -> Maybe Text -> Maybe Text -> CognitoOptions
CognitoOptions'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Enabled")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"IdentityPoolId")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"RoleArn")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"UserPoolId")
      )

instance Prelude.Hashable CognitoOptions where
  hashWithSalt :: Int -> CognitoOptions -> Int
hashWithSalt Int
_salt CognitoOptions' {Maybe Bool
Maybe Text
userPoolId :: Maybe Text
roleArn :: Maybe Text
identityPoolId :: Maybe Text
enabled :: Maybe Bool
$sel:userPoolId:CognitoOptions' :: CognitoOptions -> Maybe Text
$sel:roleArn:CognitoOptions' :: CognitoOptions -> Maybe Text
$sel:identityPoolId:CognitoOptions' :: CognitoOptions -> Maybe Text
$sel:enabled:CognitoOptions' :: CognitoOptions -> Maybe Bool
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
enabled
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
identityPoolId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
roleArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
userPoolId

instance Prelude.NFData CognitoOptions where
  rnf :: CognitoOptions -> ()
rnf CognitoOptions' {Maybe Bool
Maybe Text
userPoolId :: Maybe Text
roleArn :: Maybe Text
identityPoolId :: Maybe Text
enabled :: Maybe Bool
$sel:userPoolId:CognitoOptions' :: CognitoOptions -> Maybe Text
$sel:roleArn:CognitoOptions' :: CognitoOptions -> Maybe Text
$sel:identityPoolId:CognitoOptions' :: CognitoOptions -> Maybe Text
$sel:enabled:CognitoOptions' :: CognitoOptions -> Maybe Bool
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
enabled
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
identityPoolId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
roleArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
userPoolId

instance Data.ToJSON CognitoOptions where
  toJSON :: CognitoOptions -> Value
toJSON CognitoOptions' {Maybe Bool
Maybe Text
userPoolId :: Maybe Text
roleArn :: Maybe Text
identityPoolId :: Maybe Text
enabled :: Maybe Bool
$sel:userPoolId:CognitoOptions' :: CognitoOptions -> Maybe Text
$sel:roleArn:CognitoOptions' :: CognitoOptions -> Maybe Text
$sel:identityPoolId:CognitoOptions' :: CognitoOptions -> Maybe Text
$sel:enabled:CognitoOptions' :: CognitoOptions -> Maybe Bool
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Enabled" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
enabled,
            (Key
"IdentityPoolId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
identityPoolId,
            (Key
"RoleArn" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
roleArn,
            (Key
"UserPoolId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
userPoolId
          ]
      )