{-# 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.GetResponseHeadersPolicy
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Gets a response headers policy, including metadata (the policy\'s
-- identifier and the date and time when the policy was last modified).
--
-- To get a response headers policy, you must provide the policy\'s
-- identifier. If the response headers policy is attached to a
-- distribution\'s cache behavior, you can get the policy\'s identifier
-- using @ListDistributions@ or @GetDistribution@. If the response headers
-- policy is not attached to a cache behavior, you can get the identifier
-- using @ListResponseHeadersPolicies@.
module Amazonka.CloudFront.GetResponseHeadersPolicy
  ( -- * Creating a Request
    GetResponseHeadersPolicy (..),
    newGetResponseHeadersPolicy,

    -- * Request Lenses
    getResponseHeadersPolicy_id,

    -- * Destructuring the Response
    GetResponseHeadersPolicyResponse (..),
    newGetResponseHeadersPolicyResponse,

    -- * Response Lenses
    getResponseHeadersPolicyResponse_eTag,
    getResponseHeadersPolicyResponse_responseHeadersPolicy,
    getResponseHeadersPolicyResponse_httpStatus,
  )
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:/ 'newGetResponseHeadersPolicy' smart constructor.
data GetResponseHeadersPolicy = GetResponseHeadersPolicy'
  { -- | The identifier for the response headers policy.
    --
    -- If the response headers policy is attached to a distribution\'s cache
    -- behavior, you can get the policy\'s identifier using @ListDistributions@
    -- or @GetDistribution@. If the response headers policy is not attached to
    -- a cache behavior, you can get the identifier using
    -- @ListResponseHeadersPolicies@.
    GetResponseHeadersPolicy -> Text
id :: Prelude.Text
  }
  deriving (GetResponseHeadersPolicy -> GetResponseHeadersPolicy -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetResponseHeadersPolicy -> GetResponseHeadersPolicy -> Bool
$c/= :: GetResponseHeadersPolicy -> GetResponseHeadersPolicy -> Bool
== :: GetResponseHeadersPolicy -> GetResponseHeadersPolicy -> Bool
$c== :: GetResponseHeadersPolicy -> GetResponseHeadersPolicy -> Bool
Prelude.Eq, ReadPrec [GetResponseHeadersPolicy]
ReadPrec GetResponseHeadersPolicy
Int -> ReadS GetResponseHeadersPolicy
ReadS [GetResponseHeadersPolicy]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetResponseHeadersPolicy]
$creadListPrec :: ReadPrec [GetResponseHeadersPolicy]
readPrec :: ReadPrec GetResponseHeadersPolicy
$creadPrec :: ReadPrec GetResponseHeadersPolicy
readList :: ReadS [GetResponseHeadersPolicy]
$creadList :: ReadS [GetResponseHeadersPolicy]
readsPrec :: Int -> ReadS GetResponseHeadersPolicy
$creadsPrec :: Int -> ReadS GetResponseHeadersPolicy
Prelude.Read, Int -> GetResponseHeadersPolicy -> ShowS
[GetResponseHeadersPolicy] -> ShowS
GetResponseHeadersPolicy -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetResponseHeadersPolicy] -> ShowS
$cshowList :: [GetResponseHeadersPolicy] -> ShowS
show :: GetResponseHeadersPolicy -> String
$cshow :: GetResponseHeadersPolicy -> String
showsPrec :: Int -> GetResponseHeadersPolicy -> ShowS
$cshowsPrec :: Int -> GetResponseHeadersPolicy -> ShowS
Prelude.Show, forall x.
Rep GetResponseHeadersPolicy x -> GetResponseHeadersPolicy
forall x.
GetResponseHeadersPolicy -> Rep GetResponseHeadersPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetResponseHeadersPolicy x -> GetResponseHeadersPolicy
$cfrom :: forall x.
GetResponseHeadersPolicy -> Rep GetResponseHeadersPolicy x
Prelude.Generic)

-- |
-- Create a value of 'GetResponseHeadersPolicy' 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', 'getResponseHeadersPolicy_id' - The identifier for the response headers policy.
--
-- If the response headers policy is attached to a distribution\'s cache
-- behavior, you can get the policy\'s identifier using @ListDistributions@
-- or @GetDistribution@. If the response headers policy is not attached to
-- a cache behavior, you can get the identifier using
-- @ListResponseHeadersPolicies@.
newGetResponseHeadersPolicy ::
  -- | 'id'
  Prelude.Text ->
  GetResponseHeadersPolicy
newGetResponseHeadersPolicy :: Text -> GetResponseHeadersPolicy
newGetResponseHeadersPolicy Text
pId_ =
  GetResponseHeadersPolicy' {$sel:id:GetResponseHeadersPolicy' :: Text
id = Text
pId_}

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

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

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

instance Prelude.NFData GetResponseHeadersPolicy where
  rnf :: GetResponseHeadersPolicy -> ()
rnf GetResponseHeadersPolicy' {Text
id :: Text
$sel:id:GetResponseHeadersPolicy' :: GetResponseHeadersPolicy -> Text
..} = forall a. NFData a => a -> ()
Prelude.rnf Text
id

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

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

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

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

-- |
-- Create a value of 'GetResponseHeadersPolicyResponse' 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', 'getResponseHeadersPolicyResponse_eTag' - The version identifier for the current version of the response headers
-- policy.
--
-- 'responseHeadersPolicy', 'getResponseHeadersPolicyResponse_responseHeadersPolicy' - Contains a response headers policy.
--
-- 'httpStatus', 'getResponseHeadersPolicyResponse_httpStatus' - The response's http status code.
newGetResponseHeadersPolicyResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetResponseHeadersPolicyResponse
newGetResponseHeadersPolicyResponse :: Int -> GetResponseHeadersPolicyResponse
newGetResponseHeadersPolicyResponse Int
pHttpStatus_ =
  GetResponseHeadersPolicyResponse'
    { $sel:eTag:GetResponseHeadersPolicyResponse' :: Maybe Text
eTag =
        forall a. Maybe a
Prelude.Nothing,
      $sel:responseHeadersPolicy:GetResponseHeadersPolicyResponse' :: Maybe ResponseHeadersPolicy
responseHeadersPolicy = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetResponseHeadersPolicyResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The version identifier for the current version of the response headers
-- policy.
getResponseHeadersPolicyResponse_eTag :: Lens.Lens' GetResponseHeadersPolicyResponse (Prelude.Maybe Prelude.Text)
getResponseHeadersPolicyResponse_eTag :: Lens' GetResponseHeadersPolicyResponse (Maybe Text)
getResponseHeadersPolicyResponse_eTag = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetResponseHeadersPolicyResponse' {Maybe Text
eTag :: Maybe Text
$sel:eTag:GetResponseHeadersPolicyResponse' :: GetResponseHeadersPolicyResponse -> Maybe Text
eTag} -> Maybe Text
eTag) (\s :: GetResponseHeadersPolicyResponse
s@GetResponseHeadersPolicyResponse' {} Maybe Text
a -> GetResponseHeadersPolicyResponse
s {$sel:eTag:GetResponseHeadersPolicyResponse' :: Maybe Text
eTag = Maybe Text
a} :: GetResponseHeadersPolicyResponse)

-- | Contains a response headers policy.
getResponseHeadersPolicyResponse_responseHeadersPolicy :: Lens.Lens' GetResponseHeadersPolicyResponse (Prelude.Maybe ResponseHeadersPolicy)
getResponseHeadersPolicyResponse_responseHeadersPolicy :: Lens'
  GetResponseHeadersPolicyResponse (Maybe ResponseHeadersPolicy)
getResponseHeadersPolicyResponse_responseHeadersPolicy = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetResponseHeadersPolicyResponse' {Maybe ResponseHeadersPolicy
responseHeadersPolicy :: Maybe ResponseHeadersPolicy
$sel:responseHeadersPolicy:GetResponseHeadersPolicyResponse' :: GetResponseHeadersPolicyResponse -> Maybe ResponseHeadersPolicy
responseHeadersPolicy} -> Maybe ResponseHeadersPolicy
responseHeadersPolicy) (\s :: GetResponseHeadersPolicyResponse
s@GetResponseHeadersPolicyResponse' {} Maybe ResponseHeadersPolicy
a -> GetResponseHeadersPolicyResponse
s {$sel:responseHeadersPolicy:GetResponseHeadersPolicyResponse' :: Maybe ResponseHeadersPolicy
responseHeadersPolicy = Maybe ResponseHeadersPolicy
a} :: GetResponseHeadersPolicyResponse)

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

instance
  Prelude.NFData
    GetResponseHeadersPolicyResponse
  where
  rnf :: GetResponseHeadersPolicyResponse -> ()
rnf GetResponseHeadersPolicyResponse' {Int
Maybe Text
Maybe ResponseHeadersPolicy
httpStatus :: Int
responseHeadersPolicy :: Maybe ResponseHeadersPolicy
eTag :: Maybe Text
$sel:httpStatus:GetResponseHeadersPolicyResponse' :: GetResponseHeadersPolicyResponse -> Int
$sel:responseHeadersPolicy:GetResponseHeadersPolicyResponse' :: GetResponseHeadersPolicyResponse -> Maybe ResponseHeadersPolicy
$sel:eTag:GetResponseHeadersPolicyResponse' :: GetResponseHeadersPolicyResponse -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
eTag
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe ResponseHeadersPolicy
responseHeadersPolicy
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus