{-# 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.CloudTrail.GetTrail
-- 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)
--
-- Returns settings information for a specified trail.
module Amazonka.CloudTrail.GetTrail
  ( -- * Creating a Request
    GetTrail (..),
    newGetTrail,

    -- * Request Lenses
    getTrail_name,

    -- * Destructuring the Response
    GetTrailResponse (..),
    newGetTrailResponse,

    -- * Response Lenses
    getTrailResponse_trail,
    getTrailResponse_httpStatus,
  )
where

import Amazonka.CloudTrail.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:/ 'newGetTrail' smart constructor.
data GetTrail = GetTrail'
  { -- | The name or the Amazon Resource Name (ARN) of the trail for which you
    -- want to retrieve settings information.
    GetTrail -> Text
name :: Prelude.Text
  }
  deriving (GetTrail -> GetTrail -> Bool
(GetTrail -> GetTrail -> Bool)
-> (GetTrail -> GetTrail -> Bool) -> Eq GetTrail
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetTrail -> GetTrail -> Bool
$c/= :: GetTrail -> GetTrail -> Bool
== :: GetTrail -> GetTrail -> Bool
$c== :: GetTrail -> GetTrail -> Bool
Prelude.Eq, ReadPrec [GetTrail]
ReadPrec GetTrail
Int -> ReadS GetTrail
ReadS [GetTrail]
(Int -> ReadS GetTrail)
-> ReadS [GetTrail]
-> ReadPrec GetTrail
-> ReadPrec [GetTrail]
-> Read GetTrail
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetTrail]
$creadListPrec :: ReadPrec [GetTrail]
readPrec :: ReadPrec GetTrail
$creadPrec :: ReadPrec GetTrail
readList :: ReadS [GetTrail]
$creadList :: ReadS [GetTrail]
readsPrec :: Int -> ReadS GetTrail
$creadsPrec :: Int -> ReadS GetTrail
Prelude.Read, Int -> GetTrail -> ShowS
[GetTrail] -> ShowS
GetTrail -> String
(Int -> GetTrail -> ShowS)
-> (GetTrail -> String) -> ([GetTrail] -> ShowS) -> Show GetTrail
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetTrail] -> ShowS
$cshowList :: [GetTrail] -> ShowS
show :: GetTrail -> String
$cshow :: GetTrail -> String
showsPrec :: Int -> GetTrail -> ShowS
$cshowsPrec :: Int -> GetTrail -> ShowS
Prelude.Show, (forall x. GetTrail -> Rep GetTrail x)
-> (forall x. Rep GetTrail x -> GetTrail) -> Generic GetTrail
forall x. Rep GetTrail x -> GetTrail
forall x. GetTrail -> Rep GetTrail x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetTrail x -> GetTrail
$cfrom :: forall x. GetTrail -> Rep GetTrail x
Prelude.Generic)

-- |
-- Create a value of 'GetTrail' 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:
--
-- 'name', 'getTrail_name' - The name or the Amazon Resource Name (ARN) of the trail for which you
-- want to retrieve settings information.
newGetTrail ::
  -- | 'name'
  Prelude.Text ->
  GetTrail
newGetTrail :: Text -> GetTrail
newGetTrail Text
pName_ = GetTrail' :: Text -> GetTrail
GetTrail' {$sel:name:GetTrail' :: Text
name = Text
pName_}

-- | The name or the Amazon Resource Name (ARN) of the trail for which you
-- want to retrieve settings information.
getTrail_name :: Lens.Lens' GetTrail Prelude.Text
getTrail_name :: (Text -> f Text) -> GetTrail -> f GetTrail
getTrail_name = (GetTrail -> Text)
-> (GetTrail -> Text -> GetTrail)
-> Lens GetTrail GetTrail Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetTrail' {Text
name :: Text
$sel:name:GetTrail' :: GetTrail -> Text
name} -> Text
name) (\s :: GetTrail
s@GetTrail' {} Text
a -> GetTrail
s {$sel:name:GetTrail' :: Text
name = Text
a} :: GetTrail)

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

instance Prelude.NFData GetTrail

instance Core.ToHeaders GetTrail where
  toHeaders :: GetTrail -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetTrail -> 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
"com.amazonaws.cloudtrail.v20131101.CloudTrail_20131101.GetTrail" ::
                          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 GetTrail where
  toJSON :: GetTrail -> Value
toJSON GetTrail' {Text
name :: Text
$sel:name:GetTrail' :: GetTrail -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [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 GetTrail where
  toPath :: GetTrail -> ByteString
toPath = ByteString -> GetTrail -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

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

-- | /See:/ 'newGetTrailResponse' smart constructor.
data GetTrailResponse = GetTrailResponse'
  { GetTrailResponse -> Maybe Trail
trail :: Prelude.Maybe Trail,
    -- | The response's http status code.
    GetTrailResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetTrailResponse -> GetTrailResponse -> Bool
(GetTrailResponse -> GetTrailResponse -> Bool)
-> (GetTrailResponse -> GetTrailResponse -> Bool)
-> Eq GetTrailResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetTrailResponse -> GetTrailResponse -> Bool
$c/= :: GetTrailResponse -> GetTrailResponse -> Bool
== :: GetTrailResponse -> GetTrailResponse -> Bool
$c== :: GetTrailResponse -> GetTrailResponse -> Bool
Prelude.Eq, ReadPrec [GetTrailResponse]
ReadPrec GetTrailResponse
Int -> ReadS GetTrailResponse
ReadS [GetTrailResponse]
(Int -> ReadS GetTrailResponse)
-> ReadS [GetTrailResponse]
-> ReadPrec GetTrailResponse
-> ReadPrec [GetTrailResponse]
-> Read GetTrailResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetTrailResponse]
$creadListPrec :: ReadPrec [GetTrailResponse]
readPrec :: ReadPrec GetTrailResponse
$creadPrec :: ReadPrec GetTrailResponse
readList :: ReadS [GetTrailResponse]
$creadList :: ReadS [GetTrailResponse]
readsPrec :: Int -> ReadS GetTrailResponse
$creadsPrec :: Int -> ReadS GetTrailResponse
Prelude.Read, Int -> GetTrailResponse -> ShowS
[GetTrailResponse] -> ShowS
GetTrailResponse -> String
(Int -> GetTrailResponse -> ShowS)
-> (GetTrailResponse -> String)
-> ([GetTrailResponse] -> ShowS)
-> Show GetTrailResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetTrailResponse] -> ShowS
$cshowList :: [GetTrailResponse] -> ShowS
show :: GetTrailResponse -> String
$cshow :: GetTrailResponse -> String
showsPrec :: Int -> GetTrailResponse -> ShowS
$cshowsPrec :: Int -> GetTrailResponse -> ShowS
Prelude.Show, (forall x. GetTrailResponse -> Rep GetTrailResponse x)
-> (forall x. Rep GetTrailResponse x -> GetTrailResponse)
-> Generic GetTrailResponse
forall x. Rep GetTrailResponse x -> GetTrailResponse
forall x. GetTrailResponse -> Rep GetTrailResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetTrailResponse x -> GetTrailResponse
$cfrom :: forall x. GetTrailResponse -> Rep GetTrailResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetTrailResponse' 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:
--
-- 'trail', 'getTrailResponse_trail' - Undocumented member.
--
-- 'httpStatus', 'getTrailResponse_httpStatus' - The response's http status code.
newGetTrailResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetTrailResponse
newGetTrailResponse :: Int -> GetTrailResponse
newGetTrailResponse Int
pHttpStatus_ =
  GetTrailResponse' :: Maybe Trail -> Int -> GetTrailResponse
GetTrailResponse'
    { $sel:trail:GetTrailResponse' :: Maybe Trail
trail = Maybe Trail
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetTrailResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Undocumented member.
getTrailResponse_trail :: Lens.Lens' GetTrailResponse (Prelude.Maybe Trail)
getTrailResponse_trail :: (Maybe Trail -> f (Maybe Trail))
-> GetTrailResponse -> f GetTrailResponse
getTrailResponse_trail = (GetTrailResponse -> Maybe Trail)
-> (GetTrailResponse -> Maybe Trail -> GetTrailResponse)
-> Lens
     GetTrailResponse GetTrailResponse (Maybe Trail) (Maybe Trail)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetTrailResponse' {Maybe Trail
trail :: Maybe Trail
$sel:trail:GetTrailResponse' :: GetTrailResponse -> Maybe Trail
trail} -> Maybe Trail
trail) (\s :: GetTrailResponse
s@GetTrailResponse' {} Maybe Trail
a -> GetTrailResponse
s {$sel:trail:GetTrailResponse' :: Maybe Trail
trail = Maybe Trail
a} :: GetTrailResponse)

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

instance Prelude.NFData GetTrailResponse