{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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'
  { -- | 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,
    -- | A JSON string that contains a representation of the event returned.
    Event -> Maybe Text
cloudTrailEvent :: Prelude.Maybe Prelude.Text,
    -- | The CloudTrail ID of the event returned.
    Event -> Maybe Text
eventId :: Prelude.Maybe Prelude.Text,
    -- | The name of the event returned.
    Event -> Maybe Text
eventName :: Prelude.Maybe Prelude.Text,
    -- | The Amazon Web Services service to which the request was made.
    Event -> Maybe Text
eventSource :: Prelude.Maybe Prelude.Text,
    -- | The date and time of the event returned.
    Event -> Maybe POSIX
eventTime :: Prelude.Maybe Data.POSIX,
    -- | Information about whether the event is a write event or a read event.
    Event -> Maybe Text
readOnly :: Prelude.Maybe Prelude.Text,
    -- | A list of resources referenced by the event returned.
    Event -> Maybe [Resource]
resources :: Prelude.Maybe [Resource],
    -- | 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
  }
  deriving (Event -> Event -> Bool
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]
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
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. 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:
--
-- '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.
--
-- 'cloudTrailEvent', 'event_cloudTrailEvent' - A JSON string that contains a representation of the event returned.
--
-- 'eventId', 'event_eventId' - The CloudTrail ID of the event returned.
--
-- 'eventName', 'event_eventName' - The name of the event returned.
--
-- 'eventSource', 'event_eventSource' - The Amazon Web Services service to which the request was made.
--
-- 'eventTime', 'event_eventTime' - The date and time of the event returned.
--
-- 'readOnly', 'event_readOnly' - Information about whether the event is a write event or a read event.
--
-- 'resources', 'event_resources' - A list of resources referenced by the event returned.
--
-- 'username', 'event_username' - A user name or role name of the requester that called the API in the
-- event returned.
newEvent ::
  Event
newEvent :: Event
newEvent =
  Event'
    { $sel:accessKeyId:Event' :: Maybe Text
accessKeyId = forall a. Maybe a
Prelude.Nothing,
      $sel:cloudTrailEvent:Event' :: Maybe Text
cloudTrailEvent = forall a. Maybe a
Prelude.Nothing,
      $sel:eventId:Event' :: Maybe Text
eventId = forall a. Maybe a
Prelude.Nothing,
      $sel:eventName:Event' :: Maybe Text
eventName = forall a. Maybe a
Prelude.Nothing,
      $sel:eventSource:Event' :: Maybe Text
eventSource = forall a. Maybe a
Prelude.Nothing,
      $sel:eventTime:Event' :: Maybe POSIX
eventTime = forall a. Maybe a
Prelude.Nothing,
      $sel:readOnly:Event' :: Maybe Text
readOnly = forall a. Maybe a
Prelude.Nothing,
      $sel:resources:Event' :: Maybe [Resource]
resources = forall a. Maybe a
Prelude.Nothing,
      $sel:username:Event' :: Maybe Text
username = forall a. Maybe a
Prelude.Nothing
    }

-- | 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 :: Lens' Event (Maybe Text)
event_accessKeyId = 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)

-- | A JSON string that contains a representation of the event returned.
event_cloudTrailEvent :: Lens.Lens' Event (Prelude.Maybe Prelude.Text)
event_cloudTrailEvent :: Lens' Event (Maybe Text)
event_cloudTrailEvent = 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 CloudTrail ID of the event returned.
event_eventId :: Lens.Lens' Event (Prelude.Maybe Prelude.Text)
event_eventId :: Lens' Event (Maybe Text)
event_eventId = 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)

-- | The name of the event returned.
event_eventName :: Lens.Lens' Event (Prelude.Maybe Prelude.Text)
event_eventName :: Lens' Event (Maybe Text)
event_eventName = 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)

-- | The Amazon Web Services service to which the request was made.
event_eventSource :: Lens.Lens' Event (Prelude.Maybe Prelude.Text)
event_eventSource :: Lens' Event (Maybe Text)
event_eventSource = 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 date and time of the event returned.
event_eventTime :: Lens.Lens' Event (Prelude.Maybe Prelude.UTCTime)
event_eventTime :: Lens' Event (Maybe UTCTime)
event_eventTime = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall (a :: Format). Iso' (Time a) UTCTime
Data._Time

-- | Information about whether the event is a write event or a read event.
event_readOnly :: Lens.Lens' Event (Prelude.Maybe Prelude.Text)
event_readOnly :: Lens' Event (Maybe Text)
event_readOnly = 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)

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

-- | 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 :: Lens' Event (Maybe Text)
event_username = 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)

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

instance Prelude.Hashable Event where
  hashWithSalt :: Int -> Event -> Int
hashWithSalt Int
_salt Event' {Maybe [Resource]
Maybe Text
Maybe POSIX
username :: Maybe Text
resources :: Maybe [Resource]
readOnly :: Maybe Text
eventTime :: Maybe POSIX
eventSource :: Maybe Text
eventName :: Maybe Text
eventId :: Maybe Text
cloudTrailEvent :: Maybe Text
accessKeyId :: Maybe Text
$sel:username:Event' :: Event -> Maybe Text
$sel:resources:Event' :: Event -> Maybe [Resource]
$sel:readOnly:Event' :: Event -> Maybe Text
$sel:eventTime:Event' :: Event -> Maybe POSIX
$sel:eventSource:Event' :: Event -> Maybe Text
$sel:eventName:Event' :: Event -> Maybe Text
$sel:eventId:Event' :: Event -> Maybe Text
$sel:cloudTrailEvent:Event' :: Event -> Maybe Text
$sel:accessKeyId:Event' :: Event -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
accessKeyId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
cloudTrailEvent
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
eventId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
eventName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
eventSource
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe POSIX
eventTime
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
readOnly
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Resource]
resources
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
username

instance Prelude.NFData Event where
  rnf :: Event -> ()
rnf Event' {Maybe [Resource]
Maybe Text
Maybe POSIX
username :: Maybe Text
resources :: Maybe [Resource]
readOnly :: Maybe Text
eventTime :: Maybe POSIX
eventSource :: Maybe Text
eventName :: Maybe Text
eventId :: Maybe Text
cloudTrailEvent :: Maybe Text
accessKeyId :: Maybe Text
$sel:username:Event' :: Event -> Maybe Text
$sel:resources:Event' :: Event -> Maybe [Resource]
$sel:readOnly:Event' :: Event -> Maybe Text
$sel:eventTime:Event' :: Event -> Maybe POSIX
$sel:eventSource:Event' :: Event -> Maybe Text
$sel:eventName:Event' :: Event -> Maybe Text
$sel:eventId:Event' :: Event -> Maybe Text
$sel:cloudTrailEvent:Event' :: Event -> Maybe Text
$sel:accessKeyId:Event' :: Event -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
accessKeyId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
cloudTrailEvent
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
eventId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
eventName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
eventSource
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe POSIX
eventTime
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
readOnly
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [Resource]
resources
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
username