{-# 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.GetKeyGroupConfig
-- 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 a key group configuration.
--
-- To get a key group configuration, you must provide the key group’s
-- identifier. If the key group is referenced in a distribution’s cache
-- behavior, you can get the key group’s identifier using
-- @ListDistributions@ or @GetDistribution@. If the key group is not
-- referenced in a cache behavior, you can get the identifier using
-- @ListKeyGroups@.
module Amazonka.CloudFront.GetKeyGroupConfig
  ( -- * Creating a Request
    GetKeyGroupConfig (..),
    newGetKeyGroupConfig,

    -- * Request Lenses
    getKeyGroupConfig_id,

    -- * Destructuring the Response
    GetKeyGroupConfigResponse (..),
    newGetKeyGroupConfigResponse,

    -- * Response Lenses
    getKeyGroupConfigResponse_eTag,
    getKeyGroupConfigResponse_keyGroupConfig,
    getKeyGroupConfigResponse_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:/ 'newGetKeyGroupConfig' smart constructor.
data GetKeyGroupConfig = GetKeyGroupConfig'
  { -- | The identifier of the key group whose configuration you are getting. To
    -- get the identifier, use @ListKeyGroups@.
    GetKeyGroupConfig -> Text
id :: Prelude.Text
  }
  deriving (GetKeyGroupConfig -> GetKeyGroupConfig -> Bool
(GetKeyGroupConfig -> GetKeyGroupConfig -> Bool)
-> (GetKeyGroupConfig -> GetKeyGroupConfig -> Bool)
-> Eq GetKeyGroupConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetKeyGroupConfig -> GetKeyGroupConfig -> Bool
$c/= :: GetKeyGroupConfig -> GetKeyGroupConfig -> Bool
== :: GetKeyGroupConfig -> GetKeyGroupConfig -> Bool
$c== :: GetKeyGroupConfig -> GetKeyGroupConfig -> Bool
Prelude.Eq, ReadPrec [GetKeyGroupConfig]
ReadPrec GetKeyGroupConfig
Int -> ReadS GetKeyGroupConfig
ReadS [GetKeyGroupConfig]
(Int -> ReadS GetKeyGroupConfig)
-> ReadS [GetKeyGroupConfig]
-> ReadPrec GetKeyGroupConfig
-> ReadPrec [GetKeyGroupConfig]
-> Read GetKeyGroupConfig
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetKeyGroupConfig]
$creadListPrec :: ReadPrec [GetKeyGroupConfig]
readPrec :: ReadPrec GetKeyGroupConfig
$creadPrec :: ReadPrec GetKeyGroupConfig
readList :: ReadS [GetKeyGroupConfig]
$creadList :: ReadS [GetKeyGroupConfig]
readsPrec :: Int -> ReadS GetKeyGroupConfig
$creadsPrec :: Int -> ReadS GetKeyGroupConfig
Prelude.Read, Int -> GetKeyGroupConfig -> ShowS
[GetKeyGroupConfig] -> ShowS
GetKeyGroupConfig -> String
(Int -> GetKeyGroupConfig -> ShowS)
-> (GetKeyGroupConfig -> String)
-> ([GetKeyGroupConfig] -> ShowS)
-> Show GetKeyGroupConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetKeyGroupConfig] -> ShowS
$cshowList :: [GetKeyGroupConfig] -> ShowS
show :: GetKeyGroupConfig -> String
$cshow :: GetKeyGroupConfig -> String
showsPrec :: Int -> GetKeyGroupConfig -> ShowS
$cshowsPrec :: Int -> GetKeyGroupConfig -> ShowS
Prelude.Show, (forall x. GetKeyGroupConfig -> Rep GetKeyGroupConfig x)
-> (forall x. Rep GetKeyGroupConfig x -> GetKeyGroupConfig)
-> Generic GetKeyGroupConfig
forall x. Rep GetKeyGroupConfig x -> GetKeyGroupConfig
forall x. GetKeyGroupConfig -> Rep GetKeyGroupConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetKeyGroupConfig x -> GetKeyGroupConfig
$cfrom :: forall x. GetKeyGroupConfig -> Rep GetKeyGroupConfig x
Prelude.Generic)

-- |
-- Create a value of 'GetKeyGroupConfig' 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', 'getKeyGroupConfig_id' - The identifier of the key group whose configuration you are getting. To
-- get the identifier, use @ListKeyGroups@.
newGetKeyGroupConfig ::
  -- | 'id'
  Prelude.Text ->
  GetKeyGroupConfig
newGetKeyGroupConfig :: Text -> GetKeyGroupConfig
newGetKeyGroupConfig Text
pId_ =
  GetKeyGroupConfig' :: Text -> GetKeyGroupConfig
GetKeyGroupConfig' {$sel:id:GetKeyGroupConfig' :: Text
id = Text
pId_}

-- | The identifier of the key group whose configuration you are getting. To
-- get the identifier, use @ListKeyGroups@.
getKeyGroupConfig_id :: Lens.Lens' GetKeyGroupConfig Prelude.Text
getKeyGroupConfig_id :: (Text -> f Text) -> GetKeyGroupConfig -> f GetKeyGroupConfig
getKeyGroupConfig_id = (GetKeyGroupConfig -> Text)
-> (GetKeyGroupConfig -> Text -> GetKeyGroupConfig)
-> Lens GetKeyGroupConfig GetKeyGroupConfig Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetKeyGroupConfig' {Text
id :: Text
$sel:id:GetKeyGroupConfig' :: GetKeyGroupConfig -> Text
id} -> Text
id) (\s :: GetKeyGroupConfig
s@GetKeyGroupConfig' {} Text
a -> GetKeyGroupConfig
s {$sel:id:GetKeyGroupConfig' :: Text
id = Text
a} :: GetKeyGroupConfig)

instance Core.AWSRequest GetKeyGroupConfig where
  type
    AWSResponse GetKeyGroupConfig =
      GetKeyGroupConfigResponse
  request :: GetKeyGroupConfig -> Request GetKeyGroupConfig
request = Service -> GetKeyGroupConfig -> Request GetKeyGroupConfig
forall a. ToRequest a => Service -> a -> Request a
Request.get Service
defaultService
  response :: Logger
-> Service
-> Proxy GetKeyGroupConfig
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetKeyGroupConfig)))
response =
    (Int
 -> ResponseHeaders
 -> [Node]
 -> Either String (AWSResponse GetKeyGroupConfig))
-> Logger
-> Service
-> Proxy GetKeyGroupConfig
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetKeyGroupConfig)))
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 KeyGroupConfig -> Int -> GetKeyGroupConfigResponse
GetKeyGroupConfigResponse'
            (Maybe Text
 -> Maybe KeyGroupConfig -> Int -> GetKeyGroupConfigResponse)
-> Either String (Maybe Text)
-> Either
     String (Maybe KeyGroupConfig -> Int -> GetKeyGroupConfigResponse)
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 KeyGroupConfig -> Int -> GetKeyGroupConfigResponse)
-> Either String (Maybe KeyGroupConfig)
-> Either String (Int -> GetKeyGroupConfigResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node] -> Either String (Maybe KeyGroupConfig)
forall a. FromXML a => [Node] -> Either String a
Core.parseXML [Node]
x)
            Either String (Int -> GetKeyGroupConfigResponse)
-> Either String Int -> Either String GetKeyGroupConfigResponse
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 GetKeyGroupConfig

instance Prelude.NFData GetKeyGroupConfig

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

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

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

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

-- |
-- Create a value of 'GetKeyGroupConfigResponse' 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', 'getKeyGroupConfigResponse_eTag' - The identifier for this version of the key group.
--
-- 'keyGroupConfig', 'getKeyGroupConfigResponse_keyGroupConfig' - The key group configuration.
--
-- 'httpStatus', 'getKeyGroupConfigResponse_httpStatus' - The response's http status code.
newGetKeyGroupConfigResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetKeyGroupConfigResponse
newGetKeyGroupConfigResponse :: Int -> GetKeyGroupConfigResponse
newGetKeyGroupConfigResponse Int
pHttpStatus_ =
  GetKeyGroupConfigResponse' :: Maybe Text
-> Maybe KeyGroupConfig -> Int -> GetKeyGroupConfigResponse
GetKeyGroupConfigResponse'
    { $sel:eTag:GetKeyGroupConfigResponse' :: Maybe Text
eTag = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:keyGroupConfig:GetKeyGroupConfigResponse' :: Maybe KeyGroupConfig
keyGroupConfig = Maybe KeyGroupConfig
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetKeyGroupConfigResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

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

-- | The key group configuration.
getKeyGroupConfigResponse_keyGroupConfig :: Lens.Lens' GetKeyGroupConfigResponse (Prelude.Maybe KeyGroupConfig)
getKeyGroupConfigResponse_keyGroupConfig :: (Maybe KeyGroupConfig -> f (Maybe KeyGroupConfig))
-> GetKeyGroupConfigResponse -> f GetKeyGroupConfigResponse
getKeyGroupConfigResponse_keyGroupConfig = (GetKeyGroupConfigResponse -> Maybe KeyGroupConfig)
-> (GetKeyGroupConfigResponse
    -> Maybe KeyGroupConfig -> GetKeyGroupConfigResponse)
-> Lens
     GetKeyGroupConfigResponse
     GetKeyGroupConfigResponse
     (Maybe KeyGroupConfig)
     (Maybe KeyGroupConfig)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetKeyGroupConfigResponse' {Maybe KeyGroupConfig
keyGroupConfig :: Maybe KeyGroupConfig
$sel:keyGroupConfig:GetKeyGroupConfigResponse' :: GetKeyGroupConfigResponse -> Maybe KeyGroupConfig
keyGroupConfig} -> Maybe KeyGroupConfig
keyGroupConfig) (\s :: GetKeyGroupConfigResponse
s@GetKeyGroupConfigResponse' {} Maybe KeyGroupConfig
a -> GetKeyGroupConfigResponse
s {$sel:keyGroupConfig:GetKeyGroupConfigResponse' :: Maybe KeyGroupConfig
keyGroupConfig = Maybe KeyGroupConfig
a} :: GetKeyGroupConfigResponse)

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

instance Prelude.NFData GetKeyGroupConfigResponse