{-# 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.CloudFront.AssociateAlias
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Associates an alias (also known as a CNAME or an alternate domain name)
-- with a CloudFront distribution.
--
-- With this operation you can move an alias that\'s already in use on a
-- CloudFront distribution to a different distribution in one step. This
-- prevents the downtime that could occur if you first remove the alias
-- from one distribution and then separately add the alias to another
-- distribution.
--
-- To use this operation to associate an alias with a distribution, you
-- provide the alias and the ID of the target distribution for the alias.
-- For more information, including how to set up the target distribution,
-- prerequisites that you must complete, and other restrictions, see
-- <https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/CNAMEs.html#alternate-domain-names-move Moving an alternate domain name to a different distribution>
-- in the /Amazon CloudFront Developer Guide/.
module Amazonka.CloudFront.AssociateAlias
  ( -- * Creating a Request
    AssociateAlias (..),
    newAssociateAlias,

    -- * Request Lenses
    associateAlias_targetDistributionId,
    associateAlias_alias,

    -- * Destructuring the Response
    AssociateAliasResponse (..),
    newAssociateAliasResponse,
  )
where

import Amazonka.CloudFront.Types
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

-- | /See:/ 'newAssociateAlias' smart constructor.
data AssociateAlias = AssociateAlias'
  { -- | The ID of the distribution that you\'re associating the alias with.
    AssociateAlias -> Text
targetDistributionId :: Prelude.Text,
    -- | The alias (also known as a CNAME) to add to the target distribution.
    AssociateAlias -> Text
alias :: Prelude.Text
  }
  deriving (AssociateAlias -> AssociateAlias -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AssociateAlias -> AssociateAlias -> Bool
$c/= :: AssociateAlias -> AssociateAlias -> Bool
== :: AssociateAlias -> AssociateAlias -> Bool
$c== :: AssociateAlias -> AssociateAlias -> Bool
Prelude.Eq, ReadPrec [AssociateAlias]
ReadPrec AssociateAlias
Int -> ReadS AssociateAlias
ReadS [AssociateAlias]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AssociateAlias]
$creadListPrec :: ReadPrec [AssociateAlias]
readPrec :: ReadPrec AssociateAlias
$creadPrec :: ReadPrec AssociateAlias
readList :: ReadS [AssociateAlias]
$creadList :: ReadS [AssociateAlias]
readsPrec :: Int -> ReadS AssociateAlias
$creadsPrec :: Int -> ReadS AssociateAlias
Prelude.Read, Int -> AssociateAlias -> ShowS
[AssociateAlias] -> ShowS
AssociateAlias -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AssociateAlias] -> ShowS
$cshowList :: [AssociateAlias] -> ShowS
show :: AssociateAlias -> String
$cshow :: AssociateAlias -> String
showsPrec :: Int -> AssociateAlias -> ShowS
$cshowsPrec :: Int -> AssociateAlias -> ShowS
Prelude.Show, forall x. Rep AssociateAlias x -> AssociateAlias
forall x. AssociateAlias -> Rep AssociateAlias x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AssociateAlias x -> AssociateAlias
$cfrom :: forall x. AssociateAlias -> Rep AssociateAlias x
Prelude.Generic)

-- |
-- Create a value of 'AssociateAlias' 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:
--
-- 'targetDistributionId', 'associateAlias_targetDistributionId' - The ID of the distribution that you\'re associating the alias with.
--
-- 'alias', 'associateAlias_alias' - The alias (also known as a CNAME) to add to the target distribution.
newAssociateAlias ::
  -- | 'targetDistributionId'
  Prelude.Text ->
  -- | 'alias'
  Prelude.Text ->
  AssociateAlias
newAssociateAlias :: Text -> Text -> AssociateAlias
newAssociateAlias Text
pTargetDistributionId_ Text
pAlias_ =
  AssociateAlias'
    { $sel:targetDistributionId:AssociateAlias' :: Text
targetDistributionId =
        Text
pTargetDistributionId_,
      $sel:alias:AssociateAlias' :: Text
alias = Text
pAlias_
    }

-- | The ID of the distribution that you\'re associating the alias with.
associateAlias_targetDistributionId :: Lens.Lens' AssociateAlias Prelude.Text
associateAlias_targetDistributionId :: Lens' AssociateAlias Text
associateAlias_targetDistributionId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateAlias' {Text
targetDistributionId :: Text
$sel:targetDistributionId:AssociateAlias' :: AssociateAlias -> Text
targetDistributionId} -> Text
targetDistributionId) (\s :: AssociateAlias
s@AssociateAlias' {} Text
a -> AssociateAlias
s {$sel:targetDistributionId:AssociateAlias' :: Text
targetDistributionId = Text
a} :: AssociateAlias)

-- | The alias (also known as a CNAME) to add to the target distribution.
associateAlias_alias :: Lens.Lens' AssociateAlias Prelude.Text
associateAlias_alias :: Lens' AssociateAlias Text
associateAlias_alias = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateAlias' {Text
alias :: Text
$sel:alias:AssociateAlias' :: AssociateAlias -> Text
alias} -> Text
alias) (\s :: AssociateAlias
s@AssociateAlias' {} Text
a -> AssociateAlias
s {$sel:alias:AssociateAlias' :: Text
alias = Text
a} :: AssociateAlias)

instance Core.AWSRequest AssociateAlias where
  type
    AWSResponse AssociateAlias =
      AssociateAliasResponse
  request :: (Service -> Service) -> AssociateAlias -> Request AssociateAlias
request Service -> Service
overrides =
    forall a. ToRequest a => Service -> a -> Request a
Request.put (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy AssociateAlias
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse AssociateAlias)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull AssociateAliasResponse
AssociateAliasResponse'

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

instance Prelude.NFData AssociateAlias where
  rnf :: AssociateAlias -> ()
rnf AssociateAlias' {Text
alias :: Text
targetDistributionId :: Text
$sel:alias:AssociateAlias' :: AssociateAlias -> Text
$sel:targetDistributionId:AssociateAlias' :: AssociateAlias -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
targetDistributionId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
alias

instance Data.ToHeaders AssociateAlias where
  toHeaders :: AssociateAlias -> [Header]
toHeaders = forall a b. a -> b -> a
Prelude.const forall a. Monoid a => a
Prelude.mempty

instance Data.ToPath AssociateAlias where
  toPath :: AssociateAlias -> ByteString
toPath AssociateAlias' {Text
alias :: Text
targetDistributionId :: Text
$sel:alias:AssociateAlias' :: AssociateAlias -> Text
$sel:targetDistributionId:AssociateAlias' :: AssociateAlias -> Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/2020-05-31/distribution/",
        forall a. ToByteString a => a -> ByteString
Data.toBS Text
targetDistributionId,
        ByteString
"/associate-alias"
      ]

instance Data.ToQuery AssociateAlias where
  toQuery :: AssociateAlias -> QueryString
toQuery AssociateAlias' {Text
alias :: Text
targetDistributionId :: Text
$sel:alias:AssociateAlias' :: AssociateAlias -> Text
$sel:targetDistributionId:AssociateAlias' :: AssociateAlias -> Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat [ByteString
"Alias" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Text
alias]

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

-- |
-- Create a value of 'AssociateAliasResponse' 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.
newAssociateAliasResponse ::
  AssociateAliasResponse
newAssociateAliasResponse :: AssociateAliasResponse
newAssociateAliasResponse = AssociateAliasResponse
AssociateAliasResponse'

instance Prelude.NFData AssociateAliasResponse where
  rnf :: AssociateAliasResponse -> ()
rnf AssociateAliasResponse
_ = ()