{-# 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.GetCachePolicy
-- 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, including the following metadata:
--
-- -   The policy’s identifier.
--
-- -   The date and time when the policy was last modified.
--
-- To get a cache policy, 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.GetCachePolicy
  ( -- * Creating a Request
    GetCachePolicy (..),
    newGetCachePolicy,

    -- * Request Lenses
    getCachePolicy_id,

    -- * Destructuring the Response
    GetCachePolicyResponse (..),
    newGetCachePolicyResponse,

    -- * Response Lenses
    getCachePolicyResponse_cachePolicy,
    getCachePolicyResponse_eTag,
    getCachePolicyResponse_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:/ 'newGetCachePolicy' smart constructor.
data GetCachePolicy = GetCachePolicy'
  { -- | 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@.
    GetCachePolicy -> Text
id :: Prelude.Text
  }
  deriving (GetCachePolicy -> GetCachePolicy -> Bool
(GetCachePolicy -> GetCachePolicy -> Bool)
-> (GetCachePolicy -> GetCachePolicy -> Bool) -> Eq GetCachePolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetCachePolicy -> GetCachePolicy -> Bool
$c/= :: GetCachePolicy -> GetCachePolicy -> Bool
== :: GetCachePolicy -> GetCachePolicy -> Bool
$c== :: GetCachePolicy -> GetCachePolicy -> Bool
Prelude.Eq, ReadPrec [GetCachePolicy]
ReadPrec GetCachePolicy
Int -> ReadS GetCachePolicy
ReadS [GetCachePolicy]
(Int -> ReadS GetCachePolicy)
-> ReadS [GetCachePolicy]
-> ReadPrec GetCachePolicy
-> ReadPrec [GetCachePolicy]
-> Read GetCachePolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetCachePolicy]
$creadListPrec :: ReadPrec [GetCachePolicy]
readPrec :: ReadPrec GetCachePolicy
$creadPrec :: ReadPrec GetCachePolicy
readList :: ReadS [GetCachePolicy]
$creadList :: ReadS [GetCachePolicy]
readsPrec :: Int -> ReadS GetCachePolicy
$creadsPrec :: Int -> ReadS GetCachePolicy
Prelude.Read, Int -> GetCachePolicy -> ShowS
[GetCachePolicy] -> ShowS
GetCachePolicy -> String
(Int -> GetCachePolicy -> ShowS)
-> (GetCachePolicy -> String)
-> ([GetCachePolicy] -> ShowS)
-> Show GetCachePolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetCachePolicy] -> ShowS
$cshowList :: [GetCachePolicy] -> ShowS
show :: GetCachePolicy -> String
$cshow :: GetCachePolicy -> String
showsPrec :: Int -> GetCachePolicy -> ShowS
$cshowsPrec :: Int -> GetCachePolicy -> ShowS
Prelude.Show, (forall x. GetCachePolicy -> Rep GetCachePolicy x)
-> (forall x. Rep GetCachePolicy x -> GetCachePolicy)
-> Generic GetCachePolicy
forall x. Rep GetCachePolicy x -> GetCachePolicy
forall x. GetCachePolicy -> Rep GetCachePolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetCachePolicy x -> GetCachePolicy
$cfrom :: forall x. GetCachePolicy -> Rep GetCachePolicy x
Prelude.Generic)

-- |
-- Create a value of 'GetCachePolicy' 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', 'getCachePolicy_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@.
newGetCachePolicy ::
  -- | 'id'
  Prelude.Text ->
  GetCachePolicy
newGetCachePolicy :: Text -> GetCachePolicy
newGetCachePolicy Text
pId_ = GetCachePolicy' :: Text -> GetCachePolicy
GetCachePolicy' {$sel:id:GetCachePolicy' :: 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@.
getCachePolicy_id :: Lens.Lens' GetCachePolicy Prelude.Text
getCachePolicy_id :: (Text -> f Text) -> GetCachePolicy -> f GetCachePolicy
getCachePolicy_id = (GetCachePolicy -> Text)
-> (GetCachePolicy -> Text -> GetCachePolicy)
-> Lens GetCachePolicy GetCachePolicy Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetCachePolicy' {Text
id :: Text
$sel:id:GetCachePolicy' :: GetCachePolicy -> Text
id} -> Text
id) (\s :: GetCachePolicy
s@GetCachePolicy' {} Text
a -> GetCachePolicy
s {$sel:id:GetCachePolicy' :: Text
id = Text
a} :: GetCachePolicy)

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

instance Prelude.NFData GetCachePolicy

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

instance Core.ToPath GetCachePolicy where
  toPath :: GetCachePolicy -> ByteString
toPath GetCachePolicy' {Text
id :: Text
$sel:id:GetCachePolicy' :: GetCachePolicy -> 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]

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

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

-- |
-- Create a value of 'GetCachePolicyResponse' 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:
--
-- 'cachePolicy', 'getCachePolicyResponse_cachePolicy' - The cache policy.
--
-- 'eTag', 'getCachePolicyResponse_eTag' - The current version of the cache policy.
--
-- 'httpStatus', 'getCachePolicyResponse_httpStatus' - The response's http status code.
newGetCachePolicyResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetCachePolicyResponse
newGetCachePolicyResponse :: Int -> GetCachePolicyResponse
newGetCachePolicyResponse Int
pHttpStatus_ =
  GetCachePolicyResponse' :: Maybe CachePolicy -> Maybe Text -> Int -> GetCachePolicyResponse
GetCachePolicyResponse'
    { $sel:cachePolicy:GetCachePolicyResponse' :: Maybe CachePolicy
cachePolicy =
        Maybe CachePolicy
forall a. Maybe a
Prelude.Nothing,
      $sel:eTag:GetCachePolicyResponse' :: Maybe Text
eTag = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetCachePolicyResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The cache policy.
getCachePolicyResponse_cachePolicy :: Lens.Lens' GetCachePolicyResponse (Prelude.Maybe CachePolicy)
getCachePolicyResponse_cachePolicy :: (Maybe CachePolicy -> f (Maybe CachePolicy))
-> GetCachePolicyResponse -> f GetCachePolicyResponse
getCachePolicyResponse_cachePolicy = (GetCachePolicyResponse -> Maybe CachePolicy)
-> (GetCachePolicyResponse
    -> Maybe CachePolicy -> GetCachePolicyResponse)
-> Lens
     GetCachePolicyResponse
     GetCachePolicyResponse
     (Maybe CachePolicy)
     (Maybe CachePolicy)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetCachePolicyResponse' {Maybe CachePolicy
cachePolicy :: Maybe CachePolicy
$sel:cachePolicy:GetCachePolicyResponse' :: GetCachePolicyResponse -> Maybe CachePolicy
cachePolicy} -> Maybe CachePolicy
cachePolicy) (\s :: GetCachePolicyResponse
s@GetCachePolicyResponse' {} Maybe CachePolicy
a -> GetCachePolicyResponse
s {$sel:cachePolicy:GetCachePolicyResponse' :: Maybe CachePolicy
cachePolicy = Maybe CachePolicy
a} :: GetCachePolicyResponse)

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

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

instance Prelude.NFData GetCachePolicyResponse