{-# 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-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- 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.Lens as Lens
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
(AssociateAlias -> AssociateAlias -> Bool)
-> (AssociateAlias -> AssociateAlias -> Bool) -> Eq AssociateAlias
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]
(Int -> ReadS AssociateAlias)
-> ReadS [AssociateAlias]
-> ReadPrec AssociateAlias
-> ReadPrec [AssociateAlias]
-> Read 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
(Int -> AssociateAlias -> ShowS)
-> (AssociateAlias -> String)
-> ([AssociateAlias] -> ShowS)
-> Show AssociateAlias
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. AssociateAlias -> Rep AssociateAlias x)
-> (forall x. Rep AssociateAlias x -> AssociateAlias)
-> Generic AssociateAlias
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' :: Text -> Text -> AssociateAlias
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 :: (Text -> f Text) -> AssociateAlias -> f AssociateAlias
associateAlias_targetDistributionId = (AssociateAlias -> Text)
-> (AssociateAlias -> Text -> AssociateAlias)
-> Lens AssociateAlias AssociateAlias Text Text
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 :: (Text -> f Text) -> AssociateAlias -> f AssociateAlias
associateAlias_alias = (AssociateAlias -> Text)
-> (AssociateAlias -> Text -> AssociateAlias)
-> Lens AssociateAlias AssociateAlias Text Text
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 :: AssociateAlias -> Request AssociateAlias
request = Service -> AssociateAlias -> Request AssociateAlias
forall a. ToRequest a => Service -> a -> Request a
Request.put Service
defaultService
  response :: Logger
-> Service
-> Proxy AssociateAlias
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse AssociateAlias)))
response =
    AWSResponse AssociateAlias
-> Logger
-> Service
-> Proxy AssociateAlias
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse AssociateAlias)))
forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull AWSResponse AssociateAlias
AssociateAliasResponse
AssociateAliasResponse'

instance Prelude.Hashable AssociateAlias

instance Prelude.NFData AssociateAlias

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

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

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

-- | /See:/ 'newAssociateAliasResponse' smart constructor.
data AssociateAliasResponse = AssociateAliasResponse'
  {
  }
  deriving (AssociateAliasResponse -> AssociateAliasResponse -> Bool
(AssociateAliasResponse -> AssociateAliasResponse -> Bool)
-> (AssociateAliasResponse -> AssociateAliasResponse -> Bool)
-> Eq AssociateAliasResponse
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]
(Int -> ReadS AssociateAliasResponse)
-> ReadS [AssociateAliasResponse]
-> ReadPrec AssociateAliasResponse
-> ReadPrec [AssociateAliasResponse]
-> Read 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
(Int -> AssociateAliasResponse -> ShowS)
-> (AssociateAliasResponse -> String)
-> ([AssociateAliasResponse] -> ShowS)
-> Show AssociateAliasResponse
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. AssociateAliasResponse -> Rep AssociateAliasResponse x)
-> (forall x.
    Rep AssociateAliasResponse x -> AssociateAliasResponse)
-> Generic AssociateAliasResponse
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