{-# 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.SSM.GetParameter
-- 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)
--
-- Get information about a single parameter by specifying the parameter
-- name.
--
-- To get information about more than one parameter at a time, use the
-- GetParameters operation.
module Amazonka.SSM.GetParameter
  ( -- * Creating a Request
    GetParameter (..),
    newGetParameter,

    -- * Request Lenses
    getParameter_withDecryption,
    getParameter_name,

    -- * Destructuring the Response
    GetParameterResponse (..),
    newGetParameterResponse,

    -- * Response Lenses
    getParameterResponse_parameter,
    getParameterResponse_httpStatus,
  )
where

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
import Amazonka.SSM.Types

-- | /See:/ 'newGetParameter' smart constructor.
data GetParameter = GetParameter'
  { -- | Return decrypted values for secure string parameters. This flag is
    -- ignored for @String@ and @StringList@ parameter types.
    GetParameter -> Maybe Bool
withDecryption :: Prelude.Maybe Prelude.Bool,
    -- | The name of the parameter you want to query.
    --
    -- To query by parameter label, use @\"Name\": \"name:label\"@. To query by
    -- parameter version, use @\"Name\": \"name:version\"@.
    GetParameter -> Text
name :: Prelude.Text
  }
  deriving (GetParameter -> GetParameter -> Bool
(GetParameter -> GetParameter -> Bool)
-> (GetParameter -> GetParameter -> Bool) -> Eq GetParameter
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetParameter -> GetParameter -> Bool
$c/= :: GetParameter -> GetParameter -> Bool
== :: GetParameter -> GetParameter -> Bool
$c== :: GetParameter -> GetParameter -> Bool
Prelude.Eq, ReadPrec [GetParameter]
ReadPrec GetParameter
Int -> ReadS GetParameter
ReadS [GetParameter]
(Int -> ReadS GetParameter)
-> ReadS [GetParameter]
-> ReadPrec GetParameter
-> ReadPrec [GetParameter]
-> Read GetParameter
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetParameter]
$creadListPrec :: ReadPrec [GetParameter]
readPrec :: ReadPrec GetParameter
$creadPrec :: ReadPrec GetParameter
readList :: ReadS [GetParameter]
$creadList :: ReadS [GetParameter]
readsPrec :: Int -> ReadS GetParameter
$creadsPrec :: Int -> ReadS GetParameter
Prelude.Read, Int -> GetParameter -> ShowS
[GetParameter] -> ShowS
GetParameter -> String
(Int -> GetParameter -> ShowS)
-> (GetParameter -> String)
-> ([GetParameter] -> ShowS)
-> Show GetParameter
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetParameter] -> ShowS
$cshowList :: [GetParameter] -> ShowS
show :: GetParameter -> String
$cshow :: GetParameter -> String
showsPrec :: Int -> GetParameter -> ShowS
$cshowsPrec :: Int -> GetParameter -> ShowS
Prelude.Show, (forall x. GetParameter -> Rep GetParameter x)
-> (forall x. Rep GetParameter x -> GetParameter)
-> Generic GetParameter
forall x. Rep GetParameter x -> GetParameter
forall x. GetParameter -> Rep GetParameter x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetParameter x -> GetParameter
$cfrom :: forall x. GetParameter -> Rep GetParameter x
Prelude.Generic)

-- |
-- Create a value of 'GetParameter' 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:
--
-- 'withDecryption', 'getParameter_withDecryption' - Return decrypted values for secure string parameters. This flag is
-- ignored for @String@ and @StringList@ parameter types.
--
-- 'name', 'getParameter_name' - The name of the parameter you want to query.
--
-- To query by parameter label, use @\"Name\": \"name:label\"@. To query by
-- parameter version, use @\"Name\": \"name:version\"@.
newGetParameter ::
  -- | 'name'
  Prelude.Text ->
  GetParameter
newGetParameter :: Text -> GetParameter
newGetParameter Text
pName_ =
  GetParameter' :: Maybe Bool -> Text -> GetParameter
GetParameter'
    { $sel:withDecryption:GetParameter' :: Maybe Bool
withDecryption = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:name:GetParameter' :: Text
name = Text
pName_
    }

-- | Return decrypted values for secure string parameters. This flag is
-- ignored for @String@ and @StringList@ parameter types.
getParameter_withDecryption :: Lens.Lens' GetParameter (Prelude.Maybe Prelude.Bool)
getParameter_withDecryption :: (Maybe Bool -> f (Maybe Bool)) -> GetParameter -> f GetParameter
getParameter_withDecryption = (GetParameter -> Maybe Bool)
-> (GetParameter -> Maybe Bool -> GetParameter)
-> Lens GetParameter GetParameter (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetParameter' {Maybe Bool
withDecryption :: Maybe Bool
$sel:withDecryption:GetParameter' :: GetParameter -> Maybe Bool
withDecryption} -> Maybe Bool
withDecryption) (\s :: GetParameter
s@GetParameter' {} Maybe Bool
a -> GetParameter
s {$sel:withDecryption:GetParameter' :: Maybe Bool
withDecryption = Maybe Bool
a} :: GetParameter)

-- | The name of the parameter you want to query.
--
-- To query by parameter label, use @\"Name\": \"name:label\"@. To query by
-- parameter version, use @\"Name\": \"name:version\"@.
getParameter_name :: Lens.Lens' GetParameter Prelude.Text
getParameter_name :: (Text -> f Text) -> GetParameter -> f GetParameter
getParameter_name = (GetParameter -> Text)
-> (GetParameter -> Text -> GetParameter)
-> Lens GetParameter GetParameter Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetParameter' {Text
name :: Text
$sel:name:GetParameter' :: GetParameter -> Text
name} -> Text
name) (\s :: GetParameter
s@GetParameter' {} Text
a -> GetParameter
s {$sel:name:GetParameter' :: Text
name = Text
a} :: GetParameter)

instance Core.AWSRequest GetParameter where
  type AWSResponse GetParameter = GetParameterResponse
  request :: GetParameter -> Request GetParameter
request = Service -> GetParameter -> Request GetParameter
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy GetParameter
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetParameter)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetParameter))
-> Logger
-> Service
-> Proxy GetParameter
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetParameter)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Parameter -> Int -> GetParameterResponse
GetParameterResponse'
            (Maybe Parameter -> Int -> GetParameterResponse)
-> Either String (Maybe Parameter)
-> Either String (Int -> GetParameterResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Parameter)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"Parameter")
            Either String (Int -> GetParameterResponse)
-> Either String Int -> Either String GetParameterResponse
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 GetParameter

instance Prelude.NFData GetParameter

instance Core.ToHeaders GetParameter where
  toHeaders :: GetParameter -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetParameter -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# (ByteString
"AmazonSSM.GetParameter" :: Prelude.ByteString),
            HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON GetParameter where
  toJSON :: GetParameter -> Value
toJSON GetParameter' {Maybe Bool
Text
name :: Text
withDecryption :: Maybe Bool
$sel:name:GetParameter' :: GetParameter -> Text
$sel:withDecryption:GetParameter' :: GetParameter -> Maybe Bool
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"WithDecryption" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Bool -> Pair) -> Maybe Bool -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
withDecryption,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Name" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
name)
          ]
      )

instance Core.ToPath GetParameter where
  toPath :: GetParameter -> ByteString
toPath = ByteString -> GetParameter -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

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

-- | /See:/ 'newGetParameterResponse' smart constructor.
data GetParameterResponse = GetParameterResponse'
  { -- | Information about a parameter.
    GetParameterResponse -> Maybe Parameter
parameter :: Prelude.Maybe Parameter,
    -- | The response's http status code.
    GetParameterResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetParameterResponse -> GetParameterResponse -> Bool
(GetParameterResponse -> GetParameterResponse -> Bool)
-> (GetParameterResponse -> GetParameterResponse -> Bool)
-> Eq GetParameterResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetParameterResponse -> GetParameterResponse -> Bool
$c/= :: GetParameterResponse -> GetParameterResponse -> Bool
== :: GetParameterResponse -> GetParameterResponse -> Bool
$c== :: GetParameterResponse -> GetParameterResponse -> Bool
Prelude.Eq, Int -> GetParameterResponse -> ShowS
[GetParameterResponse] -> ShowS
GetParameterResponse -> String
(Int -> GetParameterResponse -> ShowS)
-> (GetParameterResponse -> String)
-> ([GetParameterResponse] -> ShowS)
-> Show GetParameterResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetParameterResponse] -> ShowS
$cshowList :: [GetParameterResponse] -> ShowS
show :: GetParameterResponse -> String
$cshow :: GetParameterResponse -> String
showsPrec :: Int -> GetParameterResponse -> ShowS
$cshowsPrec :: Int -> GetParameterResponse -> ShowS
Prelude.Show, (forall x. GetParameterResponse -> Rep GetParameterResponse x)
-> (forall x. Rep GetParameterResponse x -> GetParameterResponse)
-> Generic GetParameterResponse
forall x. Rep GetParameterResponse x -> GetParameterResponse
forall x. GetParameterResponse -> Rep GetParameterResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetParameterResponse x -> GetParameterResponse
$cfrom :: forall x. GetParameterResponse -> Rep GetParameterResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetParameterResponse' 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:
--
-- 'parameter', 'getParameterResponse_parameter' - Information about a parameter.
--
-- 'httpStatus', 'getParameterResponse_httpStatus' - The response's http status code.
newGetParameterResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetParameterResponse
newGetParameterResponse :: Int -> GetParameterResponse
newGetParameterResponse Int
pHttpStatus_ =
  GetParameterResponse' :: Maybe Parameter -> Int -> GetParameterResponse
GetParameterResponse'
    { $sel:parameter:GetParameterResponse' :: Maybe Parameter
parameter = Maybe Parameter
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetParameterResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Information about a parameter.
getParameterResponse_parameter :: Lens.Lens' GetParameterResponse (Prelude.Maybe Parameter)
getParameterResponse_parameter :: (Maybe Parameter -> f (Maybe Parameter))
-> GetParameterResponse -> f GetParameterResponse
getParameterResponse_parameter = (GetParameterResponse -> Maybe Parameter)
-> (GetParameterResponse
    -> Maybe Parameter -> GetParameterResponse)
-> Lens
     GetParameterResponse
     GetParameterResponse
     (Maybe Parameter)
     (Maybe Parameter)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetParameterResponse' {Maybe Parameter
parameter :: Maybe Parameter
$sel:parameter:GetParameterResponse' :: GetParameterResponse -> Maybe Parameter
parameter} -> Maybe Parameter
parameter) (\s :: GetParameterResponse
s@GetParameterResponse' {} Maybe Parameter
a -> GetParameterResponse
s {$sel:parameter:GetParameterResponse' :: Maybe Parameter
parameter = Maybe Parameter
a} :: GetParameterResponse)

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

instance Prelude.NFData GetParameterResponse