{-# 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.GetOriginRequestPolicy
-- 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 an origin request policy, including the following metadata:
--
-- -   The policy\'s identifier.
--
-- -   The date and time when the policy was last modified.
--
-- To get an origin request policy, you must provide the policy\'s
-- identifier. If the origin request policy is attached to a
-- distribution\'s cache behavior, you can get the policy\'s identifier
-- using @ListDistributions@ or @GetDistribution@. If the origin request
-- policy is not attached to a cache behavior, you can get the identifier
-- using @ListOriginRequestPolicies@.
module Amazonka.CloudFront.GetOriginRequestPolicy
  ( -- * Creating a Request
    GetOriginRequestPolicy (..),
    newGetOriginRequestPolicy,

    -- * Request Lenses
    getOriginRequestPolicy_id,

    -- * Destructuring the Response
    GetOriginRequestPolicyResponse (..),
    newGetOriginRequestPolicyResponse,

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

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

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

instance Core.AWSRequest GetOriginRequestPolicy where
  type
    AWSResponse GetOriginRequestPolicy =
      GetOriginRequestPolicyResponse
  request :: (Service -> Service)
-> GetOriginRequestPolicy -> Request GetOriginRequestPolicy
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 GetOriginRequestPolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetOriginRequestPolicy)))
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 OriginRequestPolicy
-> Int
-> GetOriginRequestPolicyResponse
GetOriginRequestPolicyResponse'
            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 GetOriginRequestPolicy where
  hashWithSalt :: Int -> GetOriginRequestPolicy -> Int
hashWithSalt Int
_salt GetOriginRequestPolicy' {Text
id :: Text
$sel:id:GetOriginRequestPolicy' :: GetOriginRequestPolicy -> Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
id

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

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

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

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

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

-- |
-- Create a value of 'GetOriginRequestPolicyResponse' 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', 'getOriginRequestPolicyResponse_eTag' - The current version of the origin request policy.
--
-- 'originRequestPolicy', 'getOriginRequestPolicyResponse_originRequestPolicy' - The origin request policy.
--
-- 'httpStatus', 'getOriginRequestPolicyResponse_httpStatus' - The response's http status code.
newGetOriginRequestPolicyResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetOriginRequestPolicyResponse
newGetOriginRequestPolicyResponse :: Int -> GetOriginRequestPolicyResponse
newGetOriginRequestPolicyResponse Int
pHttpStatus_ =
  GetOriginRequestPolicyResponse'
    { $sel:eTag:GetOriginRequestPolicyResponse' :: Maybe Text
eTag =
        forall a. Maybe a
Prelude.Nothing,
      $sel:originRequestPolicy:GetOriginRequestPolicyResponse' :: Maybe OriginRequestPolicy
originRequestPolicy = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetOriginRequestPolicyResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

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

-- | The origin request policy.
getOriginRequestPolicyResponse_originRequestPolicy :: Lens.Lens' GetOriginRequestPolicyResponse (Prelude.Maybe OriginRequestPolicy)
getOriginRequestPolicyResponse_originRequestPolicy :: Lens' GetOriginRequestPolicyResponse (Maybe OriginRequestPolicy)
getOriginRequestPolicyResponse_originRequestPolicy = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetOriginRequestPolicyResponse' {Maybe OriginRequestPolicy
originRequestPolicy :: Maybe OriginRequestPolicy
$sel:originRequestPolicy:GetOriginRequestPolicyResponse' :: GetOriginRequestPolicyResponse -> Maybe OriginRequestPolicy
originRequestPolicy} -> Maybe OriginRequestPolicy
originRequestPolicy) (\s :: GetOriginRequestPolicyResponse
s@GetOriginRequestPolicyResponse' {} Maybe OriginRequestPolicy
a -> GetOriginRequestPolicyResponse
s {$sel:originRequestPolicy:GetOriginRequestPolicyResponse' :: Maybe OriginRequestPolicy
originRequestPolicy = Maybe OriginRequestPolicy
a} :: GetOriginRequestPolicyResponse)

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

instance
  Prelude.NFData
    GetOriginRequestPolicyResponse
  where
  rnf :: GetOriginRequestPolicyResponse -> ()
rnf GetOriginRequestPolicyResponse' {Int
Maybe Text
Maybe OriginRequestPolicy
httpStatus :: Int
originRequestPolicy :: Maybe OriginRequestPolicy
eTag :: Maybe Text
$sel:httpStatus:GetOriginRequestPolicyResponse' :: GetOriginRequestPolicyResponse -> Int
$sel:originRequestPolicy:GetOriginRequestPolicyResponse' :: GetOriginRequestPolicyResponse -> Maybe OriginRequestPolicy
$sel:eTag:GetOriginRequestPolicyResponse' :: GetOriginRequestPolicyResponse -> 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 OriginRequestPolicy
originRequestPolicy
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus