{-# 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-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 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.Lens as Lens
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
(GetOriginRequestPolicy -> GetOriginRequestPolicy -> Bool)
-> (GetOriginRequestPolicy -> GetOriginRequestPolicy -> Bool)
-> Eq GetOriginRequestPolicy
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]
(Int -> ReadS GetOriginRequestPolicy)
-> ReadS [GetOriginRequestPolicy]
-> ReadPrec GetOriginRequestPolicy
-> ReadPrec [GetOriginRequestPolicy]
-> Read 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
(Int -> GetOriginRequestPolicy -> ShowS)
-> (GetOriginRequestPolicy -> String)
-> ([GetOriginRequestPolicy] -> ShowS)
-> Show GetOriginRequestPolicy
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. GetOriginRequestPolicy -> Rep GetOriginRequestPolicy x)
-> (forall x.
    Rep GetOriginRequestPolicy x -> GetOriginRequestPolicy)
-> Generic GetOriginRequestPolicy
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' :: Text -> GetOriginRequestPolicy
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 :: (Text -> f Text)
-> GetOriginRequestPolicy -> f GetOriginRequestPolicy
getOriginRequestPolicy_id = (GetOriginRequestPolicy -> Text)
-> (GetOriginRequestPolicy -> Text -> GetOriginRequestPolicy)
-> Lens GetOriginRequestPolicy GetOriginRequestPolicy Text Text
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 :: GetOriginRequestPolicy -> Request GetOriginRequestPolicy
request = Service -> GetOriginRequestPolicy -> Request GetOriginRequestPolicy
forall a. ToRequest a => Service -> a -> Request a
Request.get Service
defaultService
  response :: Logger
-> Service
-> Proxy GetOriginRequestPolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetOriginRequestPolicy)))
response =
    (Int
 -> ResponseHeaders
 -> [Node]
 -> Either String (AWSResponse GetOriginRequestPolicy))
-> Logger
-> Service
-> Proxy GetOriginRequestPolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetOriginRequestPolicy)))
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 OriginRequestPolicy
-> Int
-> GetOriginRequestPolicyResponse
GetOriginRequestPolicyResponse'
            (Maybe Text
 -> Maybe OriginRequestPolicy
 -> Int
 -> GetOriginRequestPolicyResponse)
-> Either String (Maybe Text)
-> Either
     String
     (Maybe OriginRequestPolicy
      -> Int -> GetOriginRequestPolicyResponse)
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 OriginRequestPolicy
   -> Int -> GetOriginRequestPolicyResponse)
-> Either String (Maybe OriginRequestPolicy)
-> Either String (Int -> GetOriginRequestPolicyResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node] -> Either String (Maybe OriginRequestPolicy)
forall a. FromXML a => [Node] -> Either String a
Core.parseXML [Node]
x)
            Either String (Int -> GetOriginRequestPolicyResponse)
-> Either String Int
-> Either String GetOriginRequestPolicyResponse
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 GetOriginRequestPolicy

instance Prelude.NFData GetOriginRequestPolicy

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

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

instance Core.ToQuery GetOriginRequestPolicy where
  toQuery :: GetOriginRequestPolicy -> QueryString
toQuery = QueryString -> GetOriginRequestPolicy -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
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
(GetOriginRequestPolicyResponse
 -> GetOriginRequestPolicyResponse -> Bool)
-> (GetOriginRequestPolicyResponse
    -> GetOriginRequestPolicyResponse -> Bool)
-> Eq GetOriginRequestPolicyResponse
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]
(Int -> ReadS GetOriginRequestPolicyResponse)
-> ReadS [GetOriginRequestPolicyResponse]
-> ReadPrec GetOriginRequestPolicyResponse
-> ReadPrec [GetOriginRequestPolicyResponse]
-> Read 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
(Int -> GetOriginRequestPolicyResponse -> ShowS)
-> (GetOriginRequestPolicyResponse -> String)
-> ([GetOriginRequestPolicyResponse] -> ShowS)
-> Show GetOriginRequestPolicyResponse
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.
 GetOriginRequestPolicyResponse
 -> Rep GetOriginRequestPolicyResponse x)
-> (forall x.
    Rep GetOriginRequestPolicyResponse x
    -> GetOriginRequestPolicyResponse)
-> Generic GetOriginRequestPolicyResponse
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' :: Maybe Text
-> Maybe OriginRequestPolicy
-> Int
-> GetOriginRequestPolicyResponse
GetOriginRequestPolicyResponse'
    { $sel:eTag:GetOriginRequestPolicyResponse' :: Maybe Text
eTag =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:originRequestPolicy:GetOriginRequestPolicyResponse' :: Maybe OriginRequestPolicy
originRequestPolicy = Maybe 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 :: (Maybe Text -> f (Maybe Text))
-> GetOriginRequestPolicyResponse
-> f GetOriginRequestPolicyResponse
getOriginRequestPolicyResponse_eTag = (GetOriginRequestPolicyResponse -> Maybe Text)
-> (GetOriginRequestPolicyResponse
    -> Maybe Text -> GetOriginRequestPolicyResponse)
-> Lens
     GetOriginRequestPolicyResponse
     GetOriginRequestPolicyResponse
     (Maybe Text)
     (Maybe Text)
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 :: (Maybe OriginRequestPolicy -> f (Maybe OriginRequestPolicy))
-> GetOriginRequestPolicyResponse
-> f GetOriginRequestPolicyResponse
getOriginRequestPolicyResponse_originRequestPolicy = (GetOriginRequestPolicyResponse -> Maybe OriginRequestPolicy)
-> (GetOriginRequestPolicyResponse
    -> Maybe OriginRequestPolicy -> GetOriginRequestPolicyResponse)
-> Lens
     GetOriginRequestPolicyResponse
     GetOriginRequestPolicyResponse
     (Maybe OriginRequestPolicy)
     (Maybe 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 :: (Int -> f Int)
-> GetOriginRequestPolicyResponse
-> f GetOriginRequestPolicyResponse
getOriginRequestPolicyResponse_httpStatus = (GetOriginRequestPolicyResponse -> Int)
-> (GetOriginRequestPolicyResponse
    -> Int -> GetOriginRequestPolicyResponse)
-> Lens
     GetOriginRequestPolicyResponse
     GetOriginRequestPolicyResponse
     Int
     Int
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