{-# 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.QuickSight.Types.CredentialPair
-- 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.QuickSight.Types.CredentialPair where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.QuickSight.Types.DataSourceParameters

-- | The combination of user name and password that are used as credentials.
--
-- /See:/ 'newCredentialPair' smart constructor.
data CredentialPair = CredentialPair'
  { -- | A set of alternate data source parameters that you want to share for
    -- these credentials. The credentials are applied in tandem with the data
    -- source parameters when you copy a data source by using a create or
    -- update request. The API operation compares the @DataSourceParameters@
    -- structure that\'s in the request with the structures in the
    -- @AlternateDataSourceParameters@ allow list. If the structures are an
    -- exact match, the request is allowed to use the new data source with the
    -- existing credentials. If the @AlternateDataSourceParameters@ list is
    -- null, the @DataSourceParameters@ originally used with these
    -- @Credentials@ is automatically allowed.
    CredentialPair -> Maybe (NonEmpty DataSourceParameters)
alternateDataSourceParameters :: Prelude.Maybe (Prelude.NonEmpty DataSourceParameters),
    -- | User name.
    CredentialPair -> Text
username :: Prelude.Text,
    -- | Password.
    CredentialPair -> Text
password :: Prelude.Text
  }
  deriving (CredentialPair -> CredentialPair -> Bool
(CredentialPair -> CredentialPair -> Bool)
-> (CredentialPair -> CredentialPair -> Bool) -> Eq CredentialPair
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CredentialPair -> CredentialPair -> Bool
$c/= :: CredentialPair -> CredentialPair -> Bool
== :: CredentialPair -> CredentialPair -> Bool
$c== :: CredentialPair -> CredentialPair -> Bool
Prelude.Eq, ReadPrec [CredentialPair]
ReadPrec CredentialPair
Int -> ReadS CredentialPair
ReadS [CredentialPair]
(Int -> ReadS CredentialPair)
-> ReadS [CredentialPair]
-> ReadPrec CredentialPair
-> ReadPrec [CredentialPair]
-> Read CredentialPair
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CredentialPair]
$creadListPrec :: ReadPrec [CredentialPair]
readPrec :: ReadPrec CredentialPair
$creadPrec :: ReadPrec CredentialPair
readList :: ReadS [CredentialPair]
$creadList :: ReadS [CredentialPair]
readsPrec :: Int -> ReadS CredentialPair
$creadsPrec :: Int -> ReadS CredentialPair
Prelude.Read, Int -> CredentialPair -> ShowS
[CredentialPair] -> ShowS
CredentialPair -> String
(Int -> CredentialPair -> ShowS)
-> (CredentialPair -> String)
-> ([CredentialPair] -> ShowS)
-> Show CredentialPair
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CredentialPair] -> ShowS
$cshowList :: [CredentialPair] -> ShowS
show :: CredentialPair -> String
$cshow :: CredentialPair -> String
showsPrec :: Int -> CredentialPair -> ShowS
$cshowsPrec :: Int -> CredentialPair -> ShowS
Prelude.Show, (forall x. CredentialPair -> Rep CredentialPair x)
-> (forall x. Rep CredentialPair x -> CredentialPair)
-> Generic CredentialPair
forall x. Rep CredentialPair x -> CredentialPair
forall x. CredentialPair -> Rep CredentialPair x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CredentialPair x -> CredentialPair
$cfrom :: forall x. CredentialPair -> Rep CredentialPair x
Prelude.Generic)

-- |
-- Create a value of 'CredentialPair' 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:
--
-- 'alternateDataSourceParameters', 'credentialPair_alternateDataSourceParameters' - A set of alternate data source parameters that you want to share for
-- these credentials. The credentials are applied in tandem with the data
-- source parameters when you copy a data source by using a create or
-- update request. The API operation compares the @DataSourceParameters@
-- structure that\'s in the request with the structures in the
-- @AlternateDataSourceParameters@ allow list. If the structures are an
-- exact match, the request is allowed to use the new data source with the
-- existing credentials. If the @AlternateDataSourceParameters@ list is
-- null, the @DataSourceParameters@ originally used with these
-- @Credentials@ is automatically allowed.
--
-- 'username', 'credentialPair_username' - User name.
--
-- 'password', 'credentialPair_password' - Password.
newCredentialPair ::
  -- | 'username'
  Prelude.Text ->
  -- | 'password'
  Prelude.Text ->
  CredentialPair
newCredentialPair :: Text -> Text -> CredentialPair
newCredentialPair Text
pUsername_ Text
pPassword_ =
  CredentialPair' :: Maybe (NonEmpty DataSourceParameters)
-> Text -> Text -> CredentialPair
CredentialPair'
    { $sel:alternateDataSourceParameters:CredentialPair' :: Maybe (NonEmpty DataSourceParameters)
alternateDataSourceParameters =
        Maybe (NonEmpty DataSourceParameters)
forall a. Maybe a
Prelude.Nothing,
      $sel:username:CredentialPair' :: Text
username = Text
pUsername_,
      $sel:password:CredentialPair' :: Text
password = Text
pPassword_
    }

-- | A set of alternate data source parameters that you want to share for
-- these credentials. The credentials are applied in tandem with the data
-- source parameters when you copy a data source by using a create or
-- update request. The API operation compares the @DataSourceParameters@
-- structure that\'s in the request with the structures in the
-- @AlternateDataSourceParameters@ allow list. If the structures are an
-- exact match, the request is allowed to use the new data source with the
-- existing credentials. If the @AlternateDataSourceParameters@ list is
-- null, the @DataSourceParameters@ originally used with these
-- @Credentials@ is automatically allowed.
credentialPair_alternateDataSourceParameters :: Lens.Lens' CredentialPair (Prelude.Maybe (Prelude.NonEmpty DataSourceParameters))
credentialPair_alternateDataSourceParameters :: (Maybe (NonEmpty DataSourceParameters)
 -> f (Maybe (NonEmpty DataSourceParameters)))
-> CredentialPair -> f CredentialPair
credentialPair_alternateDataSourceParameters = (CredentialPair -> Maybe (NonEmpty DataSourceParameters))
-> (CredentialPair
    -> Maybe (NonEmpty DataSourceParameters) -> CredentialPair)
-> Lens
     CredentialPair
     CredentialPair
     (Maybe (NonEmpty DataSourceParameters))
     (Maybe (NonEmpty DataSourceParameters))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CredentialPair' {Maybe (NonEmpty DataSourceParameters)
alternateDataSourceParameters :: Maybe (NonEmpty DataSourceParameters)
$sel:alternateDataSourceParameters:CredentialPair' :: CredentialPair -> Maybe (NonEmpty DataSourceParameters)
alternateDataSourceParameters} -> Maybe (NonEmpty DataSourceParameters)
alternateDataSourceParameters) (\s :: CredentialPair
s@CredentialPair' {} Maybe (NonEmpty DataSourceParameters)
a -> CredentialPair
s {$sel:alternateDataSourceParameters:CredentialPair' :: Maybe (NonEmpty DataSourceParameters)
alternateDataSourceParameters = Maybe (NonEmpty DataSourceParameters)
a} :: CredentialPair) ((Maybe (NonEmpty DataSourceParameters)
  -> f (Maybe (NonEmpty DataSourceParameters)))
 -> CredentialPair -> f CredentialPair)
-> ((Maybe (NonEmpty DataSourceParameters)
     -> f (Maybe (NonEmpty DataSourceParameters)))
    -> Maybe (NonEmpty DataSourceParameters)
    -> f (Maybe (NonEmpty DataSourceParameters)))
-> (Maybe (NonEmpty DataSourceParameters)
    -> f (Maybe (NonEmpty DataSourceParameters)))
-> CredentialPair
-> f CredentialPair
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (NonEmpty DataSourceParameters)
  (NonEmpty DataSourceParameters)
  (NonEmpty DataSourceParameters)
  (NonEmpty DataSourceParameters)
-> Iso
     (Maybe (NonEmpty DataSourceParameters))
     (Maybe (NonEmpty DataSourceParameters))
     (Maybe (NonEmpty DataSourceParameters))
     (Maybe (NonEmpty DataSourceParameters))
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  (NonEmpty DataSourceParameters)
  (NonEmpty DataSourceParameters)
  (NonEmpty DataSourceParameters)
  (NonEmpty DataSourceParameters)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | User name.
credentialPair_username :: Lens.Lens' CredentialPair Prelude.Text
credentialPair_username :: (Text -> f Text) -> CredentialPair -> f CredentialPair
credentialPair_username = (CredentialPair -> Text)
-> (CredentialPair -> Text -> CredentialPair)
-> Lens CredentialPair CredentialPair Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CredentialPair' {Text
username :: Text
$sel:username:CredentialPair' :: CredentialPair -> Text
username} -> Text
username) (\s :: CredentialPair
s@CredentialPair' {} Text
a -> CredentialPair
s {$sel:username:CredentialPair' :: Text
username = Text
a} :: CredentialPair)

-- | Password.
credentialPair_password :: Lens.Lens' CredentialPair Prelude.Text
credentialPair_password :: (Text -> f Text) -> CredentialPair -> f CredentialPair
credentialPair_password = (CredentialPair -> Text)
-> (CredentialPair -> Text -> CredentialPair)
-> Lens CredentialPair CredentialPair Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CredentialPair' {Text
password :: Text
$sel:password:CredentialPair' :: CredentialPair -> Text
password} -> Text
password) (\s :: CredentialPair
s@CredentialPair' {} Text
a -> CredentialPair
s {$sel:password:CredentialPair' :: Text
password = Text
a} :: CredentialPair)

instance Prelude.Hashable CredentialPair

instance Prelude.NFData CredentialPair

instance Core.ToJSON CredentialPair where
  toJSON :: CredentialPair -> Value
toJSON CredentialPair' {Maybe (NonEmpty DataSourceParameters)
Text
password :: Text
username :: Text
alternateDataSourceParameters :: Maybe (NonEmpty DataSourceParameters)
$sel:password:CredentialPair' :: CredentialPair -> Text
$sel:username:CredentialPair' :: CredentialPair -> Text
$sel:alternateDataSourceParameters:CredentialPair' :: CredentialPair -> Maybe (NonEmpty DataSourceParameters)
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"AlternateDataSourceParameters" Text -> NonEmpty DataSourceParameters -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (NonEmpty DataSourceParameters -> Pair)
-> Maybe (NonEmpty DataSourceParameters) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty DataSourceParameters)
alternateDataSourceParameters,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Username" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
username),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Password" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
password)
          ]
      )