{-# 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.RolesAnywhere.EnableTrustAnchor
-- 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 a trust anchor. When enabled, certificates in the trust anchor
-- chain are authorized for trust validation.
--
-- __Required permissions:__ @rolesanywhere:EnableTrustAnchor@.
module Amazonka.RolesAnywhere.EnableTrustAnchor
  ( -- * Creating a Request
    EnableTrustAnchor (..),
    newEnableTrustAnchor,

    -- * Request Lenses
    enableTrustAnchor_trustAnchorId,

    -- * Destructuring the Response
    TrustAnchorDetailResponse (..),
    newTrustAnchorDetailResponse,

    -- * Response Lenses
    trustAnchorDetailResponse_trustAnchor,
  )
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
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response
import Amazonka.RolesAnywhere.Types

-- | /See:/ 'newEnableTrustAnchor' smart constructor.
data EnableTrustAnchor = EnableTrustAnchor'
  { -- | The unique identifier of the trust anchor.
    EnableTrustAnchor -> Text
trustAnchorId :: Prelude.Text
  }
  deriving (EnableTrustAnchor -> EnableTrustAnchor -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EnableTrustAnchor -> EnableTrustAnchor -> Bool
$c/= :: EnableTrustAnchor -> EnableTrustAnchor -> Bool
== :: EnableTrustAnchor -> EnableTrustAnchor -> Bool
$c== :: EnableTrustAnchor -> EnableTrustAnchor -> Bool
Prelude.Eq, ReadPrec [EnableTrustAnchor]
ReadPrec EnableTrustAnchor
Int -> ReadS EnableTrustAnchor
ReadS [EnableTrustAnchor]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [EnableTrustAnchor]
$creadListPrec :: ReadPrec [EnableTrustAnchor]
readPrec :: ReadPrec EnableTrustAnchor
$creadPrec :: ReadPrec EnableTrustAnchor
readList :: ReadS [EnableTrustAnchor]
$creadList :: ReadS [EnableTrustAnchor]
readsPrec :: Int -> ReadS EnableTrustAnchor
$creadsPrec :: Int -> ReadS EnableTrustAnchor
Prelude.Read, Int -> EnableTrustAnchor -> ShowS
[EnableTrustAnchor] -> ShowS
EnableTrustAnchor -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EnableTrustAnchor] -> ShowS
$cshowList :: [EnableTrustAnchor] -> ShowS
show :: EnableTrustAnchor -> String
$cshow :: EnableTrustAnchor -> String
showsPrec :: Int -> EnableTrustAnchor -> ShowS
$cshowsPrec :: Int -> EnableTrustAnchor -> ShowS
Prelude.Show, forall x. Rep EnableTrustAnchor x -> EnableTrustAnchor
forall x. EnableTrustAnchor -> Rep EnableTrustAnchor x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep EnableTrustAnchor x -> EnableTrustAnchor
$cfrom :: forall x. EnableTrustAnchor -> Rep EnableTrustAnchor x
Prelude.Generic)

-- |
-- Create a value of 'EnableTrustAnchor' 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:
--
-- 'trustAnchorId', 'enableTrustAnchor_trustAnchorId' - The unique identifier of the trust anchor.
newEnableTrustAnchor ::
  -- | 'trustAnchorId'
  Prelude.Text ->
  EnableTrustAnchor
newEnableTrustAnchor :: Text -> EnableTrustAnchor
newEnableTrustAnchor Text
pTrustAnchorId_ =
  EnableTrustAnchor' {$sel:trustAnchorId:EnableTrustAnchor' :: Text
trustAnchorId = Text
pTrustAnchorId_}

-- | The unique identifier of the trust anchor.
enableTrustAnchor_trustAnchorId :: Lens.Lens' EnableTrustAnchor Prelude.Text
enableTrustAnchor_trustAnchorId :: Lens' EnableTrustAnchor Text
enableTrustAnchor_trustAnchorId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EnableTrustAnchor' {Text
trustAnchorId :: Text
$sel:trustAnchorId:EnableTrustAnchor' :: EnableTrustAnchor -> Text
trustAnchorId} -> Text
trustAnchorId) (\s :: EnableTrustAnchor
s@EnableTrustAnchor' {} Text
a -> EnableTrustAnchor
s {$sel:trustAnchorId:EnableTrustAnchor' :: Text
trustAnchorId = Text
a} :: EnableTrustAnchor)

instance Core.AWSRequest EnableTrustAnchor where
  type
    AWSResponse EnableTrustAnchor =
      TrustAnchorDetailResponse
  request :: (Service -> Service)
-> EnableTrustAnchor -> Request EnableTrustAnchor
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 EnableTrustAnchor
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse EnableTrustAnchor)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      (\Int
s ResponseHeaders
h Object
x -> forall a. FromJSON a => Object -> Either String a
Data.eitherParseJSON Object
x)

instance Prelude.Hashable EnableTrustAnchor where
  hashWithSalt :: Int -> EnableTrustAnchor -> Int
hashWithSalt Int
_salt EnableTrustAnchor' {Text
trustAnchorId :: Text
$sel:trustAnchorId:EnableTrustAnchor' :: EnableTrustAnchor -> Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
trustAnchorId

instance Prelude.NFData EnableTrustAnchor where
  rnf :: EnableTrustAnchor -> ()
rnf EnableTrustAnchor' {Text
trustAnchorId :: Text
$sel:trustAnchorId:EnableTrustAnchor' :: EnableTrustAnchor -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
trustAnchorId

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

instance Data.ToJSON EnableTrustAnchor where
  toJSON :: EnableTrustAnchor -> Value
toJSON = forall a b. a -> b -> a
Prelude.const (Object -> Value
Data.Object forall a. Monoid a => a
Prelude.mempty)

instance Data.ToPath EnableTrustAnchor where
  toPath :: EnableTrustAnchor -> ByteString
toPath EnableTrustAnchor' {Text
trustAnchorId :: Text
$sel:trustAnchorId:EnableTrustAnchor' :: EnableTrustAnchor -> Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/trustanchor/", forall a. ToByteString a => a -> ByteString
Data.toBS Text
trustAnchorId, ByteString
"/enable"]

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