{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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.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:/ 'newCreateCachePolicy' smart constructor.
data CreateCachePolicy = CreateCachePolicy'
  { -- | A cache policy configuration.
    CreateCachePolicy -> CachePolicyConfig
cachePolicyConfig :: CachePolicyConfig
  }
  deriving (CreateCachePolicy -> CreateCachePolicy -> Bool
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]
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
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. 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'
    { $sel:cachePolicyConfig:CreateCachePolicy' :: CachePolicyConfig
cachePolicyConfig =
        CachePolicyConfig
pCachePolicyConfig_
    }

-- | A cache policy configuration.
createCachePolicy_cachePolicyConfig :: Lens.Lens' CreateCachePolicy CachePolicyConfig
createCachePolicy_cachePolicyConfig :: Lens' CreateCachePolicy CachePolicyConfig
createCachePolicy_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 :: (Service -> Service)
-> CreateCachePolicy -> Request CreateCachePolicy
request Service -> Service
overrides =
    forall a. (ToRequest a, ToElement a) => Service -> a -> Request a
Request.postXML (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy CreateCachePolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateCachePolicy)))
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 CachePolicy
-> Maybe Text -> Maybe Text -> Int -> CreateCachePolicyResponse
CreateCachePolicyResponse'
            forall (f :: * -> *) a b. Functor 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.<*> (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.<*> (ResponseHeaders
h forall a.
FromText a =>
ResponseHeaders -> HeaderName -> Either String (Maybe a)
Data..#? HeaderName
"Location")
            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 CreateCachePolicy where
  hashWithSalt :: Int -> CreateCachePolicy -> Int
hashWithSalt Int
_salt CreateCachePolicy' {CachePolicyConfig
cachePolicyConfig :: CachePolicyConfig
$sel:cachePolicyConfig:CreateCachePolicy' :: CreateCachePolicy -> CachePolicyConfig
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` CachePolicyConfig
cachePolicyConfig

instance Prelude.NFData CreateCachePolicy where
  rnf :: CreateCachePolicy -> ()
rnf CreateCachePolicy' {CachePolicyConfig
cachePolicyConfig :: CachePolicyConfig
$sel:cachePolicyConfig:CreateCachePolicy' :: CreateCachePolicy -> CachePolicyConfig
..} =
    forall a. NFData a => a -> ()
Prelude.rnf CachePolicyConfig
cachePolicyConfig

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

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

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

instance Data.ToQuery CreateCachePolicy where
  toQuery :: CreateCachePolicy -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const 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
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]
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
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.
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'
    { $sel:cachePolicy:CreateCachePolicyResponse' :: Maybe CachePolicy
cachePolicy =
        forall a. Maybe a
Prelude.Nothing,
      $sel:eTag:CreateCachePolicyResponse' :: Maybe Text
eTag = forall a. Maybe a
Prelude.Nothing,
      $sel:location:CreateCachePolicyResponse' :: Maybe Text
location = 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 :: Lens' CreateCachePolicyResponse (Maybe CachePolicy)
createCachePolicyResponse_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 :: Lens' CreateCachePolicyResponse (Maybe Text)
createCachePolicyResponse_eTag = 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 :: Lens' CreateCachePolicyResponse (Maybe Text)
createCachePolicyResponse_location = 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 :: Lens' CreateCachePolicyResponse Int
createCachePolicyResponse_httpStatus = 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 where
  rnf :: CreateCachePolicyResponse -> ()
rnf CreateCachePolicyResponse' {Int
Maybe Text
Maybe CachePolicy
httpStatus :: Int
location :: Maybe Text
eTag :: Maybe Text
cachePolicy :: Maybe CachePolicy
$sel:httpStatus:CreateCachePolicyResponse' :: CreateCachePolicyResponse -> Int
$sel:location:CreateCachePolicyResponse' :: CreateCachePolicyResponse -> Maybe Text
$sel:eTag:CreateCachePolicyResponse' :: CreateCachePolicyResponse -> Maybe Text
$sel:cachePolicy:CreateCachePolicyResponse' :: CreateCachePolicyResponse -> Maybe CachePolicy
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe CachePolicy
cachePolicy
      seq :: forall a b. a -> b -> b
`Prelude.seq` 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 Text
location
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus