{-# 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.DescribeFunction
-- 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 configuration information and metadata about a CloudFront function,
-- but not the function’s code. To get a function’s code, use
-- @GetFunction@.
--
-- To get configuration information and metadata about a function, you must
-- provide the function’s name and stage. To get these values, you can use
-- @ListFunctions@.
module Amazonka.CloudFront.DescribeFunction
  ( -- * Creating a Request
    DescribeFunction (..),
    newDescribeFunction,

    -- * Request Lenses
    describeFunction_stage,
    describeFunction_name,

    -- * Destructuring the Response
    DescribeFunctionResponse (..),
    newDescribeFunctionResponse,

    -- * Response Lenses
    describeFunctionResponse_eTag,
    describeFunctionResponse_functionSummary,
    describeFunctionResponse_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:/ 'newDescribeFunction' smart constructor.
data DescribeFunction = DescribeFunction'
  { -- | The function’s stage, either @DEVELOPMENT@ or @LIVE@.
    DescribeFunction -> Maybe FunctionStage
stage :: Prelude.Maybe FunctionStage,
    -- | The name of the function that you are getting information about.
    DescribeFunction -> Text
name :: Prelude.Text
  }
  deriving (DescribeFunction -> DescribeFunction -> Bool
(DescribeFunction -> DescribeFunction -> Bool)
-> (DescribeFunction -> DescribeFunction -> Bool)
-> Eq DescribeFunction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DescribeFunction -> DescribeFunction -> Bool
$c/= :: DescribeFunction -> DescribeFunction -> Bool
== :: DescribeFunction -> DescribeFunction -> Bool
$c== :: DescribeFunction -> DescribeFunction -> Bool
Prelude.Eq, ReadPrec [DescribeFunction]
ReadPrec DescribeFunction
Int -> ReadS DescribeFunction
ReadS [DescribeFunction]
(Int -> ReadS DescribeFunction)
-> ReadS [DescribeFunction]
-> ReadPrec DescribeFunction
-> ReadPrec [DescribeFunction]
-> Read DescribeFunction
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DescribeFunction]
$creadListPrec :: ReadPrec [DescribeFunction]
readPrec :: ReadPrec DescribeFunction
$creadPrec :: ReadPrec DescribeFunction
readList :: ReadS [DescribeFunction]
$creadList :: ReadS [DescribeFunction]
readsPrec :: Int -> ReadS DescribeFunction
$creadsPrec :: Int -> ReadS DescribeFunction
Prelude.Read, Int -> DescribeFunction -> ShowS
[DescribeFunction] -> ShowS
DescribeFunction -> String
(Int -> DescribeFunction -> ShowS)
-> (DescribeFunction -> String)
-> ([DescribeFunction] -> ShowS)
-> Show DescribeFunction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DescribeFunction] -> ShowS
$cshowList :: [DescribeFunction] -> ShowS
show :: DescribeFunction -> String
$cshow :: DescribeFunction -> String
showsPrec :: Int -> DescribeFunction -> ShowS
$cshowsPrec :: Int -> DescribeFunction -> ShowS
Prelude.Show, (forall x. DescribeFunction -> Rep DescribeFunction x)
-> (forall x. Rep DescribeFunction x -> DescribeFunction)
-> Generic DescribeFunction
forall x. Rep DescribeFunction x -> DescribeFunction
forall x. DescribeFunction -> Rep DescribeFunction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DescribeFunction x -> DescribeFunction
$cfrom :: forall x. DescribeFunction -> Rep DescribeFunction x
Prelude.Generic)

-- |
-- Create a value of 'DescribeFunction' 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:
--
-- 'stage', 'describeFunction_stage' - The function’s stage, either @DEVELOPMENT@ or @LIVE@.
--
-- 'name', 'describeFunction_name' - The name of the function that you are getting information about.
newDescribeFunction ::
  -- | 'name'
  Prelude.Text ->
  DescribeFunction
newDescribeFunction :: Text -> DescribeFunction
newDescribeFunction Text
pName_ =
  DescribeFunction' :: Maybe FunctionStage -> Text -> DescribeFunction
DescribeFunction'
    { $sel:stage:DescribeFunction' :: Maybe FunctionStage
stage = Maybe FunctionStage
forall a. Maybe a
Prelude.Nothing,
      $sel:name:DescribeFunction' :: Text
name = Text
pName_
    }

-- | The function’s stage, either @DEVELOPMENT@ or @LIVE@.
describeFunction_stage :: Lens.Lens' DescribeFunction (Prelude.Maybe FunctionStage)
describeFunction_stage :: (Maybe FunctionStage -> f (Maybe FunctionStage))
-> DescribeFunction -> f DescribeFunction
describeFunction_stage = (DescribeFunction -> Maybe FunctionStage)
-> (DescribeFunction -> Maybe FunctionStage -> DescribeFunction)
-> Lens
     DescribeFunction
     DescribeFunction
     (Maybe FunctionStage)
     (Maybe FunctionStage)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeFunction' {Maybe FunctionStage
stage :: Maybe FunctionStage
$sel:stage:DescribeFunction' :: DescribeFunction -> Maybe FunctionStage
stage} -> Maybe FunctionStage
stage) (\s :: DescribeFunction
s@DescribeFunction' {} Maybe FunctionStage
a -> DescribeFunction
s {$sel:stage:DescribeFunction' :: Maybe FunctionStage
stage = Maybe FunctionStage
a} :: DescribeFunction)

-- | The name of the function that you are getting information about.
describeFunction_name :: Lens.Lens' DescribeFunction Prelude.Text
describeFunction_name :: (Text -> f Text) -> DescribeFunction -> f DescribeFunction
describeFunction_name = (DescribeFunction -> Text)
-> (DescribeFunction -> Text -> DescribeFunction)
-> Lens DescribeFunction DescribeFunction Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeFunction' {Text
name :: Text
$sel:name:DescribeFunction' :: DescribeFunction -> Text
name} -> Text
name) (\s :: DescribeFunction
s@DescribeFunction' {} Text
a -> DescribeFunction
s {$sel:name:DescribeFunction' :: Text
name = Text
a} :: DescribeFunction)

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

instance Prelude.NFData DescribeFunction

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

instance Core.ToPath DescribeFunction where
  toPath :: DescribeFunction -> ByteString
toPath DescribeFunction' {Maybe FunctionStage
Text
name :: Text
stage :: Maybe FunctionStage
$sel:name:DescribeFunction' :: DescribeFunction -> Text
$sel:stage:DescribeFunction' :: DescribeFunction -> Maybe FunctionStage
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/2020-05-31/function/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
name,
        ByteString
"/describe"
      ]

instance Core.ToQuery DescribeFunction where
  toQuery :: DescribeFunction -> QueryString
toQuery DescribeFunction' {Maybe FunctionStage
Text
name :: Text
stage :: Maybe FunctionStage
$sel:name:DescribeFunction' :: DescribeFunction -> Text
$sel:stage:DescribeFunction' :: DescribeFunction -> Maybe FunctionStage
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat [ByteString
"Stage" ByteString -> Maybe FunctionStage -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe FunctionStage
stage]

-- | /See:/ 'newDescribeFunctionResponse' smart constructor.
data DescribeFunctionResponse = DescribeFunctionResponse'
  { -- | The version identifier for the current version of the CloudFront
    -- function.
    DescribeFunctionResponse -> Maybe Text
eTag :: Prelude.Maybe Prelude.Text,
    -- | Contains configuration information and metadata about a CloudFront
    -- function.
    DescribeFunctionResponse -> Maybe FunctionSummary
functionSummary :: Prelude.Maybe FunctionSummary,
    -- | The response's http status code.
    DescribeFunctionResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (DescribeFunctionResponse -> DescribeFunctionResponse -> Bool
(DescribeFunctionResponse -> DescribeFunctionResponse -> Bool)
-> (DescribeFunctionResponse -> DescribeFunctionResponse -> Bool)
-> Eq DescribeFunctionResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DescribeFunctionResponse -> DescribeFunctionResponse -> Bool
$c/= :: DescribeFunctionResponse -> DescribeFunctionResponse -> Bool
== :: DescribeFunctionResponse -> DescribeFunctionResponse -> Bool
$c== :: DescribeFunctionResponse -> DescribeFunctionResponse -> Bool
Prelude.Eq, ReadPrec [DescribeFunctionResponse]
ReadPrec DescribeFunctionResponse
Int -> ReadS DescribeFunctionResponse
ReadS [DescribeFunctionResponse]
(Int -> ReadS DescribeFunctionResponse)
-> ReadS [DescribeFunctionResponse]
-> ReadPrec DescribeFunctionResponse
-> ReadPrec [DescribeFunctionResponse]
-> Read DescribeFunctionResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DescribeFunctionResponse]
$creadListPrec :: ReadPrec [DescribeFunctionResponse]
readPrec :: ReadPrec DescribeFunctionResponse
$creadPrec :: ReadPrec DescribeFunctionResponse
readList :: ReadS [DescribeFunctionResponse]
$creadList :: ReadS [DescribeFunctionResponse]
readsPrec :: Int -> ReadS DescribeFunctionResponse
$creadsPrec :: Int -> ReadS DescribeFunctionResponse
Prelude.Read, Int -> DescribeFunctionResponse -> ShowS
[DescribeFunctionResponse] -> ShowS
DescribeFunctionResponse -> String
(Int -> DescribeFunctionResponse -> ShowS)
-> (DescribeFunctionResponse -> String)
-> ([DescribeFunctionResponse] -> ShowS)
-> Show DescribeFunctionResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DescribeFunctionResponse] -> ShowS
$cshowList :: [DescribeFunctionResponse] -> ShowS
show :: DescribeFunctionResponse -> String
$cshow :: DescribeFunctionResponse -> String
showsPrec :: Int -> DescribeFunctionResponse -> ShowS
$cshowsPrec :: Int -> DescribeFunctionResponse -> ShowS
Prelude.Show, (forall x.
 DescribeFunctionResponse -> Rep DescribeFunctionResponse x)
-> (forall x.
    Rep DescribeFunctionResponse x -> DescribeFunctionResponse)
-> Generic DescribeFunctionResponse
forall x.
Rep DescribeFunctionResponse x -> DescribeFunctionResponse
forall x.
DescribeFunctionResponse -> Rep DescribeFunctionResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep DescribeFunctionResponse x -> DescribeFunctionResponse
$cfrom :: forall x.
DescribeFunctionResponse -> Rep DescribeFunctionResponse x
Prelude.Generic)

-- |
-- Create a value of 'DescribeFunctionResponse' 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', 'describeFunctionResponse_eTag' - The version identifier for the current version of the CloudFront
-- function.
--
-- 'functionSummary', 'describeFunctionResponse_functionSummary' - Contains configuration information and metadata about a CloudFront
-- function.
--
-- 'httpStatus', 'describeFunctionResponse_httpStatus' - The response's http status code.
newDescribeFunctionResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DescribeFunctionResponse
newDescribeFunctionResponse :: Int -> DescribeFunctionResponse
newDescribeFunctionResponse Int
pHttpStatus_ =
  DescribeFunctionResponse' :: Maybe Text
-> Maybe FunctionSummary -> Int -> DescribeFunctionResponse
DescribeFunctionResponse'
    { $sel:eTag:DescribeFunctionResponse' :: Maybe Text
eTag = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:functionSummary:DescribeFunctionResponse' :: Maybe FunctionSummary
functionSummary = Maybe FunctionSummary
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DescribeFunctionResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The version identifier for the current version of the CloudFront
-- function.
describeFunctionResponse_eTag :: Lens.Lens' DescribeFunctionResponse (Prelude.Maybe Prelude.Text)
describeFunctionResponse_eTag :: (Maybe Text -> f (Maybe Text))
-> DescribeFunctionResponse -> f DescribeFunctionResponse
describeFunctionResponse_eTag = (DescribeFunctionResponse -> Maybe Text)
-> (DescribeFunctionResponse
    -> Maybe Text -> DescribeFunctionResponse)
-> Lens
     DescribeFunctionResponse
     DescribeFunctionResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeFunctionResponse' {Maybe Text
eTag :: Maybe Text
$sel:eTag:DescribeFunctionResponse' :: DescribeFunctionResponse -> Maybe Text
eTag} -> Maybe Text
eTag) (\s :: DescribeFunctionResponse
s@DescribeFunctionResponse' {} Maybe Text
a -> DescribeFunctionResponse
s {$sel:eTag:DescribeFunctionResponse' :: Maybe Text
eTag = Maybe Text
a} :: DescribeFunctionResponse)

-- | Contains configuration information and metadata about a CloudFront
-- function.
describeFunctionResponse_functionSummary :: Lens.Lens' DescribeFunctionResponse (Prelude.Maybe FunctionSummary)
describeFunctionResponse_functionSummary :: (Maybe FunctionSummary -> f (Maybe FunctionSummary))
-> DescribeFunctionResponse -> f DescribeFunctionResponse
describeFunctionResponse_functionSummary = (DescribeFunctionResponse -> Maybe FunctionSummary)
-> (DescribeFunctionResponse
    -> Maybe FunctionSummary -> DescribeFunctionResponse)
-> Lens
     DescribeFunctionResponse
     DescribeFunctionResponse
     (Maybe FunctionSummary)
     (Maybe FunctionSummary)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeFunctionResponse' {Maybe FunctionSummary
functionSummary :: Maybe FunctionSummary
$sel:functionSummary:DescribeFunctionResponse' :: DescribeFunctionResponse -> Maybe FunctionSummary
functionSummary} -> Maybe FunctionSummary
functionSummary) (\s :: DescribeFunctionResponse
s@DescribeFunctionResponse' {} Maybe FunctionSummary
a -> DescribeFunctionResponse
s {$sel:functionSummary:DescribeFunctionResponse' :: Maybe FunctionSummary
functionSummary = Maybe FunctionSummary
a} :: DescribeFunctionResponse)

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

instance Prelude.NFData DescribeFunctionResponse