{-# 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-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 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_location,
    createKeyGroupResponse_keyGroup,
    createKeyGroupResponse_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:/ 'newCreateKeyGroup' smart constructor.
data CreateKeyGroup = CreateKeyGroup'
  { -- | A key group configuration.
    CreateKeyGroup -> KeyGroupConfig
keyGroupConfig :: KeyGroupConfig
  }
  deriving (CreateKeyGroup -> CreateKeyGroup -> Bool
(CreateKeyGroup -> CreateKeyGroup -> Bool)
-> (CreateKeyGroup -> CreateKeyGroup -> Bool) -> Eq CreateKeyGroup
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]
(Int -> ReadS CreateKeyGroup)
-> ReadS [CreateKeyGroup]
-> ReadPrec CreateKeyGroup
-> ReadPrec [CreateKeyGroup]
-> Read 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
(Int -> CreateKeyGroup -> ShowS)
-> (CreateKeyGroup -> String)
-> ([CreateKeyGroup] -> ShowS)
-> Show CreateKeyGroup
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. CreateKeyGroup -> Rep CreateKeyGroup x)
-> (forall x. Rep CreateKeyGroup x -> CreateKeyGroup)
-> Generic CreateKeyGroup
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' :: KeyGroupConfig -> CreateKeyGroup
CreateKeyGroup' {$sel:keyGroupConfig:CreateKeyGroup' :: KeyGroupConfig
keyGroupConfig = KeyGroupConfig
pKeyGroupConfig_}

-- | A key group configuration.
createKeyGroup_keyGroupConfig :: Lens.Lens' CreateKeyGroup KeyGroupConfig
createKeyGroup_keyGroupConfig :: (KeyGroupConfig -> f KeyGroupConfig)
-> CreateKeyGroup -> f CreateKeyGroup
createKeyGroup_keyGroupConfig = (CreateKeyGroup -> KeyGroupConfig)
-> (CreateKeyGroup -> KeyGroupConfig -> CreateKeyGroup)
-> Lens CreateKeyGroup CreateKeyGroup KeyGroupConfig 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 :: CreateKeyGroup -> Request CreateKeyGroup
request = Service -> CreateKeyGroup -> Request CreateKeyGroup
forall a. (ToRequest a, ToElement a) => Service -> a -> Request a
Request.postXML Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateKeyGroup
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateKeyGroup)))
response =
    (Int
 -> ResponseHeaders
 -> [Node]
 -> Either String (AWSResponse CreateKeyGroup))
-> Logger
-> Service
-> Proxy CreateKeyGroup
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateKeyGroup)))
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 Text -> Maybe KeyGroup -> Int -> CreateKeyGroupResponse
CreateKeyGroupResponse'
            (Maybe Text
 -> Maybe Text -> Maybe KeyGroup -> Int -> CreateKeyGroupResponse)
-> Either String (Maybe Text)
-> Either
     String
     (Maybe Text -> Maybe KeyGroup -> Int -> CreateKeyGroupResponse)
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 Text -> Maybe KeyGroup -> Int -> CreateKeyGroupResponse)
-> Either String (Maybe Text)
-> Either String (Maybe KeyGroup -> Int -> CreateKeyGroupResponse)
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 (Maybe KeyGroup -> Int -> CreateKeyGroupResponse)
-> Either String (Maybe KeyGroup)
-> Either String (Int -> CreateKeyGroupResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node] -> Either String (Maybe KeyGroup)
forall a. FromXML a => [Node] -> Either String a
Core.parseXML [Node]
x)
            Either String (Int -> CreateKeyGroupResponse)
-> Either String Int -> Either String CreateKeyGroupResponse
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 CreateKeyGroup

instance Prelude.NFData CreateKeyGroup

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

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

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

instance Core.ToQuery CreateKeyGroup where
  toQuery :: CreateKeyGroup -> QueryString
toQuery = QueryString -> CreateKeyGroup -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
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 URL of the key group.
    CreateKeyGroupResponse -> Maybe Text
location :: Prelude.Maybe Prelude.Text,
    -- | The key group that was just created.
    CreateKeyGroupResponse -> Maybe KeyGroup
keyGroup :: Prelude.Maybe KeyGroup,
    -- | The response's http status code.
    CreateKeyGroupResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CreateKeyGroupResponse -> CreateKeyGroupResponse -> Bool
(CreateKeyGroupResponse -> CreateKeyGroupResponse -> Bool)
-> (CreateKeyGroupResponse -> CreateKeyGroupResponse -> Bool)
-> Eq CreateKeyGroupResponse
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]
(Int -> ReadS CreateKeyGroupResponse)
-> ReadS [CreateKeyGroupResponse]
-> ReadPrec CreateKeyGroupResponse
-> ReadPrec [CreateKeyGroupResponse]
-> Read 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
(Int -> CreateKeyGroupResponse -> ShowS)
-> (CreateKeyGroupResponse -> String)
-> ([CreateKeyGroupResponse] -> ShowS)
-> Show CreateKeyGroupResponse
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. CreateKeyGroupResponse -> Rep CreateKeyGroupResponse x)
-> (forall x.
    Rep CreateKeyGroupResponse x -> CreateKeyGroupResponse)
-> Generic CreateKeyGroupResponse
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.
--
-- 'location', 'createKeyGroupResponse_location' - The URL of the key group.
--
-- 'keyGroup', 'createKeyGroupResponse_keyGroup' - The key group that was just created.
--
-- 'httpStatus', 'createKeyGroupResponse_httpStatus' - The response's http status code.
newCreateKeyGroupResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateKeyGroupResponse
newCreateKeyGroupResponse :: Int -> CreateKeyGroupResponse
newCreateKeyGroupResponse Int
pHttpStatus_ =
  CreateKeyGroupResponse' :: Maybe Text
-> Maybe Text -> Maybe KeyGroup -> Int -> CreateKeyGroupResponse
CreateKeyGroupResponse'
    { $sel:eTag:CreateKeyGroupResponse' :: Maybe Text
eTag = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:location:CreateKeyGroupResponse' :: Maybe Text
location = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:keyGroup:CreateKeyGroupResponse' :: Maybe KeyGroup
keyGroup = Maybe KeyGroup
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 :: (Maybe Text -> f (Maybe Text))
-> CreateKeyGroupResponse -> f CreateKeyGroupResponse
createKeyGroupResponse_eTag = (CreateKeyGroupResponse -> Maybe Text)
-> (CreateKeyGroupResponse -> Maybe Text -> CreateKeyGroupResponse)
-> Lens
     CreateKeyGroupResponse
     CreateKeyGroupResponse
     (Maybe Text)
     (Maybe Text)
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 URL of the key group.
createKeyGroupResponse_location :: Lens.Lens' CreateKeyGroupResponse (Prelude.Maybe Prelude.Text)
createKeyGroupResponse_location :: (Maybe Text -> f (Maybe Text))
-> CreateKeyGroupResponse -> f CreateKeyGroupResponse
createKeyGroupResponse_location = (CreateKeyGroupResponse -> Maybe Text)
-> (CreateKeyGroupResponse -> Maybe Text -> CreateKeyGroupResponse)
-> Lens
     CreateKeyGroupResponse
     CreateKeyGroupResponse
     (Maybe Text)
     (Maybe Text)
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 key group that was just created.
createKeyGroupResponse_keyGroup :: Lens.Lens' CreateKeyGroupResponse (Prelude.Maybe KeyGroup)
createKeyGroupResponse_keyGroup :: (Maybe KeyGroup -> f (Maybe KeyGroup))
-> CreateKeyGroupResponse -> f CreateKeyGroupResponse
createKeyGroupResponse_keyGroup = (CreateKeyGroupResponse -> Maybe KeyGroup)
-> (CreateKeyGroupResponse
    -> Maybe KeyGroup -> CreateKeyGroupResponse)
-> Lens
     CreateKeyGroupResponse
     CreateKeyGroupResponse
     (Maybe KeyGroup)
     (Maybe 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 response's http status code.
createKeyGroupResponse_httpStatus :: Lens.Lens' CreateKeyGroupResponse Prelude.Int
createKeyGroupResponse_httpStatus :: (Int -> f Int)
-> CreateKeyGroupResponse -> f CreateKeyGroupResponse
createKeyGroupResponse_httpStatus = (CreateKeyGroupResponse -> Int)
-> (CreateKeyGroupResponse -> Int -> CreateKeyGroupResponse)
-> Lens CreateKeyGroupResponse CreateKeyGroupResponse Int Int
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