{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.DirectoryService.EnableSso
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Enables single sign-on for a directory. Single sign-on allows users in
-- your directory to access certain Amazon Web Services services from a
-- computer joined to the directory without having to enter their
-- credentials separately.
module Amazonka.DirectoryService.EnableSso
  ( -- * Creating a Request
    EnableSso (..),
    newEnableSso,

    -- * Request Lenses
    enableSso_password,
    enableSso_userName,
    enableSso_directoryId,

    -- * Destructuring the Response
    EnableSsoResponse (..),
    newEnableSsoResponse,

    -- * Response Lenses
    enableSsoResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.DirectoryService.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | Contains the inputs for the EnableSso operation.
--
-- /See:/ 'newEnableSso' smart constructor.
data EnableSso = EnableSso'
  { -- | The password of an alternate account to use to enable single-sign on.
    -- This is only used for AD Connector directories. For more information,
    -- see the /UserName/ parameter.
    EnableSso -> Maybe (Sensitive Text)
password :: Prelude.Maybe (Data.Sensitive Prelude.Text),
    -- | The username of an alternate account to use to enable single-sign on.
    -- This is only used for AD Connector directories. This account must have
    -- privileges to add a service principal name.
    --
    -- If the AD Connector service account does not have privileges to add a
    -- service principal name, you can specify an alternate account with the
    -- /UserName/ and /Password/ parameters. These credentials are only used to
    -- enable single sign-on and are not stored by the service. The AD
    -- Connector service account is not changed.
    EnableSso -> Maybe Text
userName :: Prelude.Maybe Prelude.Text,
    -- | The identifier of the directory for which to enable single-sign on.
    EnableSso -> Text
directoryId :: Prelude.Text
  }
  deriving (EnableSso -> EnableSso -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EnableSso -> EnableSso -> Bool
$c/= :: EnableSso -> EnableSso -> Bool
== :: EnableSso -> EnableSso -> Bool
$c== :: EnableSso -> EnableSso -> Bool
Prelude.Eq, Int -> EnableSso -> ShowS
[EnableSso] -> ShowS
EnableSso -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EnableSso] -> ShowS
$cshowList :: [EnableSso] -> ShowS
show :: EnableSso -> String
$cshow :: EnableSso -> String
showsPrec :: Int -> EnableSso -> ShowS
$cshowsPrec :: Int -> EnableSso -> ShowS
Prelude.Show, forall x. Rep EnableSso x -> EnableSso
forall x. EnableSso -> Rep EnableSso x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep EnableSso x -> EnableSso
$cfrom :: forall x. EnableSso -> Rep EnableSso x
Prelude.Generic)

-- |
-- Create a value of 'EnableSso' 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:
--
-- 'password', 'enableSso_password' - The password of an alternate account to use to enable single-sign on.
-- This is only used for AD Connector directories. For more information,
-- see the /UserName/ parameter.
--
-- 'userName', 'enableSso_userName' - The username of an alternate account to use to enable single-sign on.
-- This is only used for AD Connector directories. This account must have
-- privileges to add a service principal name.
--
-- If the AD Connector service account does not have privileges to add a
-- service principal name, you can specify an alternate account with the
-- /UserName/ and /Password/ parameters. These credentials are only used to
-- enable single sign-on and are not stored by the service. The AD
-- Connector service account is not changed.
--
-- 'directoryId', 'enableSso_directoryId' - The identifier of the directory for which to enable single-sign on.
newEnableSso ::
  -- | 'directoryId'
  Prelude.Text ->
  EnableSso
newEnableSso :: Text -> EnableSso
newEnableSso Text
pDirectoryId_ =
  EnableSso'
    { $sel:password:EnableSso' :: Maybe (Sensitive Text)
password = forall a. Maybe a
Prelude.Nothing,
      $sel:userName:EnableSso' :: Maybe Text
userName = forall a. Maybe a
Prelude.Nothing,
      $sel:directoryId:EnableSso' :: Text
directoryId = Text
pDirectoryId_
    }

-- | The password of an alternate account to use to enable single-sign on.
-- This is only used for AD Connector directories. For more information,
-- see the /UserName/ parameter.
enableSso_password :: Lens.Lens' EnableSso (Prelude.Maybe Prelude.Text)
enableSso_password :: Lens' EnableSso (Maybe Text)
enableSso_password = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EnableSso' {Maybe (Sensitive Text)
password :: Maybe (Sensitive Text)
$sel:password:EnableSso' :: EnableSso -> Maybe (Sensitive Text)
password} -> Maybe (Sensitive Text)
password) (\s :: EnableSso
s@EnableSso' {} Maybe (Sensitive Text)
a -> EnableSso
s {$sel:password:EnableSso' :: Maybe (Sensitive Text)
password = Maybe (Sensitive Text)
a} :: EnableSso) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall a. Iso' (Sensitive a) a
Data._Sensitive

-- | The username of an alternate account to use to enable single-sign on.
-- This is only used for AD Connector directories. This account must have
-- privileges to add a service principal name.
--
-- If the AD Connector service account does not have privileges to add a
-- service principal name, you can specify an alternate account with the
-- /UserName/ and /Password/ parameters. These credentials are only used to
-- enable single sign-on and are not stored by the service. The AD
-- Connector service account is not changed.
enableSso_userName :: Lens.Lens' EnableSso (Prelude.Maybe Prelude.Text)
enableSso_userName :: Lens' EnableSso (Maybe Text)
enableSso_userName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EnableSso' {Maybe Text
userName :: Maybe Text
$sel:userName:EnableSso' :: EnableSso -> Maybe Text
userName} -> Maybe Text
userName) (\s :: EnableSso
s@EnableSso' {} Maybe Text
a -> EnableSso
s {$sel:userName:EnableSso' :: Maybe Text
userName = Maybe Text
a} :: EnableSso)

-- | The identifier of the directory for which to enable single-sign on.
enableSso_directoryId :: Lens.Lens' EnableSso Prelude.Text
enableSso_directoryId :: Lens' EnableSso Text
enableSso_directoryId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EnableSso' {Text
directoryId :: Text
$sel:directoryId:EnableSso' :: EnableSso -> Text
directoryId} -> Text
directoryId) (\s :: EnableSso
s@EnableSso' {} Text
a -> EnableSso
s {$sel:directoryId:EnableSso' :: Text
directoryId = Text
a} :: EnableSso)

instance Core.AWSRequest EnableSso where
  type AWSResponse EnableSso = EnableSsoResponse
  request :: (Service -> Service) -> EnableSso -> Request EnableSso
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy EnableSso
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse EnableSso)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> EnableSsoResponse
EnableSsoResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable EnableSso where
  hashWithSalt :: Int -> EnableSso -> Int
hashWithSalt Int
_salt EnableSso' {Maybe Text
Maybe (Sensitive Text)
Text
directoryId :: Text
userName :: Maybe Text
password :: Maybe (Sensitive Text)
$sel:directoryId:EnableSso' :: EnableSso -> Text
$sel:userName:EnableSso' :: EnableSso -> Maybe Text
$sel:password:EnableSso' :: EnableSso -> Maybe (Sensitive Text)
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (Sensitive Text)
password
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
userName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
directoryId

instance Prelude.NFData EnableSso where
  rnf :: EnableSso -> ()
rnf EnableSso' {Maybe Text
Maybe (Sensitive Text)
Text
directoryId :: Text
userName :: Maybe Text
password :: Maybe (Sensitive Text)
$sel:directoryId:EnableSso' :: EnableSso -> Text
$sel:userName:EnableSso' :: EnableSso -> Maybe Text
$sel:password:EnableSso' :: EnableSso -> Maybe (Sensitive Text)
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (Sensitive Text)
password
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
userName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
directoryId

instance Data.ToHeaders EnableSso where
  toHeaders :: EnableSso -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"DirectoryService_20150416.EnableSso" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON EnableSso where
  toJSON :: EnableSso -> Value
toJSON EnableSso' {Maybe Text
Maybe (Sensitive Text)
Text
directoryId :: Text
userName :: Maybe Text
password :: Maybe (Sensitive Text)
$sel:directoryId:EnableSso' :: EnableSso -> Text
$sel:userName:EnableSso' :: EnableSso -> Maybe Text
$sel:password:EnableSso' :: EnableSso -> Maybe (Sensitive Text)
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Password" 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 (Sensitive Text)
password,
            (Key
"UserName" 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
userName,
            forall a. a -> Maybe a
Prelude.Just (Key
"DirectoryId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
directoryId)
          ]
      )

instance Data.ToPath EnableSso where
  toPath :: EnableSso -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Data.ToQuery EnableSso where
  toQuery :: EnableSso -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const forall a. Monoid a => a
Prelude.mempty

-- | Contains the results of the EnableSso operation.
--
-- /See:/ 'newEnableSsoResponse' smart constructor.
data EnableSsoResponse = EnableSsoResponse'
  { -- | The response's http status code.
    EnableSsoResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (EnableSsoResponse -> EnableSsoResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EnableSsoResponse -> EnableSsoResponse -> Bool
$c/= :: EnableSsoResponse -> EnableSsoResponse -> Bool
== :: EnableSsoResponse -> EnableSsoResponse -> Bool
$c== :: EnableSsoResponse -> EnableSsoResponse -> Bool
Prelude.Eq, ReadPrec [EnableSsoResponse]
ReadPrec EnableSsoResponse
Int -> ReadS EnableSsoResponse
ReadS [EnableSsoResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [EnableSsoResponse]
$creadListPrec :: ReadPrec [EnableSsoResponse]
readPrec :: ReadPrec EnableSsoResponse
$creadPrec :: ReadPrec EnableSsoResponse
readList :: ReadS [EnableSsoResponse]
$creadList :: ReadS [EnableSsoResponse]
readsPrec :: Int -> ReadS EnableSsoResponse
$creadsPrec :: Int -> ReadS EnableSsoResponse
Prelude.Read, Int -> EnableSsoResponse -> ShowS
[EnableSsoResponse] -> ShowS
EnableSsoResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EnableSsoResponse] -> ShowS
$cshowList :: [EnableSsoResponse] -> ShowS
show :: EnableSsoResponse -> String
$cshow :: EnableSsoResponse -> String
showsPrec :: Int -> EnableSsoResponse -> ShowS
$cshowsPrec :: Int -> EnableSsoResponse -> ShowS
Prelude.Show, forall x. Rep EnableSsoResponse x -> EnableSsoResponse
forall x. EnableSsoResponse -> Rep EnableSsoResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep EnableSsoResponse x -> EnableSsoResponse
$cfrom :: forall x. EnableSsoResponse -> Rep EnableSsoResponse x
Prelude.Generic)

-- |
-- Create a value of 'EnableSsoResponse' 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:
--
-- 'httpStatus', 'enableSsoResponse_httpStatus' - The response's http status code.
newEnableSsoResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  EnableSsoResponse
newEnableSsoResponse :: Int -> EnableSsoResponse
newEnableSsoResponse Int
pHttpStatus_ =
  EnableSsoResponse' {$sel:httpStatus:EnableSsoResponse' :: Int
httpStatus = Int
pHttpStatus_}

-- | The response's http status code.
enableSsoResponse_httpStatus :: Lens.Lens' EnableSsoResponse Prelude.Int
enableSsoResponse_httpStatus :: Lens' EnableSsoResponse Int
enableSsoResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EnableSsoResponse' {Int
httpStatus :: Int
$sel:httpStatus:EnableSsoResponse' :: EnableSsoResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: EnableSsoResponse
s@EnableSsoResponse' {} Int
a -> EnableSsoResponse
s {$sel:httpStatus:EnableSsoResponse' :: Int
httpStatus = Int
a} :: EnableSsoResponse)

instance Prelude.NFData EnableSsoResponse where
  rnf :: EnableSsoResponse -> ()
rnf EnableSsoResponse' {Int
httpStatus :: Int
$sel:httpStatus:EnableSsoResponse' :: EnableSsoResponse -> Int
..} = forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus