{-# 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.IoTSiteWise.Types.Identity
-- 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.IoTSiteWise.Types.Identity where

import qualified Amazonka.Core as Core
import Amazonka.IoTSiteWise.Types.GroupIdentity
import Amazonka.IoTSiteWise.Types.IAMRoleIdentity
import Amazonka.IoTSiteWise.Types.IAMUserIdentity
import Amazonka.IoTSiteWise.Types.UserIdentity
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Contains an identity that can access an IoT SiteWise Monitor resource.
--
-- Currently, you can\'t use Amazon Web Services APIs to retrieve Amazon
-- Web Services SSO identity IDs. You can find the Amazon Web Services SSO
-- identity IDs in the URL of user and group pages in the
-- <https://console.aws.amazon.com/singlesignon Amazon Web Services SSO console>.
--
-- /See:/ 'newIdentity' smart constructor.
data Identity = Identity'
  { -- | An IAM user identity.
    Identity -> Maybe IAMUserIdentity
iamUser :: Prelude.Maybe IAMUserIdentity,
    -- | An Amazon Web Services SSO group identity.
    Identity -> Maybe GroupIdentity
group' :: Prelude.Maybe GroupIdentity,
    -- | An Amazon Web Services SSO user identity.
    Identity -> Maybe UserIdentity
user :: Prelude.Maybe UserIdentity,
    -- | An IAM role identity.
    Identity -> Maybe IAMRoleIdentity
iamRole :: Prelude.Maybe IAMRoleIdentity
  }
  deriving (Identity -> Identity -> Bool
(Identity -> Identity -> Bool)
-> (Identity -> Identity -> Bool) -> Eq Identity
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Identity -> Identity -> Bool
$c/= :: Identity -> Identity -> Bool
== :: Identity -> Identity -> Bool
$c== :: Identity -> Identity -> Bool
Prelude.Eq, ReadPrec [Identity]
ReadPrec Identity
Int -> ReadS Identity
ReadS [Identity]
(Int -> ReadS Identity)
-> ReadS [Identity]
-> ReadPrec Identity
-> ReadPrec [Identity]
-> Read Identity
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Identity]
$creadListPrec :: ReadPrec [Identity]
readPrec :: ReadPrec Identity
$creadPrec :: ReadPrec Identity
readList :: ReadS [Identity]
$creadList :: ReadS [Identity]
readsPrec :: Int -> ReadS Identity
$creadsPrec :: Int -> ReadS Identity
Prelude.Read, Int -> Identity -> ShowS
[Identity] -> ShowS
Identity -> String
(Int -> Identity -> ShowS)
-> (Identity -> String) -> ([Identity] -> ShowS) -> Show Identity
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Identity] -> ShowS
$cshowList :: [Identity] -> ShowS
show :: Identity -> String
$cshow :: Identity -> String
showsPrec :: Int -> Identity -> ShowS
$cshowsPrec :: Int -> Identity -> ShowS
Prelude.Show, (forall x. Identity -> Rep Identity x)
-> (forall x. Rep Identity x -> Identity) -> Generic Identity
forall x. Rep Identity x -> Identity
forall x. Identity -> Rep Identity x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Identity x -> Identity
$cfrom :: forall x. Identity -> Rep Identity x
Prelude.Generic)

-- |
-- Create a value of 'Identity' 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:
--
-- 'iamUser', 'identity_iamUser' - An IAM user identity.
--
-- 'group'', 'identity_group' - An Amazon Web Services SSO group identity.
--
-- 'user', 'identity_user' - An Amazon Web Services SSO user identity.
--
-- 'iamRole', 'identity_iamRole' - An IAM role identity.
newIdentity ::
  Identity
newIdentity :: Identity
newIdentity =
  Identity' :: Maybe IAMUserIdentity
-> Maybe GroupIdentity
-> Maybe UserIdentity
-> Maybe IAMRoleIdentity
-> Identity
Identity'
    { $sel:iamUser:Identity' :: Maybe IAMUserIdentity
iamUser = Maybe IAMUserIdentity
forall a. Maybe a
Prelude.Nothing,
      $sel:group':Identity' :: Maybe GroupIdentity
group' = Maybe GroupIdentity
forall a. Maybe a
Prelude.Nothing,
      $sel:user:Identity' :: Maybe UserIdentity
user = Maybe UserIdentity
forall a. Maybe a
Prelude.Nothing,
      $sel:iamRole:Identity' :: Maybe IAMRoleIdentity
iamRole = Maybe IAMRoleIdentity
forall a. Maybe a
Prelude.Nothing
    }

-- | An IAM user identity.
identity_iamUser :: Lens.Lens' Identity (Prelude.Maybe IAMUserIdentity)
identity_iamUser :: (Maybe IAMUserIdentity -> f (Maybe IAMUserIdentity))
-> Identity -> f Identity
identity_iamUser = (Identity -> Maybe IAMUserIdentity)
-> (Identity -> Maybe IAMUserIdentity -> Identity)
-> Lens
     Identity Identity (Maybe IAMUserIdentity) (Maybe IAMUserIdentity)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Identity' {Maybe IAMUserIdentity
iamUser :: Maybe IAMUserIdentity
$sel:iamUser:Identity' :: Identity -> Maybe IAMUserIdentity
iamUser} -> Maybe IAMUserIdentity
iamUser) (\s :: Identity
s@Identity' {} Maybe IAMUserIdentity
a -> Identity
s {$sel:iamUser:Identity' :: Maybe IAMUserIdentity
iamUser = Maybe IAMUserIdentity
a} :: Identity)

-- | An Amazon Web Services SSO group identity.
identity_group :: Lens.Lens' Identity (Prelude.Maybe GroupIdentity)
identity_group :: (Maybe GroupIdentity -> f (Maybe GroupIdentity))
-> Identity -> f Identity
identity_group = (Identity -> Maybe GroupIdentity)
-> (Identity -> Maybe GroupIdentity -> Identity)
-> Lens
     Identity Identity (Maybe GroupIdentity) (Maybe GroupIdentity)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Identity' {Maybe GroupIdentity
group' :: Maybe GroupIdentity
$sel:group':Identity' :: Identity -> Maybe GroupIdentity
group'} -> Maybe GroupIdentity
group') (\s :: Identity
s@Identity' {} Maybe GroupIdentity
a -> Identity
s {$sel:group':Identity' :: Maybe GroupIdentity
group' = Maybe GroupIdentity
a} :: Identity)

-- | An Amazon Web Services SSO user identity.
identity_user :: Lens.Lens' Identity (Prelude.Maybe UserIdentity)
identity_user :: (Maybe UserIdentity -> f (Maybe UserIdentity))
-> Identity -> f Identity
identity_user = (Identity -> Maybe UserIdentity)
-> (Identity -> Maybe UserIdentity -> Identity)
-> Lens Identity Identity (Maybe UserIdentity) (Maybe UserIdentity)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Identity' {Maybe UserIdentity
user :: Maybe UserIdentity
$sel:user:Identity' :: Identity -> Maybe UserIdentity
user} -> Maybe UserIdentity
user) (\s :: Identity
s@Identity' {} Maybe UserIdentity
a -> Identity
s {$sel:user:Identity' :: Maybe UserIdentity
user = Maybe UserIdentity
a} :: Identity)

-- | An IAM role identity.
identity_iamRole :: Lens.Lens' Identity (Prelude.Maybe IAMRoleIdentity)
identity_iamRole :: (Maybe IAMRoleIdentity -> f (Maybe IAMRoleIdentity))
-> Identity -> f Identity
identity_iamRole = (Identity -> Maybe IAMRoleIdentity)
-> (Identity -> Maybe IAMRoleIdentity -> Identity)
-> Lens
     Identity Identity (Maybe IAMRoleIdentity) (Maybe IAMRoleIdentity)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Identity' {Maybe IAMRoleIdentity
iamRole :: Maybe IAMRoleIdentity
$sel:iamRole:Identity' :: Identity -> Maybe IAMRoleIdentity
iamRole} -> Maybe IAMRoleIdentity
iamRole) (\s :: Identity
s@Identity' {} Maybe IAMRoleIdentity
a -> Identity
s {$sel:iamRole:Identity' :: Maybe IAMRoleIdentity
iamRole = Maybe IAMRoleIdentity
a} :: Identity)

instance Core.FromJSON Identity where
  parseJSON :: Value -> Parser Identity
parseJSON =
    String -> (Object -> Parser Identity) -> Value -> Parser Identity
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Identity"
      ( \Object
x ->
          Maybe IAMUserIdentity
-> Maybe GroupIdentity
-> Maybe UserIdentity
-> Maybe IAMRoleIdentity
-> Identity
Identity'
            (Maybe IAMUserIdentity
 -> Maybe GroupIdentity
 -> Maybe UserIdentity
 -> Maybe IAMRoleIdentity
 -> Identity)
-> Parser (Maybe IAMUserIdentity)
-> Parser
     (Maybe GroupIdentity
      -> Maybe UserIdentity -> Maybe IAMRoleIdentity -> Identity)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe IAMUserIdentity)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"iamUser")
            Parser
  (Maybe GroupIdentity
   -> Maybe UserIdentity -> Maybe IAMRoleIdentity -> Identity)
-> Parser (Maybe GroupIdentity)
-> Parser (Maybe UserIdentity -> Maybe IAMRoleIdentity -> Identity)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe GroupIdentity)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"group")
            Parser (Maybe UserIdentity -> Maybe IAMRoleIdentity -> Identity)
-> Parser (Maybe UserIdentity)
-> Parser (Maybe IAMRoleIdentity -> Identity)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe UserIdentity)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"user")
            Parser (Maybe IAMRoleIdentity -> Identity)
-> Parser (Maybe IAMRoleIdentity) -> Parser Identity
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe IAMRoleIdentity)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"iamRole")
      )

instance Prelude.Hashable Identity

instance Prelude.NFData Identity

instance Core.ToJSON Identity where
  toJSON :: Identity -> Value
toJSON Identity' {Maybe GroupIdentity
Maybe IAMRoleIdentity
Maybe IAMUserIdentity
Maybe UserIdentity
iamRole :: Maybe IAMRoleIdentity
user :: Maybe UserIdentity
group' :: Maybe GroupIdentity
iamUser :: Maybe IAMUserIdentity
$sel:iamRole:Identity' :: Identity -> Maybe IAMRoleIdentity
$sel:user:Identity' :: Identity -> Maybe UserIdentity
$sel:group':Identity' :: Identity -> Maybe GroupIdentity
$sel:iamUser:Identity' :: Identity -> Maybe IAMUserIdentity
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"iamUser" Text -> IAMUserIdentity -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (IAMUserIdentity -> Pair) -> Maybe IAMUserIdentity -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe IAMUserIdentity
iamUser,
            (Text
"group" Text -> GroupIdentity -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (GroupIdentity -> Pair) -> Maybe GroupIdentity -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe GroupIdentity
group',
            (Text
"user" Text -> UserIdentity -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (UserIdentity -> Pair) -> Maybe UserIdentity -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe UserIdentity
user,
            (Text
"iamRole" Text -> IAMRoleIdentity -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (IAMRoleIdentity -> Pair) -> Maybe IAMRoleIdentity -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe IAMRoleIdentity
iamRole
          ]
      )