{-# 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.GetDistributionConfig
-- 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)
--
-- Get the configuration information about a distribution.
module Amazonka.CloudFront.GetDistributionConfig
  ( -- * Creating a Request
    GetDistributionConfig (..),
    newGetDistributionConfig,

    -- * Request Lenses
    getDistributionConfig_id,

    -- * Destructuring the Response
    GetDistributionConfigResponse (..),
    newGetDistributionConfigResponse,

    -- * Response Lenses
    getDistributionConfigResponse_eTag,
    getDistributionConfigResponse_distributionConfig,
    getDistributionConfigResponse_httpStatus,
  )
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

-- | The request to get a distribution configuration.
--
-- /See:/ 'newGetDistributionConfig' smart constructor.
data GetDistributionConfig = GetDistributionConfig'
  { -- | The distribution\'s ID. If the ID is empty, an empty distribution
    -- configuration is returned.
    GetDistributionConfig -> Text
id :: Prelude.Text
  }
  deriving (GetDistributionConfig -> GetDistributionConfig -> Bool
(GetDistributionConfig -> GetDistributionConfig -> Bool)
-> (GetDistributionConfig -> GetDistributionConfig -> Bool)
-> Eq GetDistributionConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetDistributionConfig -> GetDistributionConfig -> Bool
$c/= :: GetDistributionConfig -> GetDistributionConfig -> Bool
== :: GetDistributionConfig -> GetDistributionConfig -> Bool
$c== :: GetDistributionConfig -> GetDistributionConfig -> Bool
Prelude.Eq, ReadPrec [GetDistributionConfig]
ReadPrec GetDistributionConfig
Int -> ReadS GetDistributionConfig
ReadS [GetDistributionConfig]
(Int -> ReadS GetDistributionConfig)
-> ReadS [GetDistributionConfig]
-> ReadPrec GetDistributionConfig
-> ReadPrec [GetDistributionConfig]
-> Read GetDistributionConfig
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetDistributionConfig]
$creadListPrec :: ReadPrec [GetDistributionConfig]
readPrec :: ReadPrec GetDistributionConfig
$creadPrec :: ReadPrec GetDistributionConfig
readList :: ReadS [GetDistributionConfig]
$creadList :: ReadS [GetDistributionConfig]
readsPrec :: Int -> ReadS GetDistributionConfig
$creadsPrec :: Int -> ReadS GetDistributionConfig
Prelude.Read, Int -> GetDistributionConfig -> ShowS
[GetDistributionConfig] -> ShowS
GetDistributionConfig -> String
(Int -> GetDistributionConfig -> ShowS)
-> (GetDistributionConfig -> String)
-> ([GetDistributionConfig] -> ShowS)
-> Show GetDistributionConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetDistributionConfig] -> ShowS
$cshowList :: [GetDistributionConfig] -> ShowS
show :: GetDistributionConfig -> String
$cshow :: GetDistributionConfig -> String
showsPrec :: Int -> GetDistributionConfig -> ShowS
$cshowsPrec :: Int -> GetDistributionConfig -> ShowS
Prelude.Show, (forall x. GetDistributionConfig -> Rep GetDistributionConfig x)
-> (forall x. Rep GetDistributionConfig x -> GetDistributionConfig)
-> Generic GetDistributionConfig
forall x. Rep GetDistributionConfig x -> GetDistributionConfig
forall x. GetDistributionConfig -> Rep GetDistributionConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetDistributionConfig x -> GetDistributionConfig
$cfrom :: forall x. GetDistributionConfig -> Rep GetDistributionConfig x
Prelude.Generic)

-- |
-- Create a value of 'GetDistributionConfig' 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:
--
-- 'id', 'getDistributionConfig_id' - The distribution\'s ID. If the ID is empty, an empty distribution
-- configuration is returned.
newGetDistributionConfig ::
  -- | 'id'
  Prelude.Text ->
  GetDistributionConfig
newGetDistributionConfig :: Text -> GetDistributionConfig
newGetDistributionConfig Text
pId_ =
  GetDistributionConfig' :: Text -> GetDistributionConfig
GetDistributionConfig' {$sel:id:GetDistributionConfig' :: Text
id = Text
pId_}

-- | The distribution\'s ID. If the ID is empty, an empty distribution
-- configuration is returned.
getDistributionConfig_id :: Lens.Lens' GetDistributionConfig Prelude.Text
getDistributionConfig_id :: (Text -> f Text)
-> GetDistributionConfig -> f GetDistributionConfig
getDistributionConfig_id = (GetDistributionConfig -> Text)
-> (GetDistributionConfig -> Text -> GetDistributionConfig)
-> Lens GetDistributionConfig GetDistributionConfig Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetDistributionConfig' {Text
id :: Text
$sel:id:GetDistributionConfig' :: GetDistributionConfig -> Text
id} -> Text
id) (\s :: GetDistributionConfig
s@GetDistributionConfig' {} Text
a -> GetDistributionConfig
s {$sel:id:GetDistributionConfig' :: Text
id = Text
a} :: GetDistributionConfig)

instance Core.AWSRequest GetDistributionConfig where
  type
    AWSResponse GetDistributionConfig =
      GetDistributionConfigResponse
  request :: GetDistributionConfig -> Request GetDistributionConfig
request = Service -> GetDistributionConfig -> Request GetDistributionConfig
forall a. ToRequest a => Service -> a -> Request a
Request.get Service
defaultService
  response :: Logger
-> Service
-> Proxy GetDistributionConfig
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetDistributionConfig)))
response =
    (Int
 -> ResponseHeaders
 -> [Node]
 -> Either String (AWSResponse GetDistributionConfig))
-> Logger
-> Service
-> Proxy GetDistributionConfig
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetDistributionConfig)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> [Node] -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveXML
      ( \Int
s ResponseHeaders
h [Node]
x ->
          Maybe Text
-> Maybe DistributionConfig -> Int -> GetDistributionConfigResponse
GetDistributionConfigResponse'
            (Maybe Text
 -> Maybe DistributionConfig
 -> Int
 -> GetDistributionConfigResponse)
-> Either String (Maybe Text)
-> Either
     String
     (Maybe DistributionConfig -> Int -> GetDistributionConfigResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (ResponseHeaders
h ResponseHeaders -> HeaderName -> Either String (Maybe Text)
forall a.
FromText a =>
ResponseHeaders -> HeaderName -> Either String (Maybe a)
Core..#? HeaderName
"ETag")
            Either
  String
  (Maybe DistributionConfig -> Int -> GetDistributionConfigResponse)
-> Either String (Maybe DistributionConfig)
-> Either String (Int -> GetDistributionConfigResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node] -> Either String (Maybe DistributionConfig)
forall a. FromXML a => [Node] -> Either String a
Core.parseXML [Node]
x)
            Either String (Int -> GetDistributionConfigResponse)
-> Either String Int -> Either String GetDistributionConfigResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable GetDistributionConfig

instance Prelude.NFData GetDistributionConfig

instance Core.ToHeaders GetDistributionConfig where
  toHeaders :: GetDistributionConfig -> ResponseHeaders
toHeaders = ResponseHeaders -> GetDistributionConfig -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const ResponseHeaders
forall a. Monoid a => a
Prelude.mempty

instance Core.ToPath GetDistributionConfig where
  toPath :: GetDistributionConfig -> ByteString
toPath GetDistributionConfig' {Text
id :: Text
$sel:id:GetDistributionConfig' :: GetDistributionConfig -> 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
id,
        ByteString
"/config"
      ]

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

-- | The returned result of the corresponding request.
--
-- /See:/ 'newGetDistributionConfigResponse' smart constructor.
data GetDistributionConfigResponse = GetDistributionConfigResponse'
  { -- | The current version of the configuration. For example: @E2QWRUHAPOMQZL@.
    GetDistributionConfigResponse -> Maybe Text
eTag :: Prelude.Maybe Prelude.Text,
    -- | The distribution\'s configuration information.
    GetDistributionConfigResponse -> Maybe DistributionConfig
distributionConfig :: Prelude.Maybe DistributionConfig,
    -- | The response's http status code.
    GetDistributionConfigResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetDistributionConfigResponse
-> GetDistributionConfigResponse -> Bool
(GetDistributionConfigResponse
 -> GetDistributionConfigResponse -> Bool)
-> (GetDistributionConfigResponse
    -> GetDistributionConfigResponse -> Bool)
-> Eq GetDistributionConfigResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetDistributionConfigResponse
-> GetDistributionConfigResponse -> Bool
$c/= :: GetDistributionConfigResponse
-> GetDistributionConfigResponse -> Bool
== :: GetDistributionConfigResponse
-> GetDistributionConfigResponse -> Bool
$c== :: GetDistributionConfigResponse
-> GetDistributionConfigResponse -> Bool
Prelude.Eq, Int -> GetDistributionConfigResponse -> ShowS
[GetDistributionConfigResponse] -> ShowS
GetDistributionConfigResponse -> String
(Int -> GetDistributionConfigResponse -> ShowS)
-> (GetDistributionConfigResponse -> String)
-> ([GetDistributionConfigResponse] -> ShowS)
-> Show GetDistributionConfigResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetDistributionConfigResponse] -> ShowS
$cshowList :: [GetDistributionConfigResponse] -> ShowS
show :: GetDistributionConfigResponse -> String
$cshow :: GetDistributionConfigResponse -> String
showsPrec :: Int -> GetDistributionConfigResponse -> ShowS
$cshowsPrec :: Int -> GetDistributionConfigResponse -> ShowS
Prelude.Show, (forall x.
 GetDistributionConfigResponse
 -> Rep GetDistributionConfigResponse x)
-> (forall x.
    Rep GetDistributionConfigResponse x
    -> GetDistributionConfigResponse)
-> Generic GetDistributionConfigResponse
forall x.
Rep GetDistributionConfigResponse x
-> GetDistributionConfigResponse
forall x.
GetDistributionConfigResponse
-> Rep GetDistributionConfigResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetDistributionConfigResponse x
-> GetDistributionConfigResponse
$cfrom :: forall x.
GetDistributionConfigResponse
-> Rep GetDistributionConfigResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetDistributionConfigResponse' 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:
--
-- 'eTag', 'getDistributionConfigResponse_eTag' - The current version of the configuration. For example: @E2QWRUHAPOMQZL@.
--
-- 'distributionConfig', 'getDistributionConfigResponse_distributionConfig' - The distribution\'s configuration information.
--
-- 'httpStatus', 'getDistributionConfigResponse_httpStatus' - The response's http status code.
newGetDistributionConfigResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetDistributionConfigResponse
newGetDistributionConfigResponse :: Int -> GetDistributionConfigResponse
newGetDistributionConfigResponse Int
pHttpStatus_ =
  GetDistributionConfigResponse' :: Maybe Text
-> Maybe DistributionConfig -> Int -> GetDistributionConfigResponse
GetDistributionConfigResponse'
    { $sel:eTag:GetDistributionConfigResponse' :: Maybe Text
eTag =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:distributionConfig:GetDistributionConfigResponse' :: Maybe DistributionConfig
distributionConfig = Maybe DistributionConfig
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetDistributionConfigResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The current version of the configuration. For example: @E2QWRUHAPOMQZL@.
getDistributionConfigResponse_eTag :: Lens.Lens' GetDistributionConfigResponse (Prelude.Maybe Prelude.Text)
getDistributionConfigResponse_eTag :: (Maybe Text -> f (Maybe Text))
-> GetDistributionConfigResponse -> f GetDistributionConfigResponse
getDistributionConfigResponse_eTag = (GetDistributionConfigResponse -> Maybe Text)
-> (GetDistributionConfigResponse
    -> Maybe Text -> GetDistributionConfigResponse)
-> Lens
     GetDistributionConfigResponse
     GetDistributionConfigResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetDistributionConfigResponse' {Maybe Text
eTag :: Maybe Text
$sel:eTag:GetDistributionConfigResponse' :: GetDistributionConfigResponse -> Maybe Text
eTag} -> Maybe Text
eTag) (\s :: GetDistributionConfigResponse
s@GetDistributionConfigResponse' {} Maybe Text
a -> GetDistributionConfigResponse
s {$sel:eTag:GetDistributionConfigResponse' :: Maybe Text
eTag = Maybe Text
a} :: GetDistributionConfigResponse)

-- | The distribution\'s configuration information.
getDistributionConfigResponse_distributionConfig :: Lens.Lens' GetDistributionConfigResponse (Prelude.Maybe DistributionConfig)
getDistributionConfigResponse_distributionConfig :: (Maybe DistributionConfig -> f (Maybe DistributionConfig))
-> GetDistributionConfigResponse -> f GetDistributionConfigResponse
getDistributionConfigResponse_distributionConfig = (GetDistributionConfigResponse -> Maybe DistributionConfig)
-> (GetDistributionConfigResponse
    -> Maybe DistributionConfig -> GetDistributionConfigResponse)
-> Lens
     GetDistributionConfigResponse
     GetDistributionConfigResponse
     (Maybe DistributionConfig)
     (Maybe DistributionConfig)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetDistributionConfigResponse' {Maybe DistributionConfig
distributionConfig :: Maybe DistributionConfig
$sel:distributionConfig:GetDistributionConfigResponse' :: GetDistributionConfigResponse -> Maybe DistributionConfig
distributionConfig} -> Maybe DistributionConfig
distributionConfig) (\s :: GetDistributionConfigResponse
s@GetDistributionConfigResponse' {} Maybe DistributionConfig
a -> GetDistributionConfigResponse
s {$sel:distributionConfig:GetDistributionConfigResponse' :: Maybe DistributionConfig
distributionConfig = Maybe DistributionConfig
a} :: GetDistributionConfigResponse)

-- | The response's http status code.
getDistributionConfigResponse_httpStatus :: Lens.Lens' GetDistributionConfigResponse Prelude.Int
getDistributionConfigResponse_httpStatus :: (Int -> f Int)
-> GetDistributionConfigResponse -> f GetDistributionConfigResponse
getDistributionConfigResponse_httpStatus = (GetDistributionConfigResponse -> Int)
-> (GetDistributionConfigResponse
    -> Int -> GetDistributionConfigResponse)
-> Lens
     GetDistributionConfigResponse GetDistributionConfigResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetDistributionConfigResponse' {Int
httpStatus :: Int
$sel:httpStatus:GetDistributionConfigResponse' :: GetDistributionConfigResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: GetDistributionConfigResponse
s@GetDistributionConfigResponse' {} Int
a -> GetDistributionConfigResponse
s {$sel:httpStatus:GetDistributionConfigResponse' :: Int
httpStatus = Int
a} :: GetDistributionConfigResponse)

instance Prelude.NFData GetDistributionConfigResponse