{-# 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.CreateTrustAnchor
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Creates a 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:CreateTrustAnchor@.
module Amazonka.RolesAnywhere.CreateTrustAnchor
  ( -- * Creating a Request
    CreateTrustAnchor (..),
    newCreateTrustAnchor,

    -- * Request Lenses
    createTrustAnchor_enabled,
    createTrustAnchor_tags,
    createTrustAnchor_name,
    createTrustAnchor_source,

    -- * 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:/ 'newCreateTrustAnchor' smart constructor.
data CreateTrustAnchor = CreateTrustAnchor'
  { -- | Specifies whether the trust anchor is enabled.
    CreateTrustAnchor -> Maybe Bool
enabled :: Prelude.Maybe Prelude.Bool,
    -- | The tags to attach to the trust anchor.
    CreateTrustAnchor -> Maybe [Tag]
tags :: Prelude.Maybe [Tag],
    -- | The name of the trust anchor.
    CreateTrustAnchor -> Text
name :: Prelude.Text,
    -- | The trust anchor type and its related certificate data.
    CreateTrustAnchor -> Source
source :: Source
  }
  deriving (CreateTrustAnchor -> CreateTrustAnchor -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateTrustAnchor -> CreateTrustAnchor -> Bool
$c/= :: CreateTrustAnchor -> CreateTrustAnchor -> Bool
== :: CreateTrustAnchor -> CreateTrustAnchor -> Bool
$c== :: CreateTrustAnchor -> CreateTrustAnchor -> Bool
Prelude.Eq, Int -> CreateTrustAnchor -> ShowS
[CreateTrustAnchor] -> ShowS
CreateTrustAnchor -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateTrustAnchor] -> ShowS
$cshowList :: [CreateTrustAnchor] -> ShowS
show :: CreateTrustAnchor -> String
$cshow :: CreateTrustAnchor -> String
showsPrec :: Int -> CreateTrustAnchor -> ShowS
$cshowsPrec :: Int -> CreateTrustAnchor -> ShowS
Prelude.Show, forall x. Rep CreateTrustAnchor x -> CreateTrustAnchor
forall x. CreateTrustAnchor -> Rep CreateTrustAnchor x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateTrustAnchor x -> CreateTrustAnchor
$cfrom :: forall x. CreateTrustAnchor -> Rep CreateTrustAnchor x
Prelude.Generic)

-- |
-- Create a value of 'CreateTrustAnchor' 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:
--
-- 'enabled', 'createTrustAnchor_enabled' - Specifies whether the trust anchor is enabled.
--
-- 'tags', 'createTrustAnchor_tags' - The tags to attach to the trust anchor.
--
-- 'name', 'createTrustAnchor_name' - The name of the trust anchor.
--
-- 'source', 'createTrustAnchor_source' - The trust anchor type and its related certificate data.
newCreateTrustAnchor ::
  -- | 'name'
  Prelude.Text ->
  -- | 'source'
  Source ->
  CreateTrustAnchor
newCreateTrustAnchor :: Text -> Source -> CreateTrustAnchor
newCreateTrustAnchor Text
pName_ Source
pSource_ =
  CreateTrustAnchor'
    { $sel:enabled:CreateTrustAnchor' :: Maybe Bool
enabled = forall a. Maybe a
Prelude.Nothing,
      $sel:tags:CreateTrustAnchor' :: Maybe [Tag]
tags = forall a. Maybe a
Prelude.Nothing,
      $sel:name:CreateTrustAnchor' :: Text
name = Text
pName_,
      $sel:source:CreateTrustAnchor' :: Source
source = Source
pSource_
    }

-- | Specifies whether the trust anchor is enabled.
createTrustAnchor_enabled :: Lens.Lens' CreateTrustAnchor (Prelude.Maybe Prelude.Bool)
createTrustAnchor_enabled :: Lens' CreateTrustAnchor (Maybe Bool)
createTrustAnchor_enabled = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateTrustAnchor' {Maybe Bool
enabled :: Maybe Bool
$sel:enabled:CreateTrustAnchor' :: CreateTrustAnchor -> Maybe Bool
enabled} -> Maybe Bool
enabled) (\s :: CreateTrustAnchor
s@CreateTrustAnchor' {} Maybe Bool
a -> CreateTrustAnchor
s {$sel:enabled:CreateTrustAnchor' :: Maybe Bool
enabled = Maybe Bool
a} :: CreateTrustAnchor)

-- | The tags to attach to the trust anchor.
createTrustAnchor_tags :: Lens.Lens' CreateTrustAnchor (Prelude.Maybe [Tag])
createTrustAnchor_tags :: Lens' CreateTrustAnchor (Maybe [Tag])
createTrustAnchor_tags = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateTrustAnchor' {Maybe [Tag]
tags :: Maybe [Tag]
$sel:tags:CreateTrustAnchor' :: CreateTrustAnchor -> Maybe [Tag]
tags} -> Maybe [Tag]
tags) (\s :: CreateTrustAnchor
s@CreateTrustAnchor' {} Maybe [Tag]
a -> CreateTrustAnchor
s {$sel:tags:CreateTrustAnchor' :: Maybe [Tag]
tags = Maybe [Tag]
a} :: CreateTrustAnchor) 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 s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

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

instance Core.AWSRequest CreateTrustAnchor where
  type
    AWSResponse CreateTrustAnchor =
      TrustAnchorDetailResponse
  request :: (Service -> Service)
-> CreateTrustAnchor -> Request CreateTrustAnchor
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 CreateTrustAnchor
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateTrustAnchor)))
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 CreateTrustAnchor where
  hashWithSalt :: Int -> CreateTrustAnchor -> Int
hashWithSalt Int
_salt CreateTrustAnchor' {Maybe Bool
Maybe [Tag]
Text
Source
source :: Source
name :: Text
tags :: Maybe [Tag]
enabled :: Maybe Bool
$sel:source:CreateTrustAnchor' :: CreateTrustAnchor -> Source
$sel:name:CreateTrustAnchor' :: CreateTrustAnchor -> Text
$sel:tags:CreateTrustAnchor' :: CreateTrustAnchor -> Maybe [Tag]
$sel:enabled:CreateTrustAnchor' :: CreateTrustAnchor -> Maybe Bool
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
enabled
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Tag]
tags
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Source
source

instance Prelude.NFData CreateTrustAnchor where
  rnf :: CreateTrustAnchor -> ()
rnf CreateTrustAnchor' {Maybe Bool
Maybe [Tag]
Text
Source
source :: Source
name :: Text
tags :: Maybe [Tag]
enabled :: Maybe Bool
$sel:source:CreateTrustAnchor' :: CreateTrustAnchor -> Source
$sel:name:CreateTrustAnchor' :: CreateTrustAnchor -> Text
$sel:tags:CreateTrustAnchor' :: CreateTrustAnchor -> Maybe [Tag]
$sel:enabled:CreateTrustAnchor' :: CreateTrustAnchor -> Maybe Bool
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
enabled
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [Tag]
tags
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Source
source

instance Data.ToHeaders CreateTrustAnchor where
  toHeaders :: CreateTrustAnchor -> 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 CreateTrustAnchor where
  toJSON :: CreateTrustAnchor -> Value
toJSON CreateTrustAnchor' {Maybe Bool
Maybe [Tag]
Text
Source
source :: Source
name :: Text
tags :: Maybe [Tag]
enabled :: Maybe Bool
$sel:source:CreateTrustAnchor' :: CreateTrustAnchor -> Source
$sel:name:CreateTrustAnchor' :: CreateTrustAnchor -> Text
$sel:tags:CreateTrustAnchor' :: CreateTrustAnchor -> Maybe [Tag]
$sel:enabled:CreateTrustAnchor' :: CreateTrustAnchor -> Maybe Bool
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"enabled" 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 Bool
enabled,
            (Key
"tags" 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 [Tag]
tags,
            forall a. a -> Maybe a
Prelude.Just (Key
"name" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
name),
            forall a. a -> Maybe a
Prelude.Just (Key
"source" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Source
source)
          ]
      )

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

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