{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# 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.Types.Event
-- 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)
module Amazonka.CloudTrail.Types.Event where

import Amazonka.CloudTrail.Types.Resource
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Contains information about an event that was returned by a lookup
-- request. The result includes a representation of a CloudTrail event.
--
-- /See:/ 'newEvent' smart constructor.
data Event = Event'
  { -- | A user name or role name of the requester that called the API in the
    -- event returned.
    Event -> Maybe Text
username :: Prelude.Maybe Prelude.Text,
    -- | A list of resources referenced by the event returned.
    Event -> Maybe [Resource]
resources :: Prelude.Maybe [Resource],
    -- | The date and time of the event returned.
    Event -> Maybe POSIX
eventTime :: Prelude.Maybe Core.POSIX,
    -- | A JSON string that contains a representation of the event returned.
    Event -> Maybe Text
cloudTrailEvent :: Prelude.Maybe Prelude.Text,
    -- | The name of the event returned.
    Event -> Maybe Text
eventName :: Prelude.Maybe Prelude.Text,
    -- | Information about whether the event is a write event or a read event.
    Event -> Maybe Text
readOnly :: Prelude.Maybe Prelude.Text,
    -- | The Amazon Web Services access key ID that was used to sign the request.
    -- If the request was made with temporary security credentials, this is the
    -- access key ID of the temporary credentials.
    Event -> Maybe Text
accessKeyId :: Prelude.Maybe Prelude.Text,
    -- | The Amazon Web Services service to which the request was made.
    Event -> Maybe Text
eventSource :: Prelude.Maybe Prelude.Text,
    -- | The CloudTrail ID of the event returned.
    Event -> Maybe Text
eventId :: Prelude.Maybe Prelude.Text
  }
  deriving (Event -> Event -> Bool
(Event -> Event -> Bool) -> (Event -> Event -> Bool) -> Eq Event
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Event -> Event -> Bool
$c/= :: Event -> Event -> Bool
== :: Event -> Event -> Bool
$c== :: Event -> Event -> Bool
Prelude.Eq, ReadPrec [Event]
ReadPrec Event
Int -> ReadS Event
ReadS [Event]
(Int -> ReadS Event)
-> ReadS [Event]
-> ReadPrec Event
-> ReadPrec [Event]
-> Read Event
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Event]
$creadListPrec :: ReadPrec [Event]
readPrec :: ReadPrec Event
$creadPrec :: ReadPrec Event
readList :: ReadS [Event]
$creadList :: ReadS [Event]
readsPrec :: Int -> ReadS Event
$creadsPrec :: Int -> ReadS Event
Prelude.Read, Int -> Event -> ShowS
[Event] -> ShowS
Event -> String
(Int -> Event -> ShowS)
-> (Event -> String) -> ([Event] -> ShowS) -> Show Event
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Event] -> ShowS
$cshowList :: [Event] -> ShowS
show :: Event -> String
$cshow :: Event -> String
showsPrec :: Int -> Event -> ShowS
$cshowsPrec :: Int -> Event -> ShowS
Prelude.Show, (forall x. Event -> Rep Event x)
-> (forall x. Rep Event x -> Event) -> Generic Event
forall x. Rep Event x -> Event
forall x. Event -> Rep Event x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Event x -> Event
$cfrom :: forall x. Event -> Rep Event x
Prelude.Generic)

-- |
-- Create a value of 'Event' 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:
--
-- 'username', 'event_username' - A user name or role name of the requester that called the API in the
-- event returned.
--
-- 'resources', 'event_resources' - A list of resources referenced by the event returned.
--
-- 'eventTime', 'event_eventTime' - The date and time of the event returned.
--
-- 'cloudTrailEvent', 'event_cloudTrailEvent' - A JSON string that contains a representation of the event returned.
--
-- 'eventName', 'event_eventName' - The name of the event returned.
--
-- 'readOnly', 'event_readOnly' - Information about whether the event is a write event or a read event.
--
-- 'accessKeyId', 'event_accessKeyId' - The Amazon Web Services access key ID that was used to sign the request.
-- If the request was made with temporary security credentials, this is the
-- access key ID of the temporary credentials.
--
-- 'eventSource', 'event_eventSource' - The Amazon Web Services service to which the request was made.
--
-- 'eventId', 'event_eventId' - The CloudTrail ID of the event returned.
newEvent ::
  Event
newEvent :: Event
newEvent =
  Event' :: Maybe Text
-> Maybe [Resource]
-> Maybe POSIX
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Event
Event'
    { $sel:username:Event' :: Maybe Text
username = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:resources:Event' :: Maybe [Resource]
resources = Maybe [Resource]
forall a. Maybe a
Prelude.Nothing,
      $sel:eventTime:Event' :: Maybe POSIX
eventTime = Maybe POSIX
forall a. Maybe a
Prelude.Nothing,
      $sel:cloudTrailEvent:Event' :: Maybe Text
cloudTrailEvent = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:eventName:Event' :: Maybe Text
eventName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:readOnly:Event' :: Maybe Text
readOnly = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:accessKeyId:Event' :: Maybe Text
accessKeyId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:eventSource:Event' :: Maybe Text
eventSource = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:eventId:Event' :: Maybe Text
eventId = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | A user name or role name of the requester that called the API in the
-- event returned.
event_username :: Lens.Lens' Event (Prelude.Maybe Prelude.Text)
event_username :: (Maybe Text -> f (Maybe Text)) -> Event -> f Event
event_username = (Event -> Maybe Text)
-> (Event -> Maybe Text -> Event)
-> Lens Event Event (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Event' {Maybe Text
username :: Maybe Text
$sel:username:Event' :: Event -> Maybe Text
username} -> Maybe Text
username) (\s :: Event
s@Event' {} Maybe Text
a -> Event
s {$sel:username:Event' :: Maybe Text
username = Maybe Text
a} :: Event)

-- | A list of resources referenced by the event returned.
event_resources :: Lens.Lens' Event (Prelude.Maybe [Resource])
event_resources :: (Maybe [Resource] -> f (Maybe [Resource])) -> Event -> f Event
event_resources = (Event -> Maybe [Resource])
-> (Event -> Maybe [Resource] -> Event)
-> Lens Event Event (Maybe [Resource]) (Maybe [Resource])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Event' {Maybe [Resource]
resources :: Maybe [Resource]
$sel:resources:Event' :: Event -> Maybe [Resource]
resources} -> Maybe [Resource]
resources) (\s :: Event
s@Event' {} Maybe [Resource]
a -> Event
s {$sel:resources:Event' :: Maybe [Resource]
resources = Maybe [Resource]
a} :: Event) ((Maybe [Resource] -> f (Maybe [Resource])) -> Event -> f Event)
-> ((Maybe [Resource] -> f (Maybe [Resource]))
    -> Maybe [Resource] -> f (Maybe [Resource]))
-> (Maybe [Resource] -> f (Maybe [Resource]))
-> Event
-> f Event
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Resource] [Resource] [Resource] [Resource]
-> Iso
     (Maybe [Resource])
     (Maybe [Resource])
     (Maybe [Resource])
     (Maybe [Resource])
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 [Resource] [Resource] [Resource] [Resource]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The date and time of the event returned.
event_eventTime :: Lens.Lens' Event (Prelude.Maybe Prelude.UTCTime)
event_eventTime :: (Maybe UTCTime -> f (Maybe UTCTime)) -> Event -> f Event
event_eventTime = (Event -> Maybe POSIX)
-> (Event -> Maybe POSIX -> Event)
-> Lens Event Event (Maybe POSIX) (Maybe POSIX)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Event' {Maybe POSIX
eventTime :: Maybe POSIX
$sel:eventTime:Event' :: Event -> Maybe POSIX
eventTime} -> Maybe POSIX
eventTime) (\s :: Event
s@Event' {} Maybe POSIX
a -> Event
s {$sel:eventTime:Event' :: Maybe POSIX
eventTime = Maybe POSIX
a} :: Event) ((Maybe POSIX -> f (Maybe POSIX)) -> Event -> f Event)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe POSIX -> f (Maybe POSIX))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> Event
-> f Event
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

-- | A JSON string that contains a representation of the event returned.
event_cloudTrailEvent :: Lens.Lens' Event (Prelude.Maybe Prelude.Text)
event_cloudTrailEvent :: (Maybe Text -> f (Maybe Text)) -> Event -> f Event
event_cloudTrailEvent = (Event -> Maybe Text)
-> (Event -> Maybe Text -> Event)
-> Lens Event Event (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Event' {Maybe Text
cloudTrailEvent :: Maybe Text
$sel:cloudTrailEvent:Event' :: Event -> Maybe Text
cloudTrailEvent} -> Maybe Text
cloudTrailEvent) (\s :: Event
s@Event' {} Maybe Text
a -> Event
s {$sel:cloudTrailEvent:Event' :: Maybe Text
cloudTrailEvent = Maybe Text
a} :: Event)

-- | The name of the event returned.
event_eventName :: Lens.Lens' Event (Prelude.Maybe Prelude.Text)
event_eventName :: (Maybe Text -> f (Maybe Text)) -> Event -> f Event
event_eventName = (Event -> Maybe Text)
-> (Event -> Maybe Text -> Event)
-> Lens Event Event (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Event' {Maybe Text
eventName :: Maybe Text
$sel:eventName:Event' :: Event -> Maybe Text
eventName} -> Maybe Text
eventName) (\s :: Event
s@Event' {} Maybe Text
a -> Event
s {$sel:eventName:Event' :: Maybe Text
eventName = Maybe Text
a} :: Event)

-- | Information about whether the event is a write event or a read event.
event_readOnly :: Lens.Lens' Event (Prelude.Maybe Prelude.Text)
event_readOnly :: (Maybe Text -> f (Maybe Text)) -> Event -> f Event
event_readOnly = (Event -> Maybe Text)
-> (Event -> Maybe Text -> Event)
-> Lens Event Event (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Event' {Maybe Text
readOnly :: Maybe Text
$sel:readOnly:Event' :: Event -> Maybe Text
readOnly} -> Maybe Text
readOnly) (\s :: Event
s@Event' {} Maybe Text
a -> Event
s {$sel:readOnly:Event' :: Maybe Text
readOnly = Maybe Text
a} :: Event)

-- | The Amazon Web Services access key ID that was used to sign the request.
-- If the request was made with temporary security credentials, this is the
-- access key ID of the temporary credentials.
event_accessKeyId :: Lens.Lens' Event (Prelude.Maybe Prelude.Text)
event_accessKeyId :: (Maybe Text -> f (Maybe Text)) -> Event -> f Event
event_accessKeyId = (Event -> Maybe Text)
-> (Event -> Maybe Text -> Event)
-> Lens Event Event (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Event' {Maybe Text
accessKeyId :: Maybe Text
$sel:accessKeyId:Event' :: Event -> Maybe Text
accessKeyId} -> Maybe Text
accessKeyId) (\s :: Event
s@Event' {} Maybe Text
a -> Event
s {$sel:accessKeyId:Event' :: Maybe Text
accessKeyId = Maybe Text
a} :: Event)

-- | The Amazon Web Services service to which the request was made.
event_eventSource :: Lens.Lens' Event (Prelude.Maybe Prelude.Text)
event_eventSource :: (Maybe Text -> f (Maybe Text)) -> Event -> f Event
event_eventSource = (Event -> Maybe Text)
-> (Event -> Maybe Text -> Event)
-> Lens Event Event (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Event' {Maybe Text
eventSource :: Maybe Text
$sel:eventSource:Event' :: Event -> Maybe Text
eventSource} -> Maybe Text
eventSource) (\s :: Event
s@Event' {} Maybe Text
a -> Event
s {$sel:eventSource:Event' :: Maybe Text
eventSource = Maybe Text
a} :: Event)

-- | The CloudTrail ID of the event returned.
event_eventId :: Lens.Lens' Event (Prelude.Maybe Prelude.Text)
event_eventId :: (Maybe Text -> f (Maybe Text)) -> Event -> f Event
event_eventId = (Event -> Maybe Text)
-> (Event -> Maybe Text -> Event)
-> Lens Event Event (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Event' {Maybe Text
eventId :: Maybe Text
$sel:eventId:Event' :: Event -> Maybe Text
eventId} -> Maybe Text
eventId) (\s :: Event
s@Event' {} Maybe Text
a -> Event
s {$sel:eventId:Event' :: Maybe Text
eventId = Maybe Text
a} :: Event)

instance Core.FromJSON Event where
  parseJSON :: Value -> Parser Event
parseJSON =
    String -> (Object -> Parser Event) -> Value -> Parser Event
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Event"
      ( \Object
x ->
          Maybe Text
-> Maybe [Resource]
-> Maybe POSIX
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Event
Event'
            (Maybe Text
 -> Maybe [Resource]
 -> Maybe POSIX
 -> Maybe Text
 -> Maybe Text
 -> Maybe Text
 -> Maybe Text
 -> Maybe Text
 -> Maybe Text
 -> Event)
-> Parser (Maybe Text)
-> Parser
     (Maybe [Resource]
      -> Maybe POSIX
      -> Maybe Text
      -> Maybe Text
      -> Maybe Text
      -> Maybe Text
      -> Maybe Text
      -> Maybe Text
      -> Event)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Username")
            Parser
  (Maybe [Resource]
   -> Maybe POSIX
   -> Maybe Text
   -> Maybe Text
   -> Maybe Text
   -> Maybe Text
   -> Maybe Text
   -> Maybe Text
   -> Event)
-> Parser (Maybe [Resource])
-> Parser
     (Maybe POSIX
      -> Maybe Text
      -> Maybe Text
      -> Maybe Text
      -> Maybe Text
      -> Maybe Text
      -> Maybe Text
      -> Event)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (Maybe [Resource]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Resources" Parser (Maybe (Maybe [Resource]))
-> Maybe [Resource] -> Parser (Maybe [Resource])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [Resource]
forall a. Monoid a => a
Prelude.mempty)
            Parser
  (Maybe POSIX
   -> Maybe Text
   -> Maybe Text
   -> Maybe Text
   -> Maybe Text
   -> Maybe Text
   -> Maybe Text
   -> Event)
-> Parser (Maybe POSIX)
-> Parser
     (Maybe Text
      -> Maybe Text
      -> Maybe Text
      -> Maybe Text
      -> Maybe Text
      -> Maybe Text
      -> Event)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe POSIX)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"EventTime")
            Parser
  (Maybe Text
   -> Maybe Text
   -> Maybe Text
   -> Maybe Text
   -> Maybe Text
   -> Maybe Text
   -> Event)
-> Parser (Maybe Text)
-> Parser
     (Maybe Text
      -> Maybe Text -> Maybe Text -> Maybe Text -> Maybe Text -> Event)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"CloudTrailEvent")
            Parser
  (Maybe Text
   -> Maybe Text -> Maybe Text -> Maybe Text -> Maybe Text -> Event)
-> Parser (Maybe Text)
-> Parser
     (Maybe Text -> Maybe Text -> Maybe Text -> Maybe Text -> Event)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"EventName")
            Parser
  (Maybe Text -> Maybe Text -> Maybe Text -> Maybe Text -> Event)
-> Parser (Maybe Text)
-> Parser (Maybe Text -> Maybe Text -> Maybe Text -> Event)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ReadOnly")
            Parser (Maybe Text -> Maybe Text -> Maybe Text -> Event)
-> Parser (Maybe Text)
-> Parser (Maybe Text -> Maybe Text -> Event)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"AccessKeyId")
            Parser (Maybe Text -> Maybe Text -> Event)
-> Parser (Maybe Text) -> Parser (Maybe Text -> Event)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"EventSource")
            Parser (Maybe Text -> Event) -> Parser (Maybe Text) -> Parser Event
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"EventId")
      )

instance Prelude.Hashable Event

instance Prelude.NFData Event