{-# 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.CreateKeyGroup
-- 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 key group that you can use with
-- <https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/PrivateContent.html CloudFront signed URLs and signed cookies>.
--
-- To create a key group, you must specify at least one public key for the
-- key group. After you create a key group, you can reference it from one
-- or more cache behaviors. When you reference a key group in a cache
-- behavior, CloudFront requires signed URLs or signed cookies for all
-- requests that match the cache behavior. The URLs or cookies must be
-- signed with a private key whose corresponding public key is in the key
-- group. The signed URL or cookie contains information about which public
-- key CloudFront should use to verify the signature. For more information,
-- see
-- <https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/PrivateContent.html Serving private content>
-- in the /Amazon CloudFront Developer Guide/.
module Amazonka.CloudFront.CreateKeyGroup
  ( -- * Creating a Request
    CreateKeyGroup (..),
    newCreateKeyGroup,

    -- * Request Lenses
    createKeyGroup_keyGroupConfig,

    -- * Destructuring the Response
    CreateKeyGroupResponse (..),
    newCreateKeyGroupResponse,

    -- * Response Lenses
    createKeyGroupResponse_eTag,
    createKeyGroupResponse_keyGroup,
    createKeyGroupResponse_location,
    createKeyGroupResponse_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:/ 'newCreateKeyGroup' smart constructor.
data CreateKeyGroup = CreateKeyGroup'
  { -- | A key group configuration.
    CreateKeyGroup -> KeyGroupConfig
keyGroupConfig :: KeyGroupConfig
  }
  deriving (CreateKeyGroup -> CreateKeyGroup -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateKeyGroup -> CreateKeyGroup -> Bool
$c/= :: CreateKeyGroup -> CreateKeyGroup -> Bool
== :: CreateKeyGroup -> CreateKeyGroup -> Bool
$c== :: CreateKeyGroup -> CreateKeyGroup -> Bool
Prelude.Eq, ReadPrec [CreateKeyGroup]
ReadPrec CreateKeyGroup
Int -> ReadS CreateKeyGroup
ReadS [CreateKeyGroup]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateKeyGroup]
$creadListPrec :: ReadPrec [CreateKeyGroup]
readPrec :: ReadPrec CreateKeyGroup
$creadPrec :: ReadPrec CreateKeyGroup
readList :: ReadS [CreateKeyGroup]
$creadList :: ReadS [CreateKeyGroup]
readsPrec :: Int -> ReadS CreateKeyGroup
$creadsPrec :: Int -> ReadS CreateKeyGroup
Prelude.Read, Int -> CreateKeyGroup -> ShowS
[CreateKeyGroup] -> ShowS
CreateKeyGroup -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateKeyGroup] -> ShowS
$cshowList :: [CreateKeyGroup] -> ShowS
show :: CreateKeyGroup -> String
$cshow :: CreateKeyGroup -> String
showsPrec :: Int -> CreateKeyGroup -> ShowS
$cshowsPrec :: Int -> CreateKeyGroup -> ShowS
Prelude.Show, forall x. Rep CreateKeyGroup x -> CreateKeyGroup
forall x. CreateKeyGroup -> Rep CreateKeyGroup x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateKeyGroup x -> CreateKeyGroup
$cfrom :: forall x. CreateKeyGroup -> Rep CreateKeyGroup x
Prelude.Generic)

-- |
-- Create a value of 'CreateKeyGroup' 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:
--
-- 'keyGroupConfig', 'createKeyGroup_keyGroupConfig' - A key group configuration.
newCreateKeyGroup ::
  -- | 'keyGroupConfig'
  KeyGroupConfig ->
  CreateKeyGroup
newCreateKeyGroup :: KeyGroupConfig -> CreateKeyGroup
newCreateKeyGroup KeyGroupConfig
pKeyGroupConfig_ =
  CreateKeyGroup' {$sel:keyGroupConfig:CreateKeyGroup' :: KeyGroupConfig
keyGroupConfig = KeyGroupConfig
pKeyGroupConfig_}

-- | A key group configuration.
createKeyGroup_keyGroupConfig :: Lens.Lens' CreateKeyGroup KeyGroupConfig
createKeyGroup_keyGroupConfig :: Lens' CreateKeyGroup KeyGroupConfig
createKeyGroup_keyGroupConfig = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateKeyGroup' {KeyGroupConfig
keyGroupConfig :: KeyGroupConfig
$sel:keyGroupConfig:CreateKeyGroup' :: CreateKeyGroup -> KeyGroupConfig
keyGroupConfig} -> KeyGroupConfig
keyGroupConfig) (\s :: CreateKeyGroup
s@CreateKeyGroup' {} KeyGroupConfig
a -> CreateKeyGroup
s {$sel:keyGroupConfig:CreateKeyGroup' :: KeyGroupConfig
keyGroupConfig = KeyGroupConfig
a} :: CreateKeyGroup)

instance Core.AWSRequest CreateKeyGroup where
  type
    AWSResponse CreateKeyGroup =
      CreateKeyGroupResponse
  request :: (Service -> Service) -> CreateKeyGroup -> Request CreateKeyGroup
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 CreateKeyGroup
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateKeyGroup)))
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 KeyGroup -> Maybe Text -> Int -> CreateKeyGroupResponse
CreateKeyGroupResponse'
            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.<*> (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 CreateKeyGroup where
  hashWithSalt :: Int -> CreateKeyGroup -> Int
hashWithSalt Int
_salt CreateKeyGroup' {KeyGroupConfig
keyGroupConfig :: KeyGroupConfig
$sel:keyGroupConfig:CreateKeyGroup' :: CreateKeyGroup -> KeyGroupConfig
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` KeyGroupConfig
keyGroupConfig

instance Prelude.NFData CreateKeyGroup where
  rnf :: CreateKeyGroup -> ()
rnf CreateKeyGroup' {KeyGroupConfig
keyGroupConfig :: KeyGroupConfig
$sel:keyGroupConfig:CreateKeyGroup' :: CreateKeyGroup -> KeyGroupConfig
..} = forall a. NFData a => a -> ()
Prelude.rnf KeyGroupConfig
keyGroupConfig

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

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

instance Data.ToPath CreateKeyGroup where
  toPath :: CreateKeyGroup -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/2020-05-31/key-group"

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

-- | /See:/ 'newCreateKeyGroupResponse' smart constructor.
data CreateKeyGroupResponse = CreateKeyGroupResponse'
  { -- | The identifier for this version of the key group.
    CreateKeyGroupResponse -> Maybe Text
eTag :: Prelude.Maybe Prelude.Text,
    -- | The key group that was just created.
    CreateKeyGroupResponse -> Maybe KeyGroup
keyGroup :: Prelude.Maybe KeyGroup,
    -- | The URL of the key group.
    CreateKeyGroupResponse -> Maybe Text
location :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    CreateKeyGroupResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CreateKeyGroupResponse -> CreateKeyGroupResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateKeyGroupResponse -> CreateKeyGroupResponse -> Bool
$c/= :: CreateKeyGroupResponse -> CreateKeyGroupResponse -> Bool
== :: CreateKeyGroupResponse -> CreateKeyGroupResponse -> Bool
$c== :: CreateKeyGroupResponse -> CreateKeyGroupResponse -> Bool
Prelude.Eq, ReadPrec [CreateKeyGroupResponse]
ReadPrec CreateKeyGroupResponse
Int -> ReadS CreateKeyGroupResponse
ReadS [CreateKeyGroupResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateKeyGroupResponse]
$creadListPrec :: ReadPrec [CreateKeyGroupResponse]
readPrec :: ReadPrec CreateKeyGroupResponse
$creadPrec :: ReadPrec CreateKeyGroupResponse
readList :: ReadS [CreateKeyGroupResponse]
$creadList :: ReadS [CreateKeyGroupResponse]
readsPrec :: Int -> ReadS CreateKeyGroupResponse
$creadsPrec :: Int -> ReadS CreateKeyGroupResponse
Prelude.Read, Int -> CreateKeyGroupResponse -> ShowS
[CreateKeyGroupResponse] -> ShowS
CreateKeyGroupResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateKeyGroupResponse] -> ShowS
$cshowList :: [CreateKeyGroupResponse] -> ShowS
show :: CreateKeyGroupResponse -> String
$cshow :: CreateKeyGroupResponse -> String
showsPrec :: Int -> CreateKeyGroupResponse -> ShowS
$cshowsPrec :: Int -> CreateKeyGroupResponse -> ShowS
Prelude.Show, forall x. Rep CreateKeyGroupResponse x -> CreateKeyGroupResponse
forall x. CreateKeyGroupResponse -> Rep CreateKeyGroupResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateKeyGroupResponse x -> CreateKeyGroupResponse
$cfrom :: forall x. CreateKeyGroupResponse -> Rep CreateKeyGroupResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreateKeyGroupResponse' 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', 'createKeyGroupResponse_eTag' - The identifier for this version of the key group.
--
-- 'keyGroup', 'createKeyGroupResponse_keyGroup' - The key group that was just created.
--
-- 'location', 'createKeyGroupResponse_location' - The URL of the key group.
--
-- 'httpStatus', 'createKeyGroupResponse_httpStatus' - The response's http status code.
newCreateKeyGroupResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateKeyGroupResponse
newCreateKeyGroupResponse :: Int -> CreateKeyGroupResponse
newCreateKeyGroupResponse Int
pHttpStatus_ =
  CreateKeyGroupResponse'
    { $sel:eTag:CreateKeyGroupResponse' :: Maybe Text
eTag = forall a. Maybe a
Prelude.Nothing,
      $sel:keyGroup:CreateKeyGroupResponse' :: Maybe KeyGroup
keyGroup = forall a. Maybe a
Prelude.Nothing,
      $sel:location:CreateKeyGroupResponse' :: Maybe Text
location = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreateKeyGroupResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The identifier for this version of the key group.
createKeyGroupResponse_eTag :: Lens.Lens' CreateKeyGroupResponse (Prelude.Maybe Prelude.Text)
createKeyGroupResponse_eTag :: Lens' CreateKeyGroupResponse (Maybe Text)
createKeyGroupResponse_eTag = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateKeyGroupResponse' {Maybe Text
eTag :: Maybe Text
$sel:eTag:CreateKeyGroupResponse' :: CreateKeyGroupResponse -> Maybe Text
eTag} -> Maybe Text
eTag) (\s :: CreateKeyGroupResponse
s@CreateKeyGroupResponse' {} Maybe Text
a -> CreateKeyGroupResponse
s {$sel:eTag:CreateKeyGroupResponse' :: Maybe Text
eTag = Maybe Text
a} :: CreateKeyGroupResponse)

-- | The key group that was just created.
createKeyGroupResponse_keyGroup :: Lens.Lens' CreateKeyGroupResponse (Prelude.Maybe KeyGroup)
createKeyGroupResponse_keyGroup :: Lens' CreateKeyGroupResponse (Maybe KeyGroup)
createKeyGroupResponse_keyGroup = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateKeyGroupResponse' {Maybe KeyGroup
keyGroup :: Maybe KeyGroup
$sel:keyGroup:CreateKeyGroupResponse' :: CreateKeyGroupResponse -> Maybe KeyGroup
keyGroup} -> Maybe KeyGroup
keyGroup) (\s :: CreateKeyGroupResponse
s@CreateKeyGroupResponse' {} Maybe KeyGroup
a -> CreateKeyGroupResponse
s {$sel:keyGroup:CreateKeyGroupResponse' :: Maybe KeyGroup
keyGroup = Maybe KeyGroup
a} :: CreateKeyGroupResponse)

-- | The URL of the key group.
createKeyGroupResponse_location :: Lens.Lens' CreateKeyGroupResponse (Prelude.Maybe Prelude.Text)
createKeyGroupResponse_location :: Lens' CreateKeyGroupResponse (Maybe Text)
createKeyGroupResponse_location = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateKeyGroupResponse' {Maybe Text
location :: Maybe Text
$sel:location:CreateKeyGroupResponse' :: CreateKeyGroupResponse -> Maybe Text
location} -> Maybe Text
location) (\s :: CreateKeyGroupResponse
s@CreateKeyGroupResponse' {} Maybe Text
a -> CreateKeyGroupResponse
s {$sel:location:CreateKeyGroupResponse' :: Maybe Text
location = Maybe Text
a} :: CreateKeyGroupResponse)

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

instance Prelude.NFData CreateKeyGroupResponse where
  rnf :: CreateKeyGroupResponse -> ()
rnf CreateKeyGroupResponse' {Int
Maybe Text
Maybe KeyGroup
httpStatus :: Int
location :: Maybe Text
keyGroup :: Maybe KeyGroup
eTag :: Maybe Text
$sel:httpStatus:CreateKeyGroupResponse' :: CreateKeyGroupResponse -> Int
$sel:location:CreateKeyGroupResponse' :: CreateKeyGroupResponse -> Maybe Text
$sel:keyGroup:CreateKeyGroupResponse' :: CreateKeyGroupResponse -> Maybe KeyGroup
$sel:eTag:CreateKeyGroupResponse' :: CreateKeyGroupResponse -> 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 KeyGroup
keyGroup
      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