{-# 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.GetCachePolicyConfig
-- 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)
--
-- Gets a cache policy configuration.
--
-- To get a cache policy configuration, you must provide the policy’s
-- identifier. If the cache policy is attached to a distribution’s cache
-- behavior, you can get the policy’s identifier using @ListDistributions@
-- or @GetDistribution@. If the cache policy is not attached to a cache
-- behavior, you can get the identifier using @ListCachePolicies@.
module Amazonka.CloudFront.GetCachePolicyConfig
  ( -- * Creating a Request
    GetCachePolicyConfig (..),
    newGetCachePolicyConfig,

    -- * Request Lenses
    getCachePolicyConfig_id,

    -- * Destructuring the Response
    GetCachePolicyConfigResponse (..),
    newGetCachePolicyConfigResponse,

    -- * Response Lenses
    getCachePolicyConfigResponse_eTag,
    getCachePolicyConfigResponse_cachePolicyConfig,
    getCachePolicyConfigResponse_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

-- | /See:/ 'newGetCachePolicyConfig' smart constructor.
data GetCachePolicyConfig = GetCachePolicyConfig'
  { -- | The unique identifier for the cache policy. If the cache policy is
    -- attached to a distribution’s cache behavior, you can get the policy’s
    -- identifier using @ListDistributions@ or @GetDistribution@. If the cache
    -- policy is not attached to a cache behavior, you can get the identifier
    -- using @ListCachePolicies@.
    GetCachePolicyConfig -> Text
id :: Prelude.Text
  }
  deriving (GetCachePolicyConfig -> GetCachePolicyConfig -> Bool
(GetCachePolicyConfig -> GetCachePolicyConfig -> Bool)
-> (GetCachePolicyConfig -> GetCachePolicyConfig -> Bool)
-> Eq GetCachePolicyConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetCachePolicyConfig -> GetCachePolicyConfig -> Bool
$c/= :: GetCachePolicyConfig -> GetCachePolicyConfig -> Bool
== :: GetCachePolicyConfig -> GetCachePolicyConfig -> Bool
$c== :: GetCachePolicyConfig -> GetCachePolicyConfig -> Bool
Prelude.Eq, ReadPrec [GetCachePolicyConfig]
ReadPrec GetCachePolicyConfig
Int -> ReadS GetCachePolicyConfig
ReadS [GetCachePolicyConfig]
(Int -> ReadS GetCachePolicyConfig)
-> ReadS [GetCachePolicyConfig]
-> ReadPrec GetCachePolicyConfig
-> ReadPrec [GetCachePolicyConfig]
-> Read GetCachePolicyConfig
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetCachePolicyConfig]
$creadListPrec :: ReadPrec [GetCachePolicyConfig]
readPrec :: ReadPrec GetCachePolicyConfig
$creadPrec :: ReadPrec GetCachePolicyConfig
readList :: ReadS [GetCachePolicyConfig]
$creadList :: ReadS [GetCachePolicyConfig]
readsPrec :: Int -> ReadS GetCachePolicyConfig
$creadsPrec :: Int -> ReadS GetCachePolicyConfig
Prelude.Read, Int -> GetCachePolicyConfig -> ShowS
[GetCachePolicyConfig] -> ShowS
GetCachePolicyConfig -> String
(Int -> GetCachePolicyConfig -> ShowS)
-> (GetCachePolicyConfig -> String)
-> ([GetCachePolicyConfig] -> ShowS)
-> Show GetCachePolicyConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetCachePolicyConfig] -> ShowS
$cshowList :: [GetCachePolicyConfig] -> ShowS
show :: GetCachePolicyConfig -> String
$cshow :: GetCachePolicyConfig -> String
showsPrec :: Int -> GetCachePolicyConfig -> ShowS
$cshowsPrec :: Int -> GetCachePolicyConfig -> ShowS
Prelude.Show, (forall x. GetCachePolicyConfig -> Rep GetCachePolicyConfig x)
-> (forall x. Rep GetCachePolicyConfig x -> GetCachePolicyConfig)
-> Generic GetCachePolicyConfig
forall x. Rep GetCachePolicyConfig x -> GetCachePolicyConfig
forall x. GetCachePolicyConfig -> Rep GetCachePolicyConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetCachePolicyConfig x -> GetCachePolicyConfig
$cfrom :: forall x. GetCachePolicyConfig -> Rep GetCachePolicyConfig x
Prelude.Generic)

-- |
-- Create a value of 'GetCachePolicyConfig' 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', 'getCachePolicyConfig_id' - The unique identifier for the cache policy. If the cache policy is
-- attached to a distribution’s cache behavior, you can get the policy’s
-- identifier using @ListDistributions@ or @GetDistribution@. If the cache
-- policy is not attached to a cache behavior, you can get the identifier
-- using @ListCachePolicies@.
newGetCachePolicyConfig ::
  -- | 'id'
  Prelude.Text ->
  GetCachePolicyConfig
newGetCachePolicyConfig :: Text -> GetCachePolicyConfig
newGetCachePolicyConfig Text
pId_ =
  GetCachePolicyConfig' :: Text -> GetCachePolicyConfig
GetCachePolicyConfig' {$sel:id:GetCachePolicyConfig' :: Text
id = Text
pId_}

-- | The unique identifier for the cache policy. If the cache policy is
-- attached to a distribution’s cache behavior, you can get the policy’s
-- identifier using @ListDistributions@ or @GetDistribution@. If the cache
-- policy is not attached to a cache behavior, you can get the identifier
-- using @ListCachePolicies@.
getCachePolicyConfig_id :: Lens.Lens' GetCachePolicyConfig Prelude.Text
getCachePolicyConfig_id :: (Text -> f Text) -> GetCachePolicyConfig -> f GetCachePolicyConfig
getCachePolicyConfig_id = (GetCachePolicyConfig -> Text)
-> (GetCachePolicyConfig -> Text -> GetCachePolicyConfig)
-> Lens GetCachePolicyConfig GetCachePolicyConfig Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetCachePolicyConfig' {Text
id :: Text
$sel:id:GetCachePolicyConfig' :: GetCachePolicyConfig -> Text
id} -> Text
id) (\s :: GetCachePolicyConfig
s@GetCachePolicyConfig' {} Text
a -> GetCachePolicyConfig
s {$sel:id:GetCachePolicyConfig' :: Text
id = Text
a} :: GetCachePolicyConfig)

instance Core.AWSRequest GetCachePolicyConfig where
  type
    AWSResponse GetCachePolicyConfig =
      GetCachePolicyConfigResponse
  request :: GetCachePolicyConfig -> Request GetCachePolicyConfig
request = Service -> GetCachePolicyConfig -> Request GetCachePolicyConfig
forall a. ToRequest a => Service -> a -> Request a
Request.get Service
defaultService
  response :: Logger
-> Service
-> Proxy GetCachePolicyConfig
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetCachePolicyConfig)))
response =
    (Int
 -> ResponseHeaders
 -> [Node]
 -> Either String (AWSResponse GetCachePolicyConfig))
-> Logger
-> Service
-> Proxy GetCachePolicyConfig
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetCachePolicyConfig)))
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 CachePolicyConfig -> Int -> GetCachePolicyConfigResponse
GetCachePolicyConfigResponse'
            (Maybe Text
 -> Maybe CachePolicyConfig -> Int -> GetCachePolicyConfigResponse)
-> Either String (Maybe Text)
-> Either
     String
     (Maybe CachePolicyConfig -> Int -> GetCachePolicyConfigResponse)
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 CachePolicyConfig -> Int -> GetCachePolicyConfigResponse)
-> Either String (Maybe CachePolicyConfig)
-> Either String (Int -> GetCachePolicyConfigResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node] -> Either String (Maybe CachePolicyConfig)
forall a. FromXML a => [Node] -> Either String a
Core.parseXML [Node]
x)
            Either String (Int -> GetCachePolicyConfigResponse)
-> Either String Int -> Either String GetCachePolicyConfigResponse
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 GetCachePolicyConfig

instance Prelude.NFData GetCachePolicyConfig

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

instance Core.ToPath GetCachePolicyConfig where
  toPath :: GetCachePolicyConfig -> ByteString
toPath GetCachePolicyConfig' {Text
id :: Text
$sel:id:GetCachePolicyConfig' :: GetCachePolicyConfig -> Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/2020-05-31/cache-policy/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
id,
        ByteString
"/config"
      ]

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

-- | /See:/ 'newGetCachePolicyConfigResponse' smart constructor.
data GetCachePolicyConfigResponse = GetCachePolicyConfigResponse'
  { -- | The current version of the cache policy.
    GetCachePolicyConfigResponse -> Maybe Text
eTag :: Prelude.Maybe Prelude.Text,
    -- | The cache policy configuration.
    GetCachePolicyConfigResponse -> Maybe CachePolicyConfig
cachePolicyConfig :: Prelude.Maybe CachePolicyConfig,
    -- | The response's http status code.
    GetCachePolicyConfigResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetCachePolicyConfigResponse
-> GetCachePolicyConfigResponse -> Bool
(GetCachePolicyConfigResponse
 -> GetCachePolicyConfigResponse -> Bool)
-> (GetCachePolicyConfigResponse
    -> GetCachePolicyConfigResponse -> Bool)
-> Eq GetCachePolicyConfigResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetCachePolicyConfigResponse
-> GetCachePolicyConfigResponse -> Bool
$c/= :: GetCachePolicyConfigResponse
-> GetCachePolicyConfigResponse -> Bool
== :: GetCachePolicyConfigResponse
-> GetCachePolicyConfigResponse -> Bool
$c== :: GetCachePolicyConfigResponse
-> GetCachePolicyConfigResponse -> Bool
Prelude.Eq, ReadPrec [GetCachePolicyConfigResponse]
ReadPrec GetCachePolicyConfigResponse
Int -> ReadS GetCachePolicyConfigResponse
ReadS [GetCachePolicyConfigResponse]
(Int -> ReadS GetCachePolicyConfigResponse)
-> ReadS [GetCachePolicyConfigResponse]
-> ReadPrec GetCachePolicyConfigResponse
-> ReadPrec [GetCachePolicyConfigResponse]
-> Read GetCachePolicyConfigResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetCachePolicyConfigResponse]
$creadListPrec :: ReadPrec [GetCachePolicyConfigResponse]
readPrec :: ReadPrec GetCachePolicyConfigResponse
$creadPrec :: ReadPrec GetCachePolicyConfigResponse
readList :: ReadS [GetCachePolicyConfigResponse]
$creadList :: ReadS [GetCachePolicyConfigResponse]
readsPrec :: Int -> ReadS GetCachePolicyConfigResponse
$creadsPrec :: Int -> ReadS GetCachePolicyConfigResponse
Prelude.Read, Int -> GetCachePolicyConfigResponse -> ShowS
[GetCachePolicyConfigResponse] -> ShowS
GetCachePolicyConfigResponse -> String
(Int -> GetCachePolicyConfigResponse -> ShowS)
-> (GetCachePolicyConfigResponse -> String)
-> ([GetCachePolicyConfigResponse] -> ShowS)
-> Show GetCachePolicyConfigResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetCachePolicyConfigResponse] -> ShowS
$cshowList :: [GetCachePolicyConfigResponse] -> ShowS
show :: GetCachePolicyConfigResponse -> String
$cshow :: GetCachePolicyConfigResponse -> String
showsPrec :: Int -> GetCachePolicyConfigResponse -> ShowS
$cshowsPrec :: Int -> GetCachePolicyConfigResponse -> ShowS
Prelude.Show, (forall x.
 GetCachePolicyConfigResponse -> Rep GetCachePolicyConfigResponse x)
-> (forall x.
    Rep GetCachePolicyConfigResponse x -> GetCachePolicyConfigResponse)
-> Generic GetCachePolicyConfigResponse
forall x.
Rep GetCachePolicyConfigResponse x -> GetCachePolicyConfigResponse
forall x.
GetCachePolicyConfigResponse -> Rep GetCachePolicyConfigResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetCachePolicyConfigResponse x -> GetCachePolicyConfigResponse
$cfrom :: forall x.
GetCachePolicyConfigResponse -> Rep GetCachePolicyConfigResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetCachePolicyConfigResponse' 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', 'getCachePolicyConfigResponse_eTag' - The current version of the cache policy.
--
-- 'cachePolicyConfig', 'getCachePolicyConfigResponse_cachePolicyConfig' - The cache policy configuration.
--
-- 'httpStatus', 'getCachePolicyConfigResponse_httpStatus' - The response's http status code.
newGetCachePolicyConfigResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetCachePolicyConfigResponse
newGetCachePolicyConfigResponse :: Int -> GetCachePolicyConfigResponse
newGetCachePolicyConfigResponse Int
pHttpStatus_ =
  GetCachePolicyConfigResponse' :: Maybe Text
-> Maybe CachePolicyConfig -> Int -> GetCachePolicyConfigResponse
GetCachePolicyConfigResponse'
    { $sel:eTag:GetCachePolicyConfigResponse' :: Maybe Text
eTag =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:cachePolicyConfig:GetCachePolicyConfigResponse' :: Maybe CachePolicyConfig
cachePolicyConfig = Maybe CachePolicyConfig
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetCachePolicyConfigResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The current version of the cache policy.
getCachePolicyConfigResponse_eTag :: Lens.Lens' GetCachePolicyConfigResponse (Prelude.Maybe Prelude.Text)
getCachePolicyConfigResponse_eTag :: (Maybe Text -> f (Maybe Text))
-> GetCachePolicyConfigResponse -> f GetCachePolicyConfigResponse
getCachePolicyConfigResponse_eTag = (GetCachePolicyConfigResponse -> Maybe Text)
-> (GetCachePolicyConfigResponse
    -> Maybe Text -> GetCachePolicyConfigResponse)
-> Lens
     GetCachePolicyConfigResponse
     GetCachePolicyConfigResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetCachePolicyConfigResponse' {Maybe Text
eTag :: Maybe Text
$sel:eTag:GetCachePolicyConfigResponse' :: GetCachePolicyConfigResponse -> Maybe Text
eTag} -> Maybe Text
eTag) (\s :: GetCachePolicyConfigResponse
s@GetCachePolicyConfigResponse' {} Maybe Text
a -> GetCachePolicyConfigResponse
s {$sel:eTag:GetCachePolicyConfigResponse' :: Maybe Text
eTag = Maybe Text
a} :: GetCachePolicyConfigResponse)

-- | The cache policy configuration.
getCachePolicyConfigResponse_cachePolicyConfig :: Lens.Lens' GetCachePolicyConfigResponse (Prelude.Maybe CachePolicyConfig)
getCachePolicyConfigResponse_cachePolicyConfig :: (Maybe CachePolicyConfig -> f (Maybe CachePolicyConfig))
-> GetCachePolicyConfigResponse -> f GetCachePolicyConfigResponse
getCachePolicyConfigResponse_cachePolicyConfig = (GetCachePolicyConfigResponse -> Maybe CachePolicyConfig)
-> (GetCachePolicyConfigResponse
    -> Maybe CachePolicyConfig -> GetCachePolicyConfigResponse)
-> Lens
     GetCachePolicyConfigResponse
     GetCachePolicyConfigResponse
     (Maybe CachePolicyConfig)
     (Maybe CachePolicyConfig)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetCachePolicyConfigResponse' {Maybe CachePolicyConfig
cachePolicyConfig :: Maybe CachePolicyConfig
$sel:cachePolicyConfig:GetCachePolicyConfigResponse' :: GetCachePolicyConfigResponse -> Maybe CachePolicyConfig
cachePolicyConfig} -> Maybe CachePolicyConfig
cachePolicyConfig) (\s :: GetCachePolicyConfigResponse
s@GetCachePolicyConfigResponse' {} Maybe CachePolicyConfig
a -> GetCachePolicyConfigResponse
s {$sel:cachePolicyConfig:GetCachePolicyConfigResponse' :: Maybe CachePolicyConfig
cachePolicyConfig = Maybe CachePolicyConfig
a} :: GetCachePolicyConfigResponse)

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

instance Prelude.NFData GetCachePolicyConfigResponse