module Network.AWS.Kinesis.Types
(
Kinesis
, JSONError
, Shard
, shard
, sAdjacentParentShardId
, sHashKeyRange
, sParentShardId
, sSequenceNumberRange
, sShardId
, Tag
, tag
, tagKey
, tagValue
, StreamDescription
, streamDescription
, sdHasMoreShards
, sdShards
, sdStreamARN
, sdStreamName
, sdStreamStatus
, PutRecordsResultEntry
, putRecordsResultEntry
, prreErrorCode
, prreErrorMessage
, prreSequenceNumber
, prreShardId
, PutRecordsRequestEntry
, putRecordsRequestEntry
, prreData
, prreExplicitHashKey
, prrePartitionKey
, StreamStatus (..)
, HashKeyRange
, hashKeyRange
, hkrEndingHashKey
, hkrStartingHashKey
, Record
, record
, rData
, rPartitionKey
, rSequenceNumber
, SequenceNumberRange
, sequenceNumberRange
, snrEndingSequenceNumber
, snrStartingSequenceNumber
, ShardIteratorType (..)
) where
import Network.AWS.Prelude
import Network.AWS.Signing
import qualified GHC.Exts
data Kinesis
instance AWSService Kinesis where
type Sg Kinesis = V4
type Er Kinesis = JSONError
service = service'
where
service' :: Service Kinesis
service' = Service
{ _svcAbbrev = "Kinesis"
, _svcPrefix = "kinesis"
, _svcVersion = "2013-12-02"
, _svcTargetPrefix = Just "Kinesis_20131202"
, _svcJSONVersion = Just "1.1"
, _svcHandle = handle
, _svcRetry = retry
}
handle :: Status
-> Maybe (LazyByteString -> ServiceError JSONError)
handle = jsonError statusSuccess service'
retry :: Retry Kinesis
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 Shard = Shard
{ _sAdjacentParentShardId :: Maybe Text
, _sHashKeyRange :: HashKeyRange
, _sParentShardId :: Maybe Text
, _sSequenceNumberRange :: SequenceNumberRange
, _sShardId :: Text
} deriving (Eq, Show)
shard :: Text
-> HashKeyRange
-> SequenceNumberRange
-> Shard
shard p1 p2 p3 = Shard
{ _sShardId = p1
, _sHashKeyRange = p2
, _sSequenceNumberRange = p3
, _sParentShardId = Nothing
, _sAdjacentParentShardId = Nothing
}
sAdjacentParentShardId :: Lens' Shard (Maybe Text)
sAdjacentParentShardId =
lens _sAdjacentParentShardId (\s a -> s { _sAdjacentParentShardId = a })
sHashKeyRange :: Lens' Shard HashKeyRange
sHashKeyRange = lens _sHashKeyRange (\s a -> s { _sHashKeyRange = a })
sParentShardId :: Lens' Shard (Maybe Text)
sParentShardId = lens _sParentShardId (\s a -> s { _sParentShardId = a })
sSequenceNumberRange :: Lens' Shard SequenceNumberRange
sSequenceNumberRange =
lens _sSequenceNumberRange (\s a -> s { _sSequenceNumberRange = a })
sShardId :: Lens' Shard Text
sShardId = lens _sShardId (\s a -> s { _sShardId = a })
instance FromJSON Shard where
parseJSON = withObject "Shard" $ \o -> Shard
<$> o .:? "AdjacentParentShardId"
<*> o .: "HashKeyRange"
<*> o .:? "ParentShardId"
<*> o .: "SequenceNumberRange"
<*> o .: "ShardId"
instance ToJSON Shard where
toJSON Shard{..} = object
[ "ShardId" .= _sShardId
, "ParentShardId" .= _sParentShardId
, "AdjacentParentShardId" .= _sAdjacentParentShardId
, "HashKeyRange" .= _sHashKeyRange
, "SequenceNumberRange" .= _sSequenceNumberRange
]
data Tag = Tag
{ _tagKey :: Text
, _tagValue :: Maybe Text
} deriving (Eq, Ord, Show)
tag :: Text
-> Tag
tag p1 = Tag
{ _tagKey = p1
, _tagValue = Nothing
}
tagKey :: Lens' Tag Text
tagKey = lens _tagKey (\s a -> s { _tagKey = a })
tagValue :: Lens' Tag (Maybe Text)
tagValue = lens _tagValue (\s a -> s { _tagValue = a })
instance FromJSON Tag where
parseJSON = withObject "Tag" $ \o -> Tag
<$> o .: "Key"
<*> o .:? "Value"
instance ToJSON Tag where
toJSON Tag{..} = object
[ "Key" .= _tagKey
, "Value" .= _tagValue
]
data StreamDescription = StreamDescription
{ _sdHasMoreShards :: Bool
, _sdShards :: List "Shards" Shard
, _sdStreamARN :: Text
, _sdStreamName :: Text
, _sdStreamStatus :: StreamStatus
} deriving (Eq, Show)
streamDescription :: Text
-> Text
-> StreamStatus
-> Bool
-> StreamDescription
streamDescription p1 p2 p3 p4 = StreamDescription
{ _sdStreamName = p1
, _sdStreamARN = p2
, _sdStreamStatus = p3
, _sdHasMoreShards = p4
, _sdShards = mempty
}
sdHasMoreShards :: Lens' StreamDescription Bool
sdHasMoreShards = lens _sdHasMoreShards (\s a -> s { _sdHasMoreShards = a })
sdShards :: Lens' StreamDescription [Shard]
sdShards = lens _sdShards (\s a -> s { _sdShards = a }) . _List
sdStreamARN :: Lens' StreamDescription Text
sdStreamARN = lens _sdStreamARN (\s a -> s { _sdStreamARN = a })
sdStreamName :: Lens' StreamDescription Text
sdStreamName = lens _sdStreamName (\s a -> s { _sdStreamName = a })
sdStreamStatus :: Lens' StreamDescription StreamStatus
sdStreamStatus = lens _sdStreamStatus (\s a -> s { _sdStreamStatus = a })
instance FromJSON StreamDescription where
parseJSON = withObject "StreamDescription" $ \o -> StreamDescription
<$> o .: "HasMoreShards"
<*> o .:? "Shards" .!= mempty
<*> o .: "StreamARN"
<*> o .: "StreamName"
<*> o .: "StreamStatus"
instance ToJSON StreamDescription where
toJSON StreamDescription{..} = object
[ "StreamName" .= _sdStreamName
, "StreamARN" .= _sdStreamARN
, "StreamStatus" .= _sdStreamStatus
, "Shards" .= _sdShards
, "HasMoreShards" .= _sdHasMoreShards
]
data PutRecordsResultEntry = PutRecordsResultEntry
{ _prreErrorCode :: Maybe Text
, _prreErrorMessage :: Maybe Text
, _prreSequenceNumber :: Maybe Text
, _prreShardId :: Maybe Text
} deriving (Eq, Ord, Show)
putRecordsResultEntry :: PutRecordsResultEntry
putRecordsResultEntry = PutRecordsResultEntry
{ _prreSequenceNumber = Nothing
, _prreShardId = Nothing
, _prreErrorCode = Nothing
, _prreErrorMessage = Nothing
}
prreErrorCode :: Lens' PutRecordsResultEntry (Maybe Text)
prreErrorCode = lens _prreErrorCode (\s a -> s { _prreErrorCode = a })
prreErrorMessage :: Lens' PutRecordsResultEntry (Maybe Text)
prreErrorMessage = lens _prreErrorMessage (\s a -> s { _prreErrorMessage = a })
prreSequenceNumber :: Lens' PutRecordsResultEntry (Maybe Text)
prreSequenceNumber =
lens _prreSequenceNumber (\s a -> s { _prreSequenceNumber = a })
prreShardId :: Lens' PutRecordsResultEntry (Maybe Text)
prreShardId = lens _prreShardId (\s a -> s { _prreShardId = a })
instance FromJSON PutRecordsResultEntry where
parseJSON = withObject "PutRecordsResultEntry" $ \o -> PutRecordsResultEntry
<$> o .:? "ErrorCode"
<*> o .:? "ErrorMessage"
<*> o .:? "SequenceNumber"
<*> o .:? "ShardId"
instance ToJSON PutRecordsResultEntry where
toJSON PutRecordsResultEntry{..} = object
[ "SequenceNumber" .= _prreSequenceNumber
, "ShardId" .= _prreShardId
, "ErrorCode" .= _prreErrorCode
, "ErrorMessage" .= _prreErrorMessage
]
data PutRecordsRequestEntry = PutRecordsRequestEntry
{ _prreData :: Base64
, _prreExplicitHashKey :: Maybe Text
, _prrePartitionKey :: Text
} deriving (Eq, Show)
putRecordsRequestEntry :: Base64
-> Text
-> PutRecordsRequestEntry
putRecordsRequestEntry p1 p2 = PutRecordsRequestEntry
{ _prreData = p1
, _prrePartitionKey = p2
, _prreExplicitHashKey = Nothing
}
prreData :: Lens' PutRecordsRequestEntry Base64
prreData = lens _prreData (\s a -> s { _prreData = a })
prreExplicitHashKey :: Lens' PutRecordsRequestEntry (Maybe Text)
prreExplicitHashKey =
lens _prreExplicitHashKey (\s a -> s { _prreExplicitHashKey = a })
prrePartitionKey :: Lens' PutRecordsRequestEntry Text
prrePartitionKey = lens _prrePartitionKey (\s a -> s { _prrePartitionKey = a })
instance FromJSON PutRecordsRequestEntry where
parseJSON = withObject "PutRecordsRequestEntry" $ \o -> PutRecordsRequestEntry
<$> o .: "Data"
<*> o .:? "ExplicitHashKey"
<*> o .: "PartitionKey"
instance ToJSON PutRecordsRequestEntry where
toJSON PutRecordsRequestEntry{..} = object
[ "Data" .= _prreData
, "ExplicitHashKey" .= _prreExplicitHashKey
, "PartitionKey" .= _prrePartitionKey
]
data StreamStatus
= Active
| Creating
| Deleting
| Updating
deriving (Eq, Ord, Show, Generic, Enum)
instance Hashable StreamStatus
instance FromText StreamStatus where
parser = takeText >>= \case
"ACTIVE" -> pure Active
"CREATING" -> pure Creating
"DELETING" -> pure Deleting
"UPDATING" -> pure Updating
e -> fail $
"Failure parsing StreamStatus from " ++ show e
instance ToText StreamStatus where
toText = \case
Active -> "ACTIVE"
Creating -> "CREATING"
Deleting -> "DELETING"
Updating -> "UPDATING"
instance ToByteString StreamStatus
instance ToHeader StreamStatus
instance ToQuery StreamStatus
instance FromJSON StreamStatus where
parseJSON = parseJSONText "StreamStatus"
instance ToJSON StreamStatus where
toJSON = toJSONText
data HashKeyRange = HashKeyRange
{ _hkrEndingHashKey :: Text
, _hkrStartingHashKey :: Text
} deriving (Eq, Ord, Show)
hashKeyRange :: Text
-> Text
-> HashKeyRange
hashKeyRange p1 p2 = HashKeyRange
{ _hkrStartingHashKey = p1
, _hkrEndingHashKey = p2
}
hkrEndingHashKey :: Lens' HashKeyRange Text
hkrEndingHashKey = lens _hkrEndingHashKey (\s a -> s { _hkrEndingHashKey = a })
hkrStartingHashKey :: Lens' HashKeyRange Text
hkrStartingHashKey =
lens _hkrStartingHashKey (\s a -> s { _hkrStartingHashKey = a })
instance FromJSON HashKeyRange where
parseJSON = withObject "HashKeyRange" $ \o -> HashKeyRange
<$> o .: "EndingHashKey"
<*> o .: "StartingHashKey"
instance ToJSON HashKeyRange where
toJSON HashKeyRange{..} = object
[ "StartingHashKey" .= _hkrStartingHashKey
, "EndingHashKey" .= _hkrEndingHashKey
]
data Record = Record
{ _rData :: Base64
, _rPartitionKey :: Text
, _rSequenceNumber :: Text
} deriving (Eq, Show)
record :: Text
-> Base64
-> Text
-> Record
record p1 p2 p3 = Record
{ _rSequenceNumber = p1
, _rData = p2
, _rPartitionKey = p3
}
rData :: Lens' Record Base64
rData = lens _rData (\s a -> s { _rData = a })
rPartitionKey :: Lens' Record Text
rPartitionKey = lens _rPartitionKey (\s a -> s { _rPartitionKey = a })
rSequenceNumber :: Lens' Record Text
rSequenceNumber = lens _rSequenceNumber (\s a -> s { _rSequenceNumber = a })
instance FromJSON Record where
parseJSON = withObject "Record" $ \o -> Record
<$> o .: "Data"
<*> o .: "PartitionKey"
<*> o .: "SequenceNumber"
instance ToJSON Record where
toJSON Record{..} = object
[ "SequenceNumber" .= _rSequenceNumber
, "Data" .= _rData
, "PartitionKey" .= _rPartitionKey
]
data SequenceNumberRange = SequenceNumberRange
{ _snrEndingSequenceNumber :: Maybe Text
, _snrStartingSequenceNumber :: Text
} deriving (Eq, Ord, Show)
sequenceNumberRange :: Text
-> SequenceNumberRange
sequenceNumberRange p1 = SequenceNumberRange
{ _snrStartingSequenceNumber = p1
, _snrEndingSequenceNumber = Nothing
}
snrEndingSequenceNumber :: Lens' SequenceNumberRange (Maybe Text)
snrEndingSequenceNumber =
lens _snrEndingSequenceNumber (\s a -> s { _snrEndingSequenceNumber = a })
snrStartingSequenceNumber :: Lens' SequenceNumberRange Text
snrStartingSequenceNumber =
lens _snrStartingSequenceNumber
(\s a -> s { _snrStartingSequenceNumber = a })
instance FromJSON SequenceNumberRange where
parseJSON = withObject "SequenceNumberRange" $ \o -> SequenceNumberRange
<$> o .:? "EndingSequenceNumber"
<*> o .: "StartingSequenceNumber"
instance ToJSON SequenceNumberRange where
toJSON SequenceNumberRange{..} = object
[ "StartingSequenceNumber" .= _snrStartingSequenceNumber
, "EndingSequenceNumber" .= _snrEndingSequenceNumber
]
data ShardIteratorType
= AfterSequenceNumber
| AtSequenceNumber
| Latest
| TrimHorizon
deriving (Eq, Ord, Show, Generic, Enum)
instance Hashable ShardIteratorType
instance FromText ShardIteratorType where
parser = takeText >>= \case
"AFTER_SEQUENCE_NUMBER" -> pure AfterSequenceNumber
"AT_SEQUENCE_NUMBER" -> pure AtSequenceNumber
"LATEST" -> pure Latest
"TRIM_HORIZON" -> pure TrimHorizon
e -> fail $
"Failure parsing ShardIteratorType from " ++ show e
instance ToText ShardIteratorType where
toText = \case
AfterSequenceNumber -> "AFTER_SEQUENCE_NUMBER"
AtSequenceNumber -> "AT_SEQUENCE_NUMBER"
Latest -> "LATEST"
TrimHorizon -> "TRIM_HORIZON"
instance ToByteString ShardIteratorType
instance ToHeader ShardIteratorType
instance ToQuery ShardIteratorType
instance FromJSON ShardIteratorType where
parseJSON = parseJSONText "ShardIteratorType"
instance ToJSON ShardIteratorType where
toJSON = toJSONText