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

    -- * Request Lenses
    getFunction_stage,
    getFunction_name,

    -- * Destructuring the Response
    GetFunctionResponse (..),
    newGetFunctionResponse,

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

-- |
-- Create a value of 'GetFunction' 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', 'getFunction_stage' - The function’s stage, either @DEVELOPMENT@ or @LIVE@.
--
-- 'name', 'getFunction_name' - The name of the function whose code you are getting.
newGetFunction ::
  -- | 'name'
  Prelude.Text ->
  GetFunction
newGetFunction :: Text -> GetFunction
newGetFunction Text
pName_ =
  GetFunction' :: Maybe FunctionStage -> Text -> GetFunction
GetFunction'
    { $sel:stage:GetFunction' :: Maybe FunctionStage
stage = Maybe FunctionStage
forall a. Maybe a
Prelude.Nothing,
      $sel:name:GetFunction' :: Text
name = Text
pName_
    }

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

-- | The name of the function whose code you are getting.
getFunction_name :: Lens.Lens' GetFunction Prelude.Text
getFunction_name :: (Text -> f Text) -> GetFunction -> f GetFunction
getFunction_name = (GetFunction -> Text)
-> (GetFunction -> Text -> GetFunction)
-> Lens GetFunction GetFunction Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetFunction' {Text
name :: Text
$sel:name:GetFunction' :: GetFunction -> Text
name} -> Text
name) (\s :: GetFunction
s@GetFunction' {} Text
a -> GetFunction
s {$sel:name:GetFunction' :: Text
name = Text
a} :: GetFunction)

instance Core.AWSRequest GetFunction where
  type AWSResponse GetFunction = GetFunctionResponse
  request :: GetFunction -> Request GetFunction
request = Service -> GetFunction -> Request GetFunction
forall a. ToRequest a => Service -> a -> Request a
Request.get Service
defaultService
  response :: Logger
-> Service
-> Proxy GetFunction
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetFunction)))
response =
    (Int
 -> ResponseHeaders
 -> ByteString
 -> Either String (AWSResponse GetFunction))
-> Logger
-> Service
-> Proxy GetFunction
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetFunction)))
forall (m :: * -> *) a.
MonadResource m =>
(Int
 -> ResponseHeaders -> ByteString -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveBytes
      ( \Int
s ResponseHeaders
h ByteString
x ->
          Maybe Text
-> Maybe (Sensitive ByteString)
-> Maybe Text
-> Int
-> GetFunctionResponse
GetFunctionResponse'
            (Maybe Text
 -> Maybe (Sensitive ByteString)
 -> Maybe Text
 -> Int
 -> GetFunctionResponse)
-> Either String (Maybe Text)
-> Either
     String
     (Maybe (Sensitive ByteString)
      -> Maybe Text -> Int -> GetFunctionResponse)
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 (Sensitive ByteString)
   -> Maybe Text -> Int -> GetFunctionResponse)
-> Either String (Maybe (Sensitive ByteString))
-> Either String (Maybe Text -> Int -> GetFunctionResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Maybe (Sensitive ByteString)
-> Either String (Maybe (Sensitive ByteString))
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Sensitive ByteString -> Maybe (Sensitive ByteString)
forall a. a -> Maybe a
Prelude.Just (ByteString -> Sensitive ByteString
Prelude.coerce ByteString
x)))
            Either String (Maybe Text -> Int -> GetFunctionResponse)
-> Either String (Maybe Text)
-> Either String (Int -> GetFunctionResponse)
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
"Content-Type")
            Either String (Int -> GetFunctionResponse)
-> Either String Int -> Either String GetFunctionResponse
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 GetFunction

instance Prelude.NFData GetFunction

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

instance Core.ToPath GetFunction where
  toPath :: GetFunction -> ByteString
toPath GetFunction' {Maybe FunctionStage
Text
name :: Text
stage :: Maybe FunctionStage
$sel:name:GetFunction' :: GetFunction -> Text
$sel:stage:GetFunction' :: GetFunction -> 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]

instance Core.ToQuery GetFunction where
  toQuery :: GetFunction -> QueryString
toQuery GetFunction' {Maybe FunctionStage
Text
name :: Text
stage :: Maybe FunctionStage
$sel:name:GetFunction' :: GetFunction -> Text
$sel:stage:GetFunction' :: GetFunction -> 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:/ 'newGetFunctionResponse' smart constructor.
data GetFunctionResponse = GetFunctionResponse'
  { -- | The version identifier for the current version of the CloudFront
    -- function.
    GetFunctionResponse -> Maybe Text
eTag :: Prelude.Maybe Prelude.Text,
    -- | The function code of a CloudFront function.
    GetFunctionResponse -> Maybe (Sensitive ByteString)
functionCode :: Prelude.Maybe (Core.Sensitive Prelude.ByteString),
    -- | The content type (media type) of the response.
    GetFunctionResponse -> Maybe Text
contentType :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    GetFunctionResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetFunctionResponse -> GetFunctionResponse -> Bool
(GetFunctionResponse -> GetFunctionResponse -> Bool)
-> (GetFunctionResponse -> GetFunctionResponse -> Bool)
-> Eq GetFunctionResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetFunctionResponse -> GetFunctionResponse -> Bool
$c/= :: GetFunctionResponse -> GetFunctionResponse -> Bool
== :: GetFunctionResponse -> GetFunctionResponse -> Bool
$c== :: GetFunctionResponse -> GetFunctionResponse -> Bool
Prelude.Eq, Int -> GetFunctionResponse -> ShowS
[GetFunctionResponse] -> ShowS
GetFunctionResponse -> String
(Int -> GetFunctionResponse -> ShowS)
-> (GetFunctionResponse -> String)
-> ([GetFunctionResponse] -> ShowS)
-> Show GetFunctionResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetFunctionResponse] -> ShowS
$cshowList :: [GetFunctionResponse] -> ShowS
show :: GetFunctionResponse -> String
$cshow :: GetFunctionResponse -> String
showsPrec :: Int -> GetFunctionResponse -> ShowS
$cshowsPrec :: Int -> GetFunctionResponse -> ShowS
Prelude.Show, (forall x. GetFunctionResponse -> Rep GetFunctionResponse x)
-> (forall x. Rep GetFunctionResponse x -> GetFunctionResponse)
-> Generic GetFunctionResponse
forall x. Rep GetFunctionResponse x -> GetFunctionResponse
forall x. GetFunctionResponse -> Rep GetFunctionResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetFunctionResponse x -> GetFunctionResponse
$cfrom :: forall x. GetFunctionResponse -> Rep GetFunctionResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetFunctionResponse' 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', 'getFunctionResponse_eTag' - The version identifier for the current version of the CloudFront
-- function.
--
-- 'functionCode', 'getFunctionResponse_functionCode' - The function code of a CloudFront function.
--
-- 'contentType', 'getFunctionResponse_contentType' - The content type (media type) of the response.
--
-- 'httpStatus', 'getFunctionResponse_httpStatus' - The response's http status code.
newGetFunctionResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetFunctionResponse
newGetFunctionResponse :: Int -> GetFunctionResponse
newGetFunctionResponse Int
pHttpStatus_ =
  GetFunctionResponse' :: Maybe Text
-> Maybe (Sensitive ByteString)
-> Maybe Text
-> Int
-> GetFunctionResponse
GetFunctionResponse'
    { $sel:eTag:GetFunctionResponse' :: Maybe Text
eTag = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:functionCode:GetFunctionResponse' :: Maybe (Sensitive ByteString)
functionCode = Maybe (Sensitive ByteString)
forall a. Maybe a
Prelude.Nothing,
      $sel:contentType:GetFunctionResponse' :: Maybe Text
contentType = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetFunctionResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

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

-- | The function code of a CloudFront function.
getFunctionResponse_functionCode :: Lens.Lens' GetFunctionResponse (Prelude.Maybe Prelude.ByteString)
getFunctionResponse_functionCode :: (Maybe ByteString -> f (Maybe ByteString))
-> GetFunctionResponse -> f GetFunctionResponse
getFunctionResponse_functionCode = (GetFunctionResponse -> Maybe (Sensitive ByteString))
-> (GetFunctionResponse
    -> Maybe (Sensitive ByteString) -> GetFunctionResponse)
-> Lens
     GetFunctionResponse
     GetFunctionResponse
     (Maybe (Sensitive ByteString))
     (Maybe (Sensitive ByteString))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetFunctionResponse' {Maybe (Sensitive ByteString)
functionCode :: Maybe (Sensitive ByteString)
$sel:functionCode:GetFunctionResponse' :: GetFunctionResponse -> Maybe (Sensitive ByteString)
functionCode} -> Maybe (Sensitive ByteString)
functionCode) (\s :: GetFunctionResponse
s@GetFunctionResponse' {} Maybe (Sensitive ByteString)
a -> GetFunctionResponse
s {$sel:functionCode:GetFunctionResponse' :: Maybe (Sensitive ByteString)
functionCode = Maybe (Sensitive ByteString)
a} :: GetFunctionResponse) ((Maybe (Sensitive ByteString) -> f (Maybe (Sensitive ByteString)))
 -> GetFunctionResponse -> f GetFunctionResponse)
-> ((Maybe ByteString -> f (Maybe ByteString))
    -> Maybe (Sensitive ByteString)
    -> f (Maybe (Sensitive ByteString)))
-> (Maybe ByteString -> f (Maybe ByteString))
-> GetFunctionResponse
-> f GetFunctionResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (Sensitive ByteString) (Sensitive ByteString) ByteString ByteString
-> Iso
     (Maybe (Sensitive ByteString))
     (Maybe (Sensitive ByteString))
     (Maybe ByteString)
     (Maybe ByteString)
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  (Sensitive ByteString) (Sensitive ByteString) ByteString ByteString
forall a. Iso' (Sensitive a) a
Core._Sensitive

-- | The content type (media type) of the response.
getFunctionResponse_contentType :: Lens.Lens' GetFunctionResponse (Prelude.Maybe Prelude.Text)
getFunctionResponse_contentType :: (Maybe Text -> f (Maybe Text))
-> GetFunctionResponse -> f GetFunctionResponse
getFunctionResponse_contentType = (GetFunctionResponse -> Maybe Text)
-> (GetFunctionResponse -> Maybe Text -> GetFunctionResponse)
-> Lens
     GetFunctionResponse GetFunctionResponse (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetFunctionResponse' {Maybe Text
contentType :: Maybe Text
$sel:contentType:GetFunctionResponse' :: GetFunctionResponse -> Maybe Text
contentType} -> Maybe Text
contentType) (\s :: GetFunctionResponse
s@GetFunctionResponse' {} Maybe Text
a -> GetFunctionResponse
s {$sel:contentType:GetFunctionResponse' :: Maybe Text
contentType = Maybe Text
a} :: GetFunctionResponse)

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

instance Prelude.NFData GetFunctionResponse