{-# 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.LookupEvents
-- 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)
--
-- Looks up
-- <https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-concepts.html#cloudtrail-concepts-management-events management events>
-- or
-- <https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-concepts.html#cloudtrail-concepts-insights-events CloudTrail Insights events>
-- that are captured by CloudTrail. You can look up events that occurred in
-- a region within the last 90 days. Lookup supports the following
-- attributes for management events:
--
-- -   Amazon Web Services access key
--
-- -   Event ID
--
-- -   Event name
--
-- -   Event source
--
-- -   Read only
--
-- -   Resource name
--
-- -   Resource type
--
-- -   User name
--
-- Lookup supports the following attributes for Insights events:
--
-- -   Event ID
--
-- -   Event name
--
-- -   Event source
--
-- All attributes are optional. The default number of results returned is
-- 50, with a maximum of 50 possible. The response includes a token that
-- you can use to get the next page of results.
--
-- The rate of lookup requests is limited to two per second, per account,
-- per region. If this limit is exceeded, a throttling error occurs.
--
-- This operation returns paginated results.
module Amazonka.CloudTrail.LookupEvents
  ( -- * Creating a Request
    LookupEvents (..),
    newLookupEvents,

    -- * Request Lenses
    lookupEvents_eventCategory,
    lookupEvents_startTime,
    lookupEvents_lookupAttributes,
    lookupEvents_nextToken,
    lookupEvents_endTime,
    lookupEvents_maxResults,

    -- * Destructuring the Response
    LookupEventsResponse (..),
    newLookupEventsResponse,

    -- * Response Lenses
    lookupEventsResponse_nextToken,
    lookupEventsResponse_events,
    lookupEventsResponse_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

-- | Contains a request for LookupEvents.
--
-- /See:/ 'newLookupEvents' smart constructor.
data LookupEvents = LookupEvents'
  { -- | Specifies the event category. If you do not specify an event category,
    -- events of the category are not returned in the response. For example, if
    -- you do not specify @insight@ as the value of @EventCategory@, no
    -- Insights events are returned.
    LookupEvents -> Maybe EventCategory
eventCategory :: Prelude.Maybe EventCategory,
    -- | Specifies that only events that occur after or at the specified time are
    -- returned. If the specified start time is after the specified end time,
    -- an error is returned.
    LookupEvents -> Maybe POSIX
startTime :: Prelude.Maybe Core.POSIX,
    -- | Contains a list of lookup attributes. Currently the list can contain
    -- only one item.
    LookupEvents -> Maybe [LookupAttribute]
lookupAttributes :: Prelude.Maybe [LookupAttribute],
    -- | The token to use to get the next page of results after a previous API
    -- call. This token must be passed in with the same parameters that were
    -- specified in the the original call. For example, if the original call
    -- specified an AttributeKey of \'Username\' with a value of \'root\', the
    -- call with NextToken should include those same parameters.
    LookupEvents -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | Specifies that only events that occur before or at the specified time
    -- are returned. If the specified end time is before the specified start
    -- time, an error is returned.
    LookupEvents -> Maybe POSIX
endTime :: Prelude.Maybe Core.POSIX,
    -- | The number of events to return. Possible values are 1 through 50. The
    -- default is 50.
    LookupEvents -> Maybe Natural
maxResults :: Prelude.Maybe Prelude.Natural
  }
  deriving (LookupEvents -> LookupEvents -> Bool
(LookupEvents -> LookupEvents -> Bool)
-> (LookupEvents -> LookupEvents -> Bool) -> Eq LookupEvents
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LookupEvents -> LookupEvents -> Bool
$c/= :: LookupEvents -> LookupEvents -> Bool
== :: LookupEvents -> LookupEvents -> Bool
$c== :: LookupEvents -> LookupEvents -> Bool
Prelude.Eq, ReadPrec [LookupEvents]
ReadPrec LookupEvents
Int -> ReadS LookupEvents
ReadS [LookupEvents]
(Int -> ReadS LookupEvents)
-> ReadS [LookupEvents]
-> ReadPrec LookupEvents
-> ReadPrec [LookupEvents]
-> Read LookupEvents
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [LookupEvents]
$creadListPrec :: ReadPrec [LookupEvents]
readPrec :: ReadPrec LookupEvents
$creadPrec :: ReadPrec LookupEvents
readList :: ReadS [LookupEvents]
$creadList :: ReadS [LookupEvents]
readsPrec :: Int -> ReadS LookupEvents
$creadsPrec :: Int -> ReadS LookupEvents
Prelude.Read, Int -> LookupEvents -> ShowS
[LookupEvents] -> ShowS
LookupEvents -> String
(Int -> LookupEvents -> ShowS)
-> (LookupEvents -> String)
-> ([LookupEvents] -> ShowS)
-> Show LookupEvents
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LookupEvents] -> ShowS
$cshowList :: [LookupEvents] -> ShowS
show :: LookupEvents -> String
$cshow :: LookupEvents -> String
showsPrec :: Int -> LookupEvents -> ShowS
$cshowsPrec :: Int -> LookupEvents -> ShowS
Prelude.Show, (forall x. LookupEvents -> Rep LookupEvents x)
-> (forall x. Rep LookupEvents x -> LookupEvents)
-> Generic LookupEvents
forall x. Rep LookupEvents x -> LookupEvents
forall x. LookupEvents -> Rep LookupEvents x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep LookupEvents x -> LookupEvents
$cfrom :: forall x. LookupEvents -> Rep LookupEvents x
Prelude.Generic)

-- |
-- Create a value of 'LookupEvents' 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:
--
-- 'eventCategory', 'lookupEvents_eventCategory' - Specifies the event category. If you do not specify an event category,
-- events of the category are not returned in the response. For example, if
-- you do not specify @insight@ as the value of @EventCategory@, no
-- Insights events are returned.
--
-- 'startTime', 'lookupEvents_startTime' - Specifies that only events that occur after or at the specified time are
-- returned. If the specified start time is after the specified end time,
-- an error is returned.
--
-- 'lookupAttributes', 'lookupEvents_lookupAttributes' - Contains a list of lookup attributes. Currently the list can contain
-- only one item.
--
-- 'nextToken', 'lookupEvents_nextToken' - The token to use to get the next page of results after a previous API
-- call. This token must be passed in with the same parameters that were
-- specified in the the original call. For example, if the original call
-- specified an AttributeKey of \'Username\' with a value of \'root\', the
-- call with NextToken should include those same parameters.
--
-- 'endTime', 'lookupEvents_endTime' - Specifies that only events that occur before or at the specified time
-- are returned. If the specified end time is before the specified start
-- time, an error is returned.
--
-- 'maxResults', 'lookupEvents_maxResults' - The number of events to return. Possible values are 1 through 50. The
-- default is 50.
newLookupEvents ::
  LookupEvents
newLookupEvents :: LookupEvents
newLookupEvents =
  LookupEvents' :: Maybe EventCategory
-> Maybe POSIX
-> Maybe [LookupAttribute]
-> Maybe Text
-> Maybe POSIX
-> Maybe Natural
-> LookupEvents
LookupEvents'
    { $sel:eventCategory:LookupEvents' :: Maybe EventCategory
eventCategory = Maybe EventCategory
forall a. Maybe a
Prelude.Nothing,
      $sel:startTime:LookupEvents' :: Maybe POSIX
startTime = Maybe POSIX
forall a. Maybe a
Prelude.Nothing,
      $sel:lookupAttributes:LookupEvents' :: Maybe [LookupAttribute]
lookupAttributes = Maybe [LookupAttribute]
forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:LookupEvents' :: Maybe Text
nextToken = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:endTime:LookupEvents' :: Maybe POSIX
endTime = Maybe POSIX
forall a. Maybe a
Prelude.Nothing,
      $sel:maxResults:LookupEvents' :: Maybe Natural
maxResults = Maybe Natural
forall a. Maybe a
Prelude.Nothing
    }

-- | Specifies the event category. If you do not specify an event category,
-- events of the category are not returned in the response. For example, if
-- you do not specify @insight@ as the value of @EventCategory@, no
-- Insights events are returned.
lookupEvents_eventCategory :: Lens.Lens' LookupEvents (Prelude.Maybe EventCategory)
lookupEvents_eventCategory :: (Maybe EventCategory -> f (Maybe EventCategory))
-> LookupEvents -> f LookupEvents
lookupEvents_eventCategory = (LookupEvents -> Maybe EventCategory)
-> (LookupEvents -> Maybe EventCategory -> LookupEvents)
-> Lens
     LookupEvents
     LookupEvents
     (Maybe EventCategory)
     (Maybe EventCategory)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LookupEvents' {Maybe EventCategory
eventCategory :: Maybe EventCategory
$sel:eventCategory:LookupEvents' :: LookupEvents -> Maybe EventCategory
eventCategory} -> Maybe EventCategory
eventCategory) (\s :: LookupEvents
s@LookupEvents' {} Maybe EventCategory
a -> LookupEvents
s {$sel:eventCategory:LookupEvents' :: Maybe EventCategory
eventCategory = Maybe EventCategory
a} :: LookupEvents)

-- | Specifies that only events that occur after or at the specified time are
-- returned. If the specified start time is after the specified end time,
-- an error is returned.
lookupEvents_startTime :: Lens.Lens' LookupEvents (Prelude.Maybe Prelude.UTCTime)
lookupEvents_startTime :: (Maybe UTCTime -> f (Maybe UTCTime))
-> LookupEvents -> f LookupEvents
lookupEvents_startTime = (LookupEvents -> Maybe POSIX)
-> (LookupEvents -> Maybe POSIX -> LookupEvents)
-> Lens LookupEvents LookupEvents (Maybe POSIX) (Maybe POSIX)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LookupEvents' {Maybe POSIX
startTime :: Maybe POSIX
$sel:startTime:LookupEvents' :: LookupEvents -> Maybe POSIX
startTime} -> Maybe POSIX
startTime) (\s :: LookupEvents
s@LookupEvents' {} Maybe POSIX
a -> LookupEvents
s {$sel:startTime:LookupEvents' :: Maybe POSIX
startTime = Maybe POSIX
a} :: LookupEvents) ((Maybe POSIX -> f (Maybe POSIX))
 -> LookupEvents -> f LookupEvents)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe POSIX -> f (Maybe POSIX))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> LookupEvents
-> f LookupEvents
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso POSIX POSIX UTCTime UTCTime
-> Iso (Maybe POSIX) (Maybe POSIX) (Maybe UTCTime) (Maybe UTCTime)
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 POSIX POSIX UTCTime UTCTime
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

-- | Contains a list of lookup attributes. Currently the list can contain
-- only one item.
lookupEvents_lookupAttributes :: Lens.Lens' LookupEvents (Prelude.Maybe [LookupAttribute])
lookupEvents_lookupAttributes :: (Maybe [LookupAttribute] -> f (Maybe [LookupAttribute]))
-> LookupEvents -> f LookupEvents
lookupEvents_lookupAttributes = (LookupEvents -> Maybe [LookupAttribute])
-> (LookupEvents -> Maybe [LookupAttribute] -> LookupEvents)
-> Lens
     LookupEvents
     LookupEvents
     (Maybe [LookupAttribute])
     (Maybe [LookupAttribute])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LookupEvents' {Maybe [LookupAttribute]
lookupAttributes :: Maybe [LookupAttribute]
$sel:lookupAttributes:LookupEvents' :: LookupEvents -> Maybe [LookupAttribute]
lookupAttributes} -> Maybe [LookupAttribute]
lookupAttributes) (\s :: LookupEvents
s@LookupEvents' {} Maybe [LookupAttribute]
a -> LookupEvents
s {$sel:lookupAttributes:LookupEvents' :: Maybe [LookupAttribute]
lookupAttributes = Maybe [LookupAttribute]
a} :: LookupEvents) ((Maybe [LookupAttribute] -> f (Maybe [LookupAttribute]))
 -> LookupEvents -> f LookupEvents)
-> ((Maybe [LookupAttribute] -> f (Maybe [LookupAttribute]))
    -> Maybe [LookupAttribute] -> f (Maybe [LookupAttribute]))
-> (Maybe [LookupAttribute] -> f (Maybe [LookupAttribute]))
-> LookupEvents
-> f LookupEvents
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [LookupAttribute]
  [LookupAttribute]
  [LookupAttribute]
  [LookupAttribute]
-> Iso
     (Maybe [LookupAttribute])
     (Maybe [LookupAttribute])
     (Maybe [LookupAttribute])
     (Maybe [LookupAttribute])
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
  [LookupAttribute]
  [LookupAttribute]
  [LookupAttribute]
  [LookupAttribute]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The token to use to get the next page of results after a previous API
-- call. This token must be passed in with the same parameters that were
-- specified in the the original call. For example, if the original call
-- specified an AttributeKey of \'Username\' with a value of \'root\', the
-- call with NextToken should include those same parameters.
lookupEvents_nextToken :: Lens.Lens' LookupEvents (Prelude.Maybe Prelude.Text)
lookupEvents_nextToken :: (Maybe Text -> f (Maybe Text)) -> LookupEvents -> f LookupEvents
lookupEvents_nextToken = (LookupEvents -> Maybe Text)
-> (LookupEvents -> Maybe Text -> LookupEvents)
-> Lens LookupEvents LookupEvents (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LookupEvents' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:LookupEvents' :: LookupEvents -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: LookupEvents
s@LookupEvents' {} Maybe Text
a -> LookupEvents
s {$sel:nextToken:LookupEvents' :: Maybe Text
nextToken = Maybe Text
a} :: LookupEvents)

-- | Specifies that only events that occur before or at the specified time
-- are returned. If the specified end time is before the specified start
-- time, an error is returned.
lookupEvents_endTime :: Lens.Lens' LookupEvents (Prelude.Maybe Prelude.UTCTime)
lookupEvents_endTime :: (Maybe UTCTime -> f (Maybe UTCTime))
-> LookupEvents -> f LookupEvents
lookupEvents_endTime = (LookupEvents -> Maybe POSIX)
-> (LookupEvents -> Maybe POSIX -> LookupEvents)
-> Lens LookupEvents LookupEvents (Maybe POSIX) (Maybe POSIX)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LookupEvents' {Maybe POSIX
endTime :: Maybe POSIX
$sel:endTime:LookupEvents' :: LookupEvents -> Maybe POSIX
endTime} -> Maybe POSIX
endTime) (\s :: LookupEvents
s@LookupEvents' {} Maybe POSIX
a -> LookupEvents
s {$sel:endTime:LookupEvents' :: Maybe POSIX
endTime = Maybe POSIX
a} :: LookupEvents) ((Maybe POSIX -> f (Maybe POSIX))
 -> LookupEvents -> f LookupEvents)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe POSIX -> f (Maybe POSIX))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> LookupEvents
-> f LookupEvents
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso POSIX POSIX UTCTime UTCTime
-> Iso (Maybe POSIX) (Maybe POSIX) (Maybe UTCTime) (Maybe UTCTime)
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 POSIX POSIX UTCTime UTCTime
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

-- | The number of events to return. Possible values are 1 through 50. The
-- default is 50.
lookupEvents_maxResults :: Lens.Lens' LookupEvents (Prelude.Maybe Prelude.Natural)
lookupEvents_maxResults :: (Maybe Natural -> f (Maybe Natural))
-> LookupEvents -> f LookupEvents
lookupEvents_maxResults = (LookupEvents -> Maybe Natural)
-> (LookupEvents -> Maybe Natural -> LookupEvents)
-> Lens LookupEvents LookupEvents (Maybe Natural) (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LookupEvents' {Maybe Natural
maxResults :: Maybe Natural
$sel:maxResults:LookupEvents' :: LookupEvents -> Maybe Natural
maxResults} -> Maybe Natural
maxResults) (\s :: LookupEvents
s@LookupEvents' {} Maybe Natural
a -> LookupEvents
s {$sel:maxResults:LookupEvents' :: Maybe Natural
maxResults = Maybe Natural
a} :: LookupEvents)

instance Core.AWSPager LookupEvents where
  page :: LookupEvents -> AWSResponse LookupEvents -> Maybe LookupEvents
page LookupEvents
rq AWSResponse LookupEvents
rs
    | Maybe Text -> Bool
forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse LookupEvents
LookupEventsResponse
rs
            LookupEventsResponse
-> Getting (First Text) LookupEventsResponse Text -> Maybe Text
forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? (Maybe Text -> Const (First Text) (Maybe Text))
-> LookupEventsResponse -> Const (First Text) LookupEventsResponse
Lens' LookupEventsResponse (Maybe Text)
lookupEventsResponse_nextToken ((Maybe Text -> Const (First Text) (Maybe Text))
 -> LookupEventsResponse -> Const (First Text) LookupEventsResponse)
-> ((Text -> Const (First Text) Text)
    -> Maybe Text -> Const (First Text) (Maybe Text))
-> Getting (First Text) LookupEventsResponse Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (Text -> Const (First Text) Text)
-> Maybe Text -> Const (First Text) (Maybe Text)
forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just
        ) =
      Maybe LookupEvents
forall a. Maybe a
Prelude.Nothing
    | Maybe [Event] -> Bool
forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse LookupEvents
LookupEventsResponse
rs
            LookupEventsResponse
-> Getting (First [Event]) LookupEventsResponse [Event]
-> Maybe [Event]
forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? (Maybe [Event] -> Const (First [Event]) (Maybe [Event]))
-> LookupEventsResponse
-> Const (First [Event]) LookupEventsResponse
Lens' LookupEventsResponse (Maybe [Event])
lookupEventsResponse_events ((Maybe [Event] -> Const (First [Event]) (Maybe [Event]))
 -> LookupEventsResponse
 -> Const (First [Event]) LookupEventsResponse)
-> (([Event] -> Const (First [Event]) [Event])
    -> Maybe [Event] -> Const (First [Event]) (Maybe [Event]))
-> Getting (First [Event]) LookupEventsResponse [Event]
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Event] -> Const (First [Event]) [Event])
-> Maybe [Event] -> Const (First [Event]) (Maybe [Event])
forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just
        ) =
      Maybe LookupEvents
forall a. Maybe a
Prelude.Nothing
    | Bool
Prelude.otherwise =
      LookupEvents -> Maybe LookupEvents
forall a. a -> Maybe a
Prelude.Just (LookupEvents -> Maybe LookupEvents)
-> LookupEvents -> Maybe LookupEvents
forall a b. (a -> b) -> a -> b
Prelude.$
        LookupEvents
rq
          LookupEvents -> (LookupEvents -> LookupEvents) -> LookupEvents
forall a b. a -> (a -> b) -> b
Prelude.& (Maybe Text -> Identity (Maybe Text))
-> LookupEvents -> Identity LookupEvents
Lens LookupEvents LookupEvents (Maybe Text) (Maybe Text)
lookupEvents_nextToken
          ((Maybe Text -> Identity (Maybe Text))
 -> LookupEvents -> Identity LookupEvents)
-> Maybe Text -> LookupEvents -> LookupEvents
forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse LookupEvents
LookupEventsResponse
rs
          LookupEventsResponse
-> Getting (First Text) LookupEventsResponse Text -> Maybe Text
forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? (Maybe Text -> Const (First Text) (Maybe Text))
-> LookupEventsResponse -> Const (First Text) LookupEventsResponse
Lens' LookupEventsResponse (Maybe Text)
lookupEventsResponse_nextToken ((Maybe Text -> Const (First Text) (Maybe Text))
 -> LookupEventsResponse -> Const (First Text) LookupEventsResponse)
-> ((Text -> Const (First Text) Text)
    -> Maybe Text -> Const (First Text) (Maybe Text))
-> Getting (First Text) LookupEventsResponse Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (Text -> Const (First Text) Text)
-> Maybe Text -> Const (First Text) (Maybe Text)
forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just

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

instance Prelude.NFData LookupEvents

instance Core.ToHeaders LookupEvents where
  toHeaders :: LookupEvents -> ResponseHeaders
toHeaders =
    ResponseHeaders -> LookupEvents -> 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.LookupEvents" ::
                          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 LookupEvents where
  toJSON :: LookupEvents -> Value
toJSON LookupEvents' {Maybe Natural
Maybe [LookupAttribute]
Maybe Text
Maybe POSIX
Maybe EventCategory
maxResults :: Maybe Natural
endTime :: Maybe POSIX
nextToken :: Maybe Text
lookupAttributes :: Maybe [LookupAttribute]
startTime :: Maybe POSIX
eventCategory :: Maybe EventCategory
$sel:maxResults:LookupEvents' :: LookupEvents -> Maybe Natural
$sel:endTime:LookupEvents' :: LookupEvents -> Maybe POSIX
$sel:nextToken:LookupEvents' :: LookupEvents -> Maybe Text
$sel:lookupAttributes:LookupEvents' :: LookupEvents -> Maybe [LookupAttribute]
$sel:startTime:LookupEvents' :: LookupEvents -> Maybe POSIX
$sel:eventCategory:LookupEvents' :: LookupEvents -> Maybe EventCategory
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"EventCategory" Text -> EventCategory -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (EventCategory -> Pair) -> Maybe EventCategory -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe EventCategory
eventCategory,
            (Text
"StartTime" Text -> POSIX -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (POSIX -> Pair) -> Maybe POSIX -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe POSIX
startTime,
            (Text
"LookupAttributes" Text -> [LookupAttribute] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              ([LookupAttribute] -> Pair)
-> Maybe [LookupAttribute] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [LookupAttribute]
lookupAttributes,
            (Text
"NextToken" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
nextToken,
            (Text
"EndTime" Text -> POSIX -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (POSIX -> Pair) -> Maybe POSIX -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe POSIX
endTime,
            (Text
"MaxResults" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Natural -> Pair) -> Maybe Natural -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
maxResults
          ]
      )

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

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

-- | Contains a response to a LookupEvents action.
--
-- /See:/ 'newLookupEventsResponse' smart constructor.
data LookupEventsResponse = LookupEventsResponse'
  { -- | The token to use to get the next page of results after a previous API
    -- call. If the token does not appear, there are no more results to return.
    -- The token must be passed in with the same parameters as the previous
    -- call. For example, if the original call specified an AttributeKey of
    -- \'Username\' with a value of \'root\', the call with NextToken should
    -- include those same parameters.
    LookupEventsResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | A list of events returned based on the lookup attributes specified and
    -- the CloudTrail event. The events list is sorted by time. The most recent
    -- event is listed first.
    LookupEventsResponse -> Maybe [Event]
events :: Prelude.Maybe [Event],
    -- | The response's http status code.
    LookupEventsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (LookupEventsResponse -> LookupEventsResponse -> Bool
(LookupEventsResponse -> LookupEventsResponse -> Bool)
-> (LookupEventsResponse -> LookupEventsResponse -> Bool)
-> Eq LookupEventsResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LookupEventsResponse -> LookupEventsResponse -> Bool
$c/= :: LookupEventsResponse -> LookupEventsResponse -> Bool
== :: LookupEventsResponse -> LookupEventsResponse -> Bool
$c== :: LookupEventsResponse -> LookupEventsResponse -> Bool
Prelude.Eq, ReadPrec [LookupEventsResponse]
ReadPrec LookupEventsResponse
Int -> ReadS LookupEventsResponse
ReadS [LookupEventsResponse]
(Int -> ReadS LookupEventsResponse)
-> ReadS [LookupEventsResponse]
-> ReadPrec LookupEventsResponse
-> ReadPrec [LookupEventsResponse]
-> Read LookupEventsResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [LookupEventsResponse]
$creadListPrec :: ReadPrec [LookupEventsResponse]
readPrec :: ReadPrec LookupEventsResponse
$creadPrec :: ReadPrec LookupEventsResponse
readList :: ReadS [LookupEventsResponse]
$creadList :: ReadS [LookupEventsResponse]
readsPrec :: Int -> ReadS LookupEventsResponse
$creadsPrec :: Int -> ReadS LookupEventsResponse
Prelude.Read, Int -> LookupEventsResponse -> ShowS
[LookupEventsResponse] -> ShowS
LookupEventsResponse -> String
(Int -> LookupEventsResponse -> ShowS)
-> (LookupEventsResponse -> String)
-> ([LookupEventsResponse] -> ShowS)
-> Show LookupEventsResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LookupEventsResponse] -> ShowS
$cshowList :: [LookupEventsResponse] -> ShowS
show :: LookupEventsResponse -> String
$cshow :: LookupEventsResponse -> String
showsPrec :: Int -> LookupEventsResponse -> ShowS
$cshowsPrec :: Int -> LookupEventsResponse -> ShowS
Prelude.Show, (forall x. LookupEventsResponse -> Rep LookupEventsResponse x)
-> (forall x. Rep LookupEventsResponse x -> LookupEventsResponse)
-> Generic LookupEventsResponse
forall x. Rep LookupEventsResponse x -> LookupEventsResponse
forall x. LookupEventsResponse -> Rep LookupEventsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep LookupEventsResponse x -> LookupEventsResponse
$cfrom :: forall x. LookupEventsResponse -> Rep LookupEventsResponse x
Prelude.Generic)

-- |
-- Create a value of 'LookupEventsResponse' 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:
--
-- 'nextToken', 'lookupEventsResponse_nextToken' - The token to use to get the next page of results after a previous API
-- call. If the token does not appear, there are no more results to return.
-- The token must be passed in with the same parameters as the previous
-- call. For example, if the original call specified an AttributeKey of
-- \'Username\' with a value of \'root\', the call with NextToken should
-- include those same parameters.
--
-- 'events', 'lookupEventsResponse_events' - A list of events returned based on the lookup attributes specified and
-- the CloudTrail event. The events list is sorted by time. The most recent
-- event is listed first.
--
-- 'httpStatus', 'lookupEventsResponse_httpStatus' - The response's http status code.
newLookupEventsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  LookupEventsResponse
newLookupEventsResponse :: Int -> LookupEventsResponse
newLookupEventsResponse Int
pHttpStatus_ =
  LookupEventsResponse' :: Maybe Text -> Maybe [Event] -> Int -> LookupEventsResponse
LookupEventsResponse'
    { $sel:nextToken:LookupEventsResponse' :: Maybe Text
nextToken = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:events:LookupEventsResponse' :: Maybe [Event]
events = Maybe [Event]
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:LookupEventsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The token to use to get the next page of results after a previous API
-- call. If the token does not appear, there are no more results to return.
-- The token must be passed in with the same parameters as the previous
-- call. For example, if the original call specified an AttributeKey of
-- \'Username\' with a value of \'root\', the call with NextToken should
-- include those same parameters.
lookupEventsResponse_nextToken :: Lens.Lens' LookupEventsResponse (Prelude.Maybe Prelude.Text)
lookupEventsResponse_nextToken :: (Maybe Text -> f (Maybe Text))
-> LookupEventsResponse -> f LookupEventsResponse
lookupEventsResponse_nextToken = (LookupEventsResponse -> Maybe Text)
-> (LookupEventsResponse -> Maybe Text -> LookupEventsResponse)
-> Lens' LookupEventsResponse (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LookupEventsResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:LookupEventsResponse' :: LookupEventsResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: LookupEventsResponse
s@LookupEventsResponse' {} Maybe Text
a -> LookupEventsResponse
s {$sel:nextToken:LookupEventsResponse' :: Maybe Text
nextToken = Maybe Text
a} :: LookupEventsResponse)

-- | A list of events returned based on the lookup attributes specified and
-- the CloudTrail event. The events list is sorted by time. The most recent
-- event is listed first.
lookupEventsResponse_events :: Lens.Lens' LookupEventsResponse (Prelude.Maybe [Event])
lookupEventsResponse_events :: (Maybe [Event] -> f (Maybe [Event]))
-> LookupEventsResponse -> f LookupEventsResponse
lookupEventsResponse_events = (LookupEventsResponse -> Maybe [Event])
-> (LookupEventsResponse -> Maybe [Event] -> LookupEventsResponse)
-> Lens' LookupEventsResponse (Maybe [Event])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LookupEventsResponse' {Maybe [Event]
events :: Maybe [Event]
$sel:events:LookupEventsResponse' :: LookupEventsResponse -> Maybe [Event]
events} -> Maybe [Event]
events) (\s :: LookupEventsResponse
s@LookupEventsResponse' {} Maybe [Event]
a -> LookupEventsResponse
s {$sel:events:LookupEventsResponse' :: Maybe [Event]
events = Maybe [Event]
a} :: LookupEventsResponse) ((Maybe [Event] -> f (Maybe [Event]))
 -> LookupEventsResponse -> f LookupEventsResponse)
-> ((Maybe [Event] -> f (Maybe [Event]))
    -> Maybe [Event] -> f (Maybe [Event]))
-> (Maybe [Event] -> f (Maybe [Event]))
-> LookupEventsResponse
-> f LookupEventsResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Event] [Event] [Event] [Event]
-> Iso
     (Maybe [Event]) (Maybe [Event]) (Maybe [Event]) (Maybe [Event])
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 [Event] [Event] [Event] [Event]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.NFData LookupEventsResponse