{-# 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.CreateCachePolicy
-- 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)
--
-- Creates a cache policy.
--
-- After you create a cache policy, you can attach it to one or more cache
-- behaviors. When it’s attached to a cache behavior, the cache policy
-- determines the following:
--
-- -   The values that CloudFront includes in the /cache key/. These values
--     can include HTTP headers, cookies, and URL query strings. CloudFront
--     uses the cache key to find an object in its cache that it can return
--     to the viewer.
--
-- -   The default, minimum, and maximum time to live (TTL) values that you
--     want objects to stay in the CloudFront cache.
--
-- The headers, cookies, and query strings that are included in the cache
-- key are automatically included in requests that CloudFront sends to the
-- origin. CloudFront sends a request when it can’t find an object in its
-- cache that matches the request’s cache key. If you want to send values
-- to the origin but /not/ include them in the cache key, use
-- @OriginRequestPolicy@.
--
-- For more information about cache policies, see
-- <https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/controlling-the-cache-key.html Controlling the cache key>
-- in the /Amazon CloudFront Developer Guide/.
module Amazonka.CloudFront.CreateCachePolicy
  ( -- * Creating a Request
    CreateCachePolicy (..),
    newCreateCachePolicy,

    -- * Request Lenses
    createCachePolicy_cachePolicyConfig,

    -- * Destructuring the Response
    CreateCachePolicyResponse (..),
    newCreateCachePolicyResponse,

    -- * Response Lenses
    createCachePolicyResponse_cachePolicy,
    createCachePolicyResponse_eTag,
    createCachePolicyResponse_location,
    createCachePolicyResponse_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:/ 'newCreateCachePolicy' smart constructor.
data CreateCachePolicy = CreateCachePolicy'
  { -- | A cache policy configuration.
    CreateCachePolicy -> CachePolicyConfig
cachePolicyConfig :: CachePolicyConfig
  }
  deriving (CreateCachePolicy -> CreateCachePolicy -> Bool
(CreateCachePolicy -> CreateCachePolicy -> Bool)
-> (CreateCachePolicy -> CreateCachePolicy -> Bool)
-> Eq CreateCachePolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateCachePolicy -> CreateCachePolicy -> Bool
$c/= :: CreateCachePolicy -> CreateCachePolicy -> Bool
== :: CreateCachePolicy -> CreateCachePolicy -> Bool
$c== :: CreateCachePolicy -> CreateCachePolicy -> Bool
Prelude.Eq, ReadPrec [CreateCachePolicy]
ReadPrec CreateCachePolicy
Int -> ReadS CreateCachePolicy
ReadS [CreateCachePolicy]
(Int -> ReadS CreateCachePolicy)
-> ReadS [CreateCachePolicy]
-> ReadPrec CreateCachePolicy
-> ReadPrec [CreateCachePolicy]
-> Read CreateCachePolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateCachePolicy]
$creadListPrec :: ReadPrec [CreateCachePolicy]
readPrec :: ReadPrec CreateCachePolicy
$creadPrec :: ReadPrec CreateCachePolicy
readList :: ReadS [CreateCachePolicy]
$creadList :: ReadS [CreateCachePolicy]
readsPrec :: Int -> ReadS CreateCachePolicy
$creadsPrec :: Int -> ReadS CreateCachePolicy
Prelude.Read, Int -> CreateCachePolicy -> ShowS
[CreateCachePolicy] -> ShowS
CreateCachePolicy -> String
(Int -> CreateCachePolicy -> ShowS)
-> (CreateCachePolicy -> String)
-> ([CreateCachePolicy] -> ShowS)
-> Show CreateCachePolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateCachePolicy] -> ShowS
$cshowList :: [CreateCachePolicy] -> ShowS
show :: CreateCachePolicy -> String
$cshow :: CreateCachePolicy -> String
showsPrec :: Int -> CreateCachePolicy -> ShowS
$cshowsPrec :: Int -> CreateCachePolicy -> ShowS
Prelude.Show, (forall x. CreateCachePolicy -> Rep CreateCachePolicy x)
-> (forall x. Rep CreateCachePolicy x -> CreateCachePolicy)
-> Generic CreateCachePolicy
forall x. Rep CreateCachePolicy x -> CreateCachePolicy
forall x. CreateCachePolicy -> Rep CreateCachePolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateCachePolicy x -> CreateCachePolicy
$cfrom :: forall x. CreateCachePolicy -> Rep CreateCachePolicy x
Prelude.Generic)

-- |
-- Create a value of 'CreateCachePolicy' 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:
--
-- 'cachePolicyConfig', 'createCachePolicy_cachePolicyConfig' - A cache policy configuration.
newCreateCachePolicy ::
  -- | 'cachePolicyConfig'
  CachePolicyConfig ->
  CreateCachePolicy
newCreateCachePolicy :: CachePolicyConfig -> CreateCachePolicy
newCreateCachePolicy CachePolicyConfig
pCachePolicyConfig_ =
  CreateCachePolicy' :: CachePolicyConfig -> CreateCachePolicy
CreateCachePolicy'
    { $sel:cachePolicyConfig:CreateCachePolicy' :: CachePolicyConfig
cachePolicyConfig =
        CachePolicyConfig
pCachePolicyConfig_
    }

-- | A cache policy configuration.
createCachePolicy_cachePolicyConfig :: Lens.Lens' CreateCachePolicy CachePolicyConfig
createCachePolicy_cachePolicyConfig :: (CachePolicyConfig -> f CachePolicyConfig)
-> CreateCachePolicy -> f CreateCachePolicy
createCachePolicy_cachePolicyConfig = (CreateCachePolicy -> CachePolicyConfig)
-> (CreateCachePolicy -> CachePolicyConfig -> CreateCachePolicy)
-> Lens
     CreateCachePolicy
     CreateCachePolicy
     CachePolicyConfig
     CachePolicyConfig
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateCachePolicy' {CachePolicyConfig
cachePolicyConfig :: CachePolicyConfig
$sel:cachePolicyConfig:CreateCachePolicy' :: CreateCachePolicy -> CachePolicyConfig
cachePolicyConfig} -> CachePolicyConfig
cachePolicyConfig) (\s :: CreateCachePolicy
s@CreateCachePolicy' {} CachePolicyConfig
a -> CreateCachePolicy
s {$sel:cachePolicyConfig:CreateCachePolicy' :: CachePolicyConfig
cachePolicyConfig = CachePolicyConfig
a} :: CreateCachePolicy)

instance Core.AWSRequest CreateCachePolicy where
  type
    AWSResponse CreateCachePolicy =
      CreateCachePolicyResponse
  request :: CreateCachePolicy -> Request CreateCachePolicy
request = Service -> CreateCachePolicy -> Request CreateCachePolicy
forall a. (ToRequest a, ToElement a) => Service -> a -> Request a
Request.postXML Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateCachePolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateCachePolicy)))
response =
    (Int
 -> ResponseHeaders
 -> [Node]
 -> Either String (AWSResponse CreateCachePolicy))
-> Logger
-> Service
-> Proxy CreateCachePolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateCachePolicy)))
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 -> Maybe Text -> Int -> CreateCachePolicyResponse
CreateCachePolicyResponse'
            (Maybe CachePolicy
 -> Maybe Text -> Maybe Text -> Int -> CreateCachePolicyResponse)
-> Either String (Maybe CachePolicy)
-> Either
     String
     (Maybe Text -> Maybe Text -> Int -> CreateCachePolicyResponse)
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 -> Maybe Text -> Int -> CreateCachePolicyResponse)
-> Either String (Maybe Text)
-> Either String (Maybe Text -> Int -> CreateCachePolicyResponse)
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 (Maybe Text -> Int -> CreateCachePolicyResponse)
-> Either String (Maybe Text)
-> Either String (Int -> CreateCachePolicyResponse)
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
"Location")
            Either String (Int -> CreateCachePolicyResponse)
-> Either String Int -> Either String CreateCachePolicyResponse
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 CreateCachePolicy

instance Prelude.NFData CreateCachePolicy

instance Core.ToElement CreateCachePolicy where
  toElement :: CreateCachePolicy -> Element
toElement CreateCachePolicy' {CachePolicyConfig
cachePolicyConfig :: CachePolicyConfig
$sel:cachePolicyConfig:CreateCachePolicy' :: CreateCachePolicy -> CachePolicyConfig
..} =
    Name -> CachePolicyConfig -> Element
forall a. ToXML a => Name -> a -> Element
Core.mkElement
      Name
"{http://cloudfront.amazonaws.com/doc/2020-05-31/}CachePolicyConfig"
      CachePolicyConfig
cachePolicyConfig

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

instance Core.ToPath CreateCachePolicy where
  toPath :: CreateCachePolicy -> ByteString
toPath = ByteString -> CreateCachePolicy -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/2020-05-31/cache-policy"

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

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

-- |
-- Create a value of 'CreateCachePolicyResponse' 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', 'createCachePolicyResponse_cachePolicy' - A cache policy.
--
-- 'eTag', 'createCachePolicyResponse_eTag' - The current version of the cache policy.
--
-- 'location', 'createCachePolicyResponse_location' - The fully qualified URI of the cache policy just created.
--
-- 'httpStatus', 'createCachePolicyResponse_httpStatus' - The response's http status code.
newCreateCachePolicyResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateCachePolicyResponse
newCreateCachePolicyResponse :: Int -> CreateCachePolicyResponse
newCreateCachePolicyResponse Int
pHttpStatus_ =
  CreateCachePolicyResponse' :: Maybe CachePolicy
-> Maybe Text -> Maybe Text -> Int -> CreateCachePolicyResponse
CreateCachePolicyResponse'
    { $sel:cachePolicy:CreateCachePolicyResponse' :: Maybe CachePolicy
cachePolicy =
        Maybe CachePolicy
forall a. Maybe a
Prelude.Nothing,
      $sel:eTag:CreateCachePolicyResponse' :: Maybe Text
eTag = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:location:CreateCachePolicyResponse' :: Maybe Text
location = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreateCachePolicyResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

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

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

-- | The fully qualified URI of the cache policy just created.
createCachePolicyResponse_location :: Lens.Lens' CreateCachePolicyResponse (Prelude.Maybe Prelude.Text)
createCachePolicyResponse_location :: (Maybe Text -> f (Maybe Text))
-> CreateCachePolicyResponse -> f CreateCachePolicyResponse
createCachePolicyResponse_location = (CreateCachePolicyResponse -> Maybe Text)
-> (CreateCachePolicyResponse
    -> Maybe Text -> CreateCachePolicyResponse)
-> Lens
     CreateCachePolicyResponse
     CreateCachePolicyResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateCachePolicyResponse' {Maybe Text
location :: Maybe Text
$sel:location:CreateCachePolicyResponse' :: CreateCachePolicyResponse -> Maybe Text
location} -> Maybe Text
location) (\s :: CreateCachePolicyResponse
s@CreateCachePolicyResponse' {} Maybe Text
a -> CreateCachePolicyResponse
s {$sel:location:CreateCachePolicyResponse' :: Maybe Text
location = Maybe Text
a} :: CreateCachePolicyResponse)

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

instance Prelude.NFData CreateCachePolicyResponse