{-# 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.UpdateTrustAnchor
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Updates the trust anchor.You establish trust between IAM Roles Anywhere
-- and your certificate authority (CA) by configuring a trust anchor. A
-- Trust Anchor is defined either as a reference to a AWS Certificate
-- Manager Private Certificate Authority (ACM PCA), or by uploading a
-- Certificate Authority (CA) certificate. Your AWS workloads can
-- authenticate with the trust anchor using certificates issued by the
-- trusted Certificate Authority (CA) in exchange for temporary AWS
-- credentials.
--
-- __Required permissions:__ @rolesanywhere:UpdateTrustAnchor@.
module Amazonka.RolesAnywhere.UpdateTrustAnchor
  ( -- * Creating a Request
    UpdateTrustAnchor (..),
    newUpdateTrustAnchor,

    -- * Request Lenses
    updateTrustAnchor_name,
    updateTrustAnchor_source,
    updateTrustAnchor_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:/ 'newUpdateTrustAnchor' smart constructor.
data UpdateTrustAnchor = UpdateTrustAnchor'
  { -- | The name of the trust anchor.
    UpdateTrustAnchor -> Maybe Text
name :: Prelude.Maybe Prelude.Text,
    -- | The trust anchor type and its related certificate data.
    UpdateTrustAnchor -> Maybe Source
source :: Prelude.Maybe Source,
    -- | The unique identifier of the trust anchor.
    UpdateTrustAnchor -> Text
trustAnchorId :: Prelude.Text
  }
  deriving (UpdateTrustAnchor -> UpdateTrustAnchor -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateTrustAnchor -> UpdateTrustAnchor -> Bool
$c/= :: UpdateTrustAnchor -> UpdateTrustAnchor -> Bool
== :: UpdateTrustAnchor -> UpdateTrustAnchor -> Bool
$c== :: UpdateTrustAnchor -> UpdateTrustAnchor -> Bool
Prelude.Eq, ReadPrec [UpdateTrustAnchor]
ReadPrec UpdateTrustAnchor
Int -> ReadS UpdateTrustAnchor
ReadS [UpdateTrustAnchor]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateTrustAnchor]
$creadListPrec :: ReadPrec [UpdateTrustAnchor]
readPrec :: ReadPrec UpdateTrustAnchor
$creadPrec :: ReadPrec UpdateTrustAnchor
readList :: ReadS [UpdateTrustAnchor]
$creadList :: ReadS [UpdateTrustAnchor]
readsPrec :: Int -> ReadS UpdateTrustAnchor
$creadsPrec :: Int -> ReadS UpdateTrustAnchor
Prelude.Read, Int -> UpdateTrustAnchor -> ShowS
[UpdateTrustAnchor] -> ShowS
UpdateTrustAnchor -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateTrustAnchor] -> ShowS
$cshowList :: [UpdateTrustAnchor] -> ShowS
show :: UpdateTrustAnchor -> String
$cshow :: UpdateTrustAnchor -> String
showsPrec :: Int -> UpdateTrustAnchor -> ShowS
$cshowsPrec :: Int -> UpdateTrustAnchor -> ShowS
Prelude.Show, forall x. Rep UpdateTrustAnchor x -> UpdateTrustAnchor
forall x. UpdateTrustAnchor -> Rep UpdateTrustAnchor x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpdateTrustAnchor x -> UpdateTrustAnchor
$cfrom :: forall x. UpdateTrustAnchor -> Rep UpdateTrustAnchor x
Prelude.Generic)

-- |
-- Create a value of 'UpdateTrustAnchor' 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:
--
-- 'name', 'updateTrustAnchor_name' - The name of the trust anchor.
--
-- 'source', 'updateTrustAnchor_source' - The trust anchor type and its related certificate data.
--
-- 'trustAnchorId', 'updateTrustAnchor_trustAnchorId' - The unique identifier of the trust anchor.
newUpdateTrustAnchor ::
  -- | 'trustAnchorId'
  Prelude.Text ->
  UpdateTrustAnchor
newUpdateTrustAnchor :: Text -> UpdateTrustAnchor
newUpdateTrustAnchor Text
pTrustAnchorId_ =
  UpdateTrustAnchor'
    { $sel:name:UpdateTrustAnchor' :: Maybe Text
name = forall a. Maybe a
Prelude.Nothing,
      $sel:source:UpdateTrustAnchor' :: Maybe Source
source = forall a. Maybe a
Prelude.Nothing,
      $sel:trustAnchorId:UpdateTrustAnchor' :: Text
trustAnchorId = Text
pTrustAnchorId_
    }

-- | The name of the trust anchor.
updateTrustAnchor_name :: Lens.Lens' UpdateTrustAnchor (Prelude.Maybe Prelude.Text)
updateTrustAnchor_name :: Lens' UpdateTrustAnchor (Maybe Text)
updateTrustAnchor_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateTrustAnchor' {Maybe Text
name :: Maybe Text
$sel:name:UpdateTrustAnchor' :: UpdateTrustAnchor -> Maybe Text
name} -> Maybe Text
name) (\s :: UpdateTrustAnchor
s@UpdateTrustAnchor' {} Maybe Text
a -> UpdateTrustAnchor
s {$sel:name:UpdateTrustAnchor' :: Maybe Text
name = Maybe Text
a} :: UpdateTrustAnchor)

-- | The trust anchor type and its related certificate data.
updateTrustAnchor_source :: Lens.Lens' UpdateTrustAnchor (Prelude.Maybe Source)
updateTrustAnchor_source :: Lens' UpdateTrustAnchor (Maybe Source)
updateTrustAnchor_source = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateTrustAnchor' {Maybe Source
source :: Maybe Source
$sel:source:UpdateTrustAnchor' :: UpdateTrustAnchor -> Maybe Source
source} -> Maybe Source
source) (\s :: UpdateTrustAnchor
s@UpdateTrustAnchor' {} Maybe Source
a -> UpdateTrustAnchor
s {$sel:source:UpdateTrustAnchor' :: Maybe Source
source = Maybe Source
a} :: UpdateTrustAnchor)

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

instance Core.AWSRequest UpdateTrustAnchor where
  type
    AWSResponse UpdateTrustAnchor =
      TrustAnchorDetailResponse
  request :: (Service -> Service)
-> UpdateTrustAnchor -> Request UpdateTrustAnchor
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.patchJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy UpdateTrustAnchor
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse UpdateTrustAnchor)))
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 UpdateTrustAnchor where
  hashWithSalt :: Int -> UpdateTrustAnchor -> Int
hashWithSalt Int
_salt UpdateTrustAnchor' {Maybe Text
Maybe Source
Text
trustAnchorId :: Text
source :: Maybe Source
name :: Maybe Text
$sel:trustAnchorId:UpdateTrustAnchor' :: UpdateTrustAnchor -> Text
$sel:source:UpdateTrustAnchor' :: UpdateTrustAnchor -> Maybe Source
$sel:name:UpdateTrustAnchor' :: UpdateTrustAnchor -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Source
source
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
trustAnchorId

instance Prelude.NFData UpdateTrustAnchor where
  rnf :: UpdateTrustAnchor -> ()
rnf UpdateTrustAnchor' {Maybe Text
Maybe Source
Text
trustAnchorId :: Text
source :: Maybe Source
name :: Maybe Text
$sel:trustAnchorId:UpdateTrustAnchor' :: UpdateTrustAnchor -> Text
$sel:source:UpdateTrustAnchor' :: UpdateTrustAnchor -> Maybe Source
$sel:name:UpdateTrustAnchor' :: UpdateTrustAnchor -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Source
source
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
trustAnchorId

instance Data.ToHeaders UpdateTrustAnchor where
  toHeaders :: UpdateTrustAnchor -> 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 UpdateTrustAnchor where
  toJSON :: UpdateTrustAnchor -> Value
toJSON UpdateTrustAnchor' {Maybe Text
Maybe Source
Text
trustAnchorId :: Text
source :: Maybe Source
name :: Maybe Text
$sel:trustAnchorId:UpdateTrustAnchor' :: UpdateTrustAnchor -> Text
$sel:source:UpdateTrustAnchor' :: UpdateTrustAnchor -> Maybe Source
$sel:name:UpdateTrustAnchor' :: UpdateTrustAnchor -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"name" 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
name,
            (Key
"source" 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 Source
source
          ]
      )

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

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