{-# 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.CloudWatchLogs.GetLogRecord
-- 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)
--
-- Retrieves all of the fields and values of a single log event. All fields
-- are retrieved, even if the original query that produced the
-- @logRecordPointer@ retrieved only a subset of fields. Fields are
-- returned as field name\/field value pairs.
--
-- The full unparsed log event is returned within @\@message@.
module Amazonka.CloudWatchLogs.GetLogRecord
  ( -- * Creating a Request
    GetLogRecord (..),
    newGetLogRecord,

    -- * Request Lenses
    getLogRecord_logRecordPointer,

    -- * Destructuring the Response
    GetLogRecordResponse (..),
    newGetLogRecordResponse,

    -- * Response Lenses
    getLogRecordResponse_logRecord,
    getLogRecordResponse_httpStatus,
  )
where

import Amazonka.CloudWatchLogs.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:/ 'newGetLogRecord' smart constructor.
data GetLogRecord = GetLogRecord'
  { -- | The pointer corresponding to the log event record you want to retrieve.
    -- You get this from the response of a @GetQueryResults@ operation. In that
    -- response, the value of the @\@ptr@ field for a log event is the value to
    -- use as @logRecordPointer@ to retrieve that complete log event record.
    GetLogRecord -> Text
logRecordPointer :: Prelude.Text
  }
  deriving (GetLogRecord -> GetLogRecord -> Bool
(GetLogRecord -> GetLogRecord -> Bool)
-> (GetLogRecord -> GetLogRecord -> Bool) -> Eq GetLogRecord
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetLogRecord -> GetLogRecord -> Bool
$c/= :: GetLogRecord -> GetLogRecord -> Bool
== :: GetLogRecord -> GetLogRecord -> Bool
$c== :: GetLogRecord -> GetLogRecord -> Bool
Prelude.Eq, ReadPrec [GetLogRecord]
ReadPrec GetLogRecord
Int -> ReadS GetLogRecord
ReadS [GetLogRecord]
(Int -> ReadS GetLogRecord)
-> ReadS [GetLogRecord]
-> ReadPrec GetLogRecord
-> ReadPrec [GetLogRecord]
-> Read GetLogRecord
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetLogRecord]
$creadListPrec :: ReadPrec [GetLogRecord]
readPrec :: ReadPrec GetLogRecord
$creadPrec :: ReadPrec GetLogRecord
readList :: ReadS [GetLogRecord]
$creadList :: ReadS [GetLogRecord]
readsPrec :: Int -> ReadS GetLogRecord
$creadsPrec :: Int -> ReadS GetLogRecord
Prelude.Read, Int -> GetLogRecord -> ShowS
[GetLogRecord] -> ShowS
GetLogRecord -> String
(Int -> GetLogRecord -> ShowS)
-> (GetLogRecord -> String)
-> ([GetLogRecord] -> ShowS)
-> Show GetLogRecord
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetLogRecord] -> ShowS
$cshowList :: [GetLogRecord] -> ShowS
show :: GetLogRecord -> String
$cshow :: GetLogRecord -> String
showsPrec :: Int -> GetLogRecord -> ShowS
$cshowsPrec :: Int -> GetLogRecord -> ShowS
Prelude.Show, (forall x. GetLogRecord -> Rep GetLogRecord x)
-> (forall x. Rep GetLogRecord x -> GetLogRecord)
-> Generic GetLogRecord
forall x. Rep GetLogRecord x -> GetLogRecord
forall x. GetLogRecord -> Rep GetLogRecord x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetLogRecord x -> GetLogRecord
$cfrom :: forall x. GetLogRecord -> Rep GetLogRecord x
Prelude.Generic)

-- |
-- Create a value of 'GetLogRecord' 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:
--
-- 'logRecordPointer', 'getLogRecord_logRecordPointer' - The pointer corresponding to the log event record you want to retrieve.
-- You get this from the response of a @GetQueryResults@ operation. In that
-- response, the value of the @\@ptr@ field for a log event is the value to
-- use as @logRecordPointer@ to retrieve that complete log event record.
newGetLogRecord ::
  -- | 'logRecordPointer'
  Prelude.Text ->
  GetLogRecord
newGetLogRecord :: Text -> GetLogRecord
newGetLogRecord Text
pLogRecordPointer_ =
  GetLogRecord' :: Text -> GetLogRecord
GetLogRecord'
    { $sel:logRecordPointer:GetLogRecord' :: Text
logRecordPointer =
        Text
pLogRecordPointer_
    }

-- | The pointer corresponding to the log event record you want to retrieve.
-- You get this from the response of a @GetQueryResults@ operation. In that
-- response, the value of the @\@ptr@ field for a log event is the value to
-- use as @logRecordPointer@ to retrieve that complete log event record.
getLogRecord_logRecordPointer :: Lens.Lens' GetLogRecord Prelude.Text
getLogRecord_logRecordPointer :: (Text -> f Text) -> GetLogRecord -> f GetLogRecord
getLogRecord_logRecordPointer = (GetLogRecord -> Text)
-> (GetLogRecord -> Text -> GetLogRecord)
-> Lens GetLogRecord GetLogRecord Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetLogRecord' {Text
logRecordPointer :: Text
$sel:logRecordPointer:GetLogRecord' :: GetLogRecord -> Text
logRecordPointer} -> Text
logRecordPointer) (\s :: GetLogRecord
s@GetLogRecord' {} Text
a -> GetLogRecord
s {$sel:logRecordPointer:GetLogRecord' :: Text
logRecordPointer = Text
a} :: GetLogRecord)

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

instance Prelude.NFData GetLogRecord

instance Core.ToHeaders GetLogRecord where
  toHeaders :: GetLogRecord -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetLogRecord -> 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
"Logs_20140328.GetLogRecord" :: 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 GetLogRecord where
  toJSON :: GetLogRecord -> Value
toJSON GetLogRecord' {Text
logRecordPointer :: Text
$sel:logRecordPointer:GetLogRecord' :: GetLogRecord -> 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
"logRecordPointer" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
logRecordPointer)
          ]
      )

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

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

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

-- |
-- Create a value of 'GetLogRecordResponse' 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:
--
-- 'logRecord', 'getLogRecordResponse_logRecord' - The requested log event, as a JSON string.
--
-- 'httpStatus', 'getLogRecordResponse_httpStatus' - The response's http status code.
newGetLogRecordResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetLogRecordResponse
newGetLogRecordResponse :: Int -> GetLogRecordResponse
newGetLogRecordResponse Int
pHttpStatus_ =
  GetLogRecordResponse' :: Maybe (HashMap Text Text) -> Int -> GetLogRecordResponse
GetLogRecordResponse'
    { $sel:logRecord:GetLogRecordResponse' :: Maybe (HashMap Text Text)
logRecord = Maybe (HashMap Text Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetLogRecordResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The requested log event, as a JSON string.
getLogRecordResponse_logRecord :: Lens.Lens' GetLogRecordResponse (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
getLogRecordResponse_logRecord :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> GetLogRecordResponse -> f GetLogRecordResponse
getLogRecordResponse_logRecord = (GetLogRecordResponse -> Maybe (HashMap Text Text))
-> (GetLogRecordResponse
    -> Maybe (HashMap Text Text) -> GetLogRecordResponse)
-> Lens
     GetLogRecordResponse
     GetLogRecordResponse
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetLogRecordResponse' {Maybe (HashMap Text Text)
logRecord :: Maybe (HashMap Text Text)
$sel:logRecord:GetLogRecordResponse' :: GetLogRecordResponse -> Maybe (HashMap Text Text)
logRecord} -> Maybe (HashMap Text Text)
logRecord) (\s :: GetLogRecordResponse
s@GetLogRecordResponse' {} Maybe (HashMap Text Text)
a -> GetLogRecordResponse
s {$sel:logRecord:GetLogRecordResponse' :: Maybe (HashMap Text Text)
logRecord = Maybe (HashMap Text Text)
a} :: GetLogRecordResponse) ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
 -> GetLogRecordResponse -> f GetLogRecordResponse)
-> ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
    -> Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> GetLogRecordResponse
-> f GetLogRecordResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
-> Iso
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
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
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.NFData GetLogRecordResponse