module Network.AWS.CloudTrail.Types
(
CloudTrail
, JSONError
, Event
, event
, eCloudTrailEvent
, eEventId
, eEventName
, eEventTime
, eResources
, eUsername
, Trail
, trail
, tCloudWatchLogsLogGroupArn
, tCloudWatchLogsRoleArn
, tIncludeGlobalServiceEvents
, tName
, tS3BucketName
, tS3KeyPrefix
, tSnsTopicName
, LookupAttribute
, lookupAttribute
, laAttributeKey
, laAttributeValue
, LookupAttributeKey (..)
, Resource
, resource
, rResourceName
, rResourceType
) where
import Network.AWS.Prelude
import Network.AWS.Signing
import qualified GHC.Exts
data CloudTrail
instance AWSService CloudTrail where
type Sg CloudTrail = V4
type Er CloudTrail = JSONError
service = service'
where
service' :: Service CloudTrail
service' = Service
{ _svcAbbrev = "CloudTrail"
, _svcPrefix = "cloudtrail"
, _svcVersion = "2013-11-01"
, _svcTargetPrefix = Just "com.amazonaws.cloudtrail.v20131101.CloudTrail_20131101"
, _svcJSONVersion = Just "1.1"
, _svcHandle = handle
, _svcRetry = retry
}
handle :: Status
-> Maybe (LazyByteString -> ServiceError JSONError)
handle = jsonError statusSuccess service'
retry :: Retry CloudTrail
retry = Exponential
{ _retryBase = 0.05
, _retryGrowth = 2
, _retryAttempts = 5
, _retryCheck = check
}
check :: Status
-> JSONError
-> Bool
check (statusCode -> s) (awsErrorCode -> e)
| s == 500 = True
| s == 509 = True
| s == 503 = True
| otherwise = False
data Event = Event
{ _eCloudTrailEvent :: Maybe Text
, _eEventId :: Maybe Text
, _eEventName :: Maybe Text
, _eEventTime :: Maybe POSIX
, _eResources :: List "Resources" Resource
, _eUsername :: Maybe Text
} deriving (Eq, Read, Show)
event :: Event
event = Event
{ _eEventId = Nothing
, _eEventName = Nothing
, _eEventTime = Nothing
, _eUsername = Nothing
, _eResources = mempty
, _eCloudTrailEvent = Nothing
}
eCloudTrailEvent :: Lens' Event (Maybe Text)
eCloudTrailEvent = lens _eCloudTrailEvent (\s a -> s { _eCloudTrailEvent = a })
eEventId :: Lens' Event (Maybe Text)
eEventId = lens _eEventId (\s a -> s { _eEventId = a })
eEventName :: Lens' Event (Maybe Text)
eEventName = lens _eEventName (\s a -> s { _eEventName = a })
eEventTime :: Lens' Event (Maybe UTCTime)
eEventTime = lens _eEventTime (\s a -> s { _eEventTime = a }) . mapping _Time
eResources :: Lens' Event [Resource]
eResources = lens _eResources (\s a -> s { _eResources = a }) . _List
eUsername :: Lens' Event (Maybe Text)
eUsername = lens _eUsername (\s a -> s { _eUsername = a })
instance FromJSON Event where
parseJSON = withObject "Event" $ \o -> Event
<$> o .:? "CloudTrailEvent"
<*> o .:? "EventId"
<*> o .:? "EventName"
<*> o .:? "EventTime"
<*> o .:? "Resources" .!= mempty
<*> o .:? "Username"
instance ToJSON Event where
toJSON Event{..} = object
[ "EventId" .= _eEventId
, "EventName" .= _eEventName
, "EventTime" .= _eEventTime
, "Username" .= _eUsername
, "Resources" .= _eResources
, "CloudTrailEvent" .= _eCloudTrailEvent
]
data Trail = Trail
{ _tCloudWatchLogsLogGroupArn :: Maybe Text
, _tCloudWatchLogsRoleArn :: Maybe Text
, _tIncludeGlobalServiceEvents :: Maybe Bool
, _tName :: Maybe Text
, _tS3BucketName :: Maybe Text
, _tS3KeyPrefix :: Maybe Text
, _tSnsTopicName :: Maybe Text
} deriving (Eq, Ord, Read, Show)
trail :: Trail
trail = Trail
{ _tName = Nothing
, _tS3BucketName = Nothing
, _tS3KeyPrefix = Nothing
, _tSnsTopicName = Nothing
, _tIncludeGlobalServiceEvents = Nothing
, _tCloudWatchLogsLogGroupArn = Nothing
, _tCloudWatchLogsRoleArn = Nothing
}
tCloudWatchLogsLogGroupArn :: Lens' Trail (Maybe Text)
tCloudWatchLogsLogGroupArn =
lens _tCloudWatchLogsLogGroupArn
(\s a -> s { _tCloudWatchLogsLogGroupArn = a })
tCloudWatchLogsRoleArn :: Lens' Trail (Maybe Text)
tCloudWatchLogsRoleArn =
lens _tCloudWatchLogsRoleArn (\s a -> s { _tCloudWatchLogsRoleArn = a })
tIncludeGlobalServiceEvents :: Lens' Trail (Maybe Bool)
tIncludeGlobalServiceEvents =
lens _tIncludeGlobalServiceEvents
(\s a -> s { _tIncludeGlobalServiceEvents = a })
tName :: Lens' Trail (Maybe Text)
tName = lens _tName (\s a -> s { _tName = a })
tS3BucketName :: Lens' Trail (Maybe Text)
tS3BucketName = lens _tS3BucketName (\s a -> s { _tS3BucketName = a })
tS3KeyPrefix :: Lens' Trail (Maybe Text)
tS3KeyPrefix = lens _tS3KeyPrefix (\s a -> s { _tS3KeyPrefix = a })
tSnsTopicName :: Lens' Trail (Maybe Text)
tSnsTopicName = lens _tSnsTopicName (\s a -> s { _tSnsTopicName = a })
instance FromJSON Trail where
parseJSON = withObject "Trail" $ \o -> Trail
<$> o .:? "CloudWatchLogsLogGroupArn"
<*> o .:? "CloudWatchLogsRoleArn"
<*> o .:? "IncludeGlobalServiceEvents"
<*> o .:? "Name"
<*> o .:? "S3BucketName"
<*> o .:? "S3KeyPrefix"
<*> o .:? "SnsTopicName"
instance ToJSON Trail where
toJSON Trail{..} = object
[ "Name" .= _tName
, "S3BucketName" .= _tS3BucketName
, "S3KeyPrefix" .= _tS3KeyPrefix
, "SnsTopicName" .= _tSnsTopicName
, "IncludeGlobalServiceEvents" .= _tIncludeGlobalServiceEvents
, "CloudWatchLogsLogGroupArn" .= _tCloudWatchLogsLogGroupArn
, "CloudWatchLogsRoleArn" .= _tCloudWatchLogsRoleArn
]
data LookupAttribute = LookupAttribute
{ _laAttributeKey :: LookupAttributeKey
, _laAttributeValue :: Text
} deriving (Eq, Read, Show)
lookupAttribute :: LookupAttributeKey
-> Text
-> LookupAttribute
lookupAttribute p1 p2 = LookupAttribute
{ _laAttributeKey = p1
, _laAttributeValue = p2
}
laAttributeKey :: Lens' LookupAttribute LookupAttributeKey
laAttributeKey = lens _laAttributeKey (\s a -> s { _laAttributeKey = a })
laAttributeValue :: Lens' LookupAttribute Text
laAttributeValue = lens _laAttributeValue (\s a -> s { _laAttributeValue = a })
instance FromJSON LookupAttribute where
parseJSON = withObject "LookupAttribute" $ \o -> LookupAttribute
<$> o .: "AttributeKey"
<*> o .: "AttributeValue"
instance ToJSON LookupAttribute where
toJSON LookupAttribute{..} = object
[ "AttributeKey" .= _laAttributeKey
, "AttributeValue" .= _laAttributeValue
]
data LookupAttributeKey
= EventId
| EventName
| ResourceName
| ResourceType
| Username
deriving (Eq, Ord, Read, Show, Generic, Enum)
instance Hashable LookupAttributeKey
instance FromText LookupAttributeKey where
parser = takeLowerText >>= \case
"eventid" -> pure EventId
"eventname" -> pure EventName
"resourcename" -> pure ResourceName
"resourcetype" -> pure ResourceType
"username" -> pure Username
e -> fail $
"Failure parsing LookupAttributeKey from " ++ show e
instance ToText LookupAttributeKey where
toText = \case
EventId -> "EventId"
EventName -> "EventName"
ResourceName -> "ResourceName"
ResourceType -> "ResourceType"
Username -> "Username"
instance ToByteString LookupAttributeKey
instance ToHeader LookupAttributeKey
instance ToQuery LookupAttributeKey
instance FromJSON LookupAttributeKey where
parseJSON = parseJSONText "LookupAttributeKey"
instance ToJSON LookupAttributeKey where
toJSON = toJSONText
data Resource = Resource
{ _rResourceName :: Maybe Text
, _rResourceType :: Maybe Text
} deriving (Eq, Ord, Read, Show)
resource :: Resource
resource = Resource
{ _rResourceType = Nothing
, _rResourceName = Nothing
}
rResourceName :: Lens' Resource (Maybe Text)
rResourceName = lens _rResourceName (\s a -> s { _rResourceName = a })
rResourceType :: Lens' Resource (Maybe Text)
rResourceType = lens _rResourceType (\s a -> s { _rResourceType = a })
instance FromJSON Resource where
parseJSON = withObject "Resource" $ \o -> Resource
<$> o .:? "ResourceName"
<*> o .:? "ResourceType"
instance ToJSON Resource where
toJSON Resource{..} = object
[ "ResourceType" .= _rResourceType
, "ResourceName" .= _rResourceName
]