1
0
Fork 0
mirror of https://github.com/fog/fog-aws.git synced 2022-11-09 13:50:52 -05:00
fog--fog-aws/lib/fog/aws/requests/kinesis/create_stream.rb

71 lines
2.2 KiB
Ruby
Raw Normal View History

2015-06-19 16:55:32 -04:00
module Fog
module AWS
class Kinesis
class Real
# Creates a Amazon Kinesis stream.
#
# ==== Options
# * ShardCount<~Number>: The number of shards that the stream will use.
# * StreamName<~String>: A name to identify the stream.
# ==== Returns
# * response<~Excon::Response>:
#
# ==== See Also
# https://docs.aws.amazon.com/kinesis/latest/APIReference/API_CreateStream.html
#
def create_stream(options={})
body = {
"ShardCount" => options.delete("ShardCount") || 1,
"StreamName" => options.delete("StreamName")
}.reject{ |_,v| v.nil? }
2015-07-02 15:59:39 -04:00
request({
'X-Amz-Target' => "Kinesis_#{@version}.CreateStream",
:body => body,
}.merge(options))
2015-06-19 16:55:32 -04:00
end
end
class Mock
2015-06-30 18:15:14 -04:00
def create_stream(options={})
stream_name = options.delete("StreamName")
shard_count = options.delete("ShardCount") || 1
stream_arn = "arn:aws:kinesis:#{@region}:#{@account_id}:stream/#{stream_name}"
if data[:kinesis_streams].detect{ |s| s["StreamName"] == stream_name }
2015-07-02 18:19:53 -04:00
raise Fog::AWS::Kinesis::ResourceInUse.new("Stream #{stream_name} under account #{@account_id} already exists.")
2015-06-30 18:15:14 -04:00
end
shards = (0...shard_count).map do |shard|
{
"HashKeyRange"=>{
"EndingHashKey"=>"340282366920938463463374607431768211455",
"StartingHashKey"=>"0"
},
"SequenceNumberRange"=>{
2015-07-02 15:23:25 -04:00
"StartingSequenceNumber"=> next_sequence_number
2015-06-30 18:15:14 -04:00
},
2015-07-02 15:23:25 -04:00
"ShardId"=>next_shard_id,
2015-06-30 18:15:14 -04:00
"Records" => []
}
end
data[:kinesis_streams] = [{
"HasMoreShards" => false,
"StreamARN" => stream_arn,
"StreamName" => stream_name,
"StreamStatus" => "ACTIVE",
"Shards" => shards,
2015-07-02 16:12:09 -04:00
"Tags" => {}
2015-06-30 18:15:14 -04:00
}]
2015-07-02 14:32:04 -04:00
response = Excon::Response.new
response.status = 200
2015-06-30 18:15:14 -04:00
response.body = ""
response
2015-06-19 16:55:32 -04:00
end
end
end
end
end