fog-aws 0.6.0 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/lib/fog/aws.rb +3 -1
  3. data/lib/fog/aws/errors.rb +3 -3
  4. data/lib/fog/aws/kinesis.rb +187 -0
  5. data/lib/fog/aws/lambda.rb +10 -2
  6. data/lib/fog/aws/models/dns/zones.rb +2 -2
  7. data/lib/fog/aws/parsers/compute/describe_route_tables.rb +3 -3
  8. data/lib/fog/aws/parsers/compute/describe_vpcs.rb +1 -1
  9. data/lib/fog/aws/requests/compute/describe_route_tables.rb +1 -0
  10. data/lib/fog/aws/requests/dns/change_resource_record_sets.rb +116 -107
  11. data/lib/fog/aws/requests/kinesis/add_tags_to_stream.rb +48 -0
  12. data/lib/fog/aws/requests/kinesis/create_stream.rb +70 -0
  13. data/lib/fog/aws/requests/kinesis/delete_stream.rb +45 -0
  14. data/lib/fog/aws/requests/kinesis/describe_stream.rb +54 -0
  15. data/lib/fog/aws/requests/kinesis/get_records.rb +72 -0
  16. data/lib/fog/aws/requests/kinesis/get_shard_iterator.rb +53 -0
  17. data/lib/fog/aws/requests/kinesis/list_streams.rb +40 -0
  18. data/lib/fog/aws/requests/kinesis/list_tags_for_stream.rb +57 -0
  19. data/lib/fog/aws/requests/kinesis/merge_shards.rb +85 -0
  20. data/lib/fog/aws/requests/kinesis/put_record.rb +70 -0
  21. data/lib/fog/aws/requests/kinesis/put_records.rb +68 -0
  22. data/lib/fog/aws/requests/kinesis/remove_tags_from_stream.rb +49 -0
  23. data/lib/fog/aws/requests/kinesis/split_shard.rb +85 -0
  24. data/lib/fog/aws/storage.rb +4 -8
  25. data/lib/fog/aws/version.rb +1 -1
  26. data/tests/helpers/mock_helper.rb +0 -1
  27. data/tests/requests/compute/route_tests.rb +8 -7
  28. data/tests/requests/dns/change_resource_record_sets_tests.rb +26 -2
  29. data/tests/requests/emr/helper.rb +0 -1
  30. data/tests/requests/kinesis/helper.rb +111 -0
  31. data/tests/requests/kinesis/stream_tests.rb +169 -0
  32. metadata +19 -4
@@ -0,0 +1,48 @@
1
+ module Fog
2
+ module AWS
3
+ class Kinesis
4
+ class Real
5
+ # Adds or updates tags for the specified Amazon Kinesis stream.
6
+ #
7
+ # ==== Options
8
+ # * StreamName<~String>: The name of the stream.
9
+ # * Tags<~Hash>: The set of key-value pairs to use to create the tags.
10
+ # ==== Returns
11
+ # * response<~Excon::Response>:
12
+ #
13
+ # ==== See Also
14
+ # https://docs.aws.amazon.com/kinesis/latest/APIReference/API_AddTagsToStream.html
15
+ #
16
+ def add_tags_to_stream(options={})
17
+ body = {
18
+ "StreamName" => options.delete("StreamName"),
19
+ "Tags" => options.delete("Tags")
20
+ }.reject{ |_,v| v.nil? }
21
+
22
+ request({
23
+ 'X-Amz-Target' => "Kinesis_#{@version}.AddTagsToStream",
24
+ :body => body,
25
+ }.merge(options))
26
+ end
27
+ end
28
+
29
+ class Mock
30
+ def add_tags_to_stream(options={})
31
+ stream_name = options.delete("StreamName")
32
+ tags = options.delete("Tags")
33
+
34
+ unless stream = data[:kinesis_streams].detect{ |s| s["StreamName"] == stream_name }
35
+ raise Fog::AWS::Kinesis::ResourceNotFound.new("Stream #{stream_name} under account #{@account_id} not found.")
36
+ end
37
+
38
+ stream["Tags"] = stream["Tags"].merge(tags)
39
+
40
+ response = Excon::Response.new
41
+ response.status = 200
42
+ response.body = ""
43
+ response
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,70 @@
1
+ module Fog
2
+ module AWS
3
+ class Kinesis
4
+ class Real
5
+ # Creates a Amazon Kinesis stream.
6
+ #
7
+ # ==== Options
8
+ # * ShardCount<~Number>: The number of shards that the stream will use.
9
+ # * StreamName<~String>: A name to identify the stream.
10
+ # ==== Returns
11
+ # * response<~Excon::Response>:
12
+ #
13
+ # ==== See Also
14
+ # https://docs.aws.amazon.com/kinesis/latest/APIReference/API_CreateStream.html
15
+ #
16
+ def create_stream(options={})
17
+ body = {
18
+ "ShardCount" => options.delete("ShardCount") || 1,
19
+ "StreamName" => options.delete("StreamName")
20
+ }.reject{ |_,v| v.nil? }
21
+
22
+ request({
23
+ 'X-Amz-Target' => "Kinesis_#{@version}.CreateStream",
24
+ :body => body,
25
+ }.merge(options))
26
+ end
27
+ end
28
+
29
+ class Mock
30
+ def create_stream(options={})
31
+ stream_name = options.delete("StreamName")
32
+ shard_count = options.delete("ShardCount") || 1
33
+ stream_arn = "arn:aws:kinesis:#{@region}:#{@account_id}:stream/#{stream_name}"
34
+
35
+ if data[:kinesis_streams].detect{ |s| s["StreamName"] == stream_name }
36
+ raise Fog::AWS::Kinesis::ResourceInUse.new("Stream #{stream_name} under account #{@account_id} already exists.")
37
+ end
38
+
39
+ shards = (0...shard_count).map do |shard|
40
+ {
41
+ "HashKeyRange"=>{
42
+ "EndingHashKey"=>"340282366920938463463374607431768211455",
43
+ "StartingHashKey"=>"0"
44
+ },
45
+ "SequenceNumberRange"=>{
46
+ "StartingSequenceNumber"=> next_sequence_number
47
+ },
48
+ "ShardId"=>next_shard_id,
49
+ "Records" => []
50
+ }
51
+ end
52
+
53
+ data[:kinesis_streams] = [{
54
+ "HasMoreShards" => false,
55
+ "StreamARN" => stream_arn,
56
+ "StreamName" => stream_name,
57
+ "StreamStatus" => "ACTIVE",
58
+ "Shards" => shards,
59
+ "Tags" => {}
60
+ }]
61
+
62
+ response = Excon::Response.new
63
+ response.status = 200
64
+ response.body = ""
65
+ response
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,45 @@
1
+ module Fog
2
+ module AWS
3
+ class Kinesis
4
+ class Real
5
+ # Deletes a stream and all its shards and data.
6
+ #
7
+ # ==== Options
8
+ # * StreamName<~String>: A name to identify the stream.
9
+ # ==== Returns
10
+ # * response<~Excon::Response>:
11
+ #
12
+ # ==== See Also
13
+ # https://docs.aws.amazon.com/kinesis/latest/APIReference/API_DeleteStream.html
14
+ #
15
+ def delete_stream(options={})
16
+ body = {
17
+ "StreamName" => options.delete("StreamName")
18
+ }.reject{ |_,v| v.nil? }
19
+
20
+ request({
21
+ 'X-Amz-Target' => "Kinesis_#{@version}.DeleteStream",
22
+ :body => body,
23
+ }.merge(options))
24
+ end
25
+ end
26
+
27
+ class Mock
28
+ def delete_stream(options={})
29
+ stream_name = options.delete("StreamName")
30
+
31
+ unless stream = data[:kinesis_streams].detect{ |s| s["StreamName"] == stream_name }
32
+ raise Fog::AWS::Kinesis::ResourceNotFound.new("Stream #{stream_name} under account #{@account_id} not found.")
33
+ end
34
+
35
+ data[:kinesis_streams].delete(stream)
36
+
37
+ response = Excon::Response.new
38
+ response.status = 200
39
+ response.body = ""
40
+ response
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,54 @@
1
+ module Fog
2
+ module AWS
3
+ class Kinesis
4
+ class Real
5
+ # Describes the specified stream.
6
+ #
7
+ # ==== Options
8
+ # * ExclusiveStartShardId<~String>: The shard ID of the shard to start with.
9
+ # * Limit<~Number>: The maximum number of shards to return.
10
+ # * StreamName<~String>: The name of the stream to describe.
11
+ # ==== Returns
12
+ # * response<~Excon::Response>:
13
+ #
14
+ # ==== See Also
15
+ # https://docs.aws.amazon.com/kinesis/latest/APIReference/API_DescribeStream.html
16
+ #
17
+ def describe_stream(options={})
18
+ body = {
19
+ "ExclusiveStartShardId" => options.delete("ExclusiveStartShardId"),
20
+ "Limit" => options.delete("Limit"),
21
+ "StreamName" => options.delete("StreamName")
22
+ }.reject{ |_,v| v.nil? }
23
+
24
+ response = request({
25
+ :idempotent => true,
26
+ 'X-Amz-Target' => "Kinesis_#{@version}.DescribeStream",
27
+ :body => body,
28
+ }.merge(options))
29
+ response.body = Fog::JSON.decode(response.body) unless response.body.nil?
30
+ response.body
31
+ response
32
+ end
33
+ end
34
+
35
+ class Mock
36
+ def describe_stream(options={})
37
+ stream_name = options.delete("StreamName")
38
+
39
+ unless stream = data[:kinesis_streams].detect{ |s| s["StreamName"] == stream_name }
40
+ raise Fog::AWS::Kinesis::ResourceNotFound.new("Stream #{stream_name} under account #{@account_id} not found.")
41
+ end
42
+
43
+ # Strip Records key out of shards for response
44
+ shards = stream["Shards"].reject{ |k,_| k == "Records" }
45
+
46
+ response = Excon::Response.new
47
+ response.status = 200
48
+ response.body = { "StreamDescription" => stream.dup.merge("Shards" => shards) }
49
+ response
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,72 @@
1
+ module Fog
2
+ module AWS
3
+ class Kinesis
4
+ class Real
5
+ # Gets data records from a shard.
6
+ #
7
+ # ==== Options
8
+ # * Limit<~Number>: The maximum number of records to return.
9
+ # * ShardIterator<~String>: The position in the shard from which you want to start sequentially reading data records.
10
+ # ==== Returns
11
+ # * response<~Excon::Response>:
12
+ #
13
+ # ==== See Also
14
+ # https://docs.aws.amazon.com/kinesis/latest/APIReference/API_GetRecords.html
15
+ #
16
+ def get_records(options={})
17
+ body = {
18
+ "Limit" => options.delete("Limit"),
19
+ "ShardIterator" => options.delete("ShardIterator")
20
+ }.reject{ |_,v| v.nil? }
21
+
22
+ response = request({
23
+ 'X-Amz-Target' => "Kinesis_#{@version}.GetRecords",
24
+ :body => body,
25
+ }.merge(options))
26
+ response.body = Fog::JSON.decode(response.body) unless response.body.nil?
27
+ response
28
+ end
29
+ end
30
+
31
+ class Mock
32
+ def get_records(options={})
33
+ shard_iterator = Fog::JSON.decode(options.delete("ShardIterator"))
34
+ limit = options.delete("Limit") || -1
35
+ stream_name = shard_iterator["StreamName"]
36
+ shard_id = shard_iterator["ShardId"]
37
+ starting_sequence_number = (shard_iterator["StartingSequenceNumber"] || 1).to_i
38
+
39
+ unless stream = data[:kinesis_streams].detect{ |s| s["StreamName"] == stream_name }
40
+ raise Fog::AWS::Kinesis::ResourceNotFound.new("Stream #{stream_name} under account #{@account_id} not found.")
41
+ end
42
+
43
+ unless shard = stream["Shards"].detect{ |shard| shard["ShardId"] == shard_id }
44
+ raise Fog::AWS::Kinesis::ResourceNotFound.new("Could not find shard #{shard_id} in stream #{stream_name} under account #{@account_id}.")
45
+ end
46
+
47
+ records = []
48
+ shard["Records"].each do |record|
49
+ next if record["SequenceNumber"].to_i < starting_sequence_number
50
+ records << record
51
+ break if records.size == limit
52
+ end
53
+
54
+ shard_iterator["StartingSequenceNumber"] = if records.empty?
55
+ starting_sequence_number.to_s
56
+ else
57
+ (records.last["SequenceNumber"].to_i + 1).to_s
58
+ end
59
+
60
+ response = Excon::Response.new
61
+ response.status = 200
62
+ response.body = {
63
+ "MillisBehindLatest"=> 0,
64
+ "NextShardIterator"=> Fog::JSON.encode(shard_iterator),
65
+ "Records"=> records
66
+ }
67
+ response
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,53 @@
1
+ module Fog
2
+ module AWS
3
+ class Kinesis
4
+ class Real
5
+ # Gets a shard iterator.
6
+ #
7
+ # ==== Options
8
+ # * ShardId<~String>: The shard ID of the shard to get the iterator for.
9
+ # * ShardIteratorType<~String>: Determines how the shard iterator is used to start reading data records from the shard.
10
+ # * StartingSequenceNumber<~String>: The sequence number of the data record in the shard from which to start reading from.
11
+ # * StreamName<~String>: A name to identify the stream.
12
+ # ==== Returns
13
+ # * response<~Excon::Response>:
14
+ #
15
+ # ==== See Also
16
+ # https://docs.aws.amazon.com/kinesis/latest/APIReference/API_GetShardIterator.html
17
+ #
18
+ def get_shard_iterator(options={})
19
+ body = {
20
+ "ShardId" => options.delete("ShardId"),
21
+ "ShardIteratorType" => options.delete("ShardIteratorType"),
22
+ "StartingSequenceNumber" => options.delete("StartingSequenceNumber"),
23
+ "StreamName" => options.delete("StreamName")
24
+ }.reject{ |_,v| v.nil? }
25
+
26
+ response = request({
27
+ 'X-Amz-Target' => "Kinesis_#{@version}.GetShardIterator",
28
+ :body => body,
29
+ }.merge(options))
30
+ response.body = Fog::JSON.decode(response.body) unless response.body.nil?
31
+ response
32
+ end
33
+ end
34
+
35
+ class Mock
36
+ def get_shard_iterator(options={})
37
+ stream_name = options["StreamName"]
38
+
39
+ unless stream = data[:kinesis_streams].detect{ |s| s["StreamName"] == stream_name }
40
+ raise Fog::AWS::Kinesis::ResourceNotFound.new("Stream #{stream_name} under account #{@account_id} not found.")
41
+ end
42
+
43
+ response = Excon::Response.new
44
+ response.status = 200
45
+ response.body = {
46
+ "ShardIterator" => Fog::JSON.encode(options) # just encode the options that were given, we decode them in get_records
47
+ }
48
+ response
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,40 @@
1
+ module Fog
2
+ module AWS
3
+ class Kinesis
4
+ class Real
5
+ # List availabe streams
6
+ #
7
+ # ==== Options
8
+ # * ExclusiveStartStreamName<~String>: The name of the stream to start the list with.
9
+ # * Limit<~Number>: The maximum number of streams to list.
10
+ # ==== Returns
11
+ # * response<~Excon::Response>:
12
+ #
13
+ # ==== See Also
14
+ # https://docs.aws.amazon.com/kinesis/latest/APIReference/API_ListStreams.html
15
+ #
16
+ def list_streams(options={})
17
+ response = request({
18
+ :idempotent => true,
19
+ 'X-Amz-Target' => "Kinesis_#{@version}.ListStreams",
20
+ :body => {},
21
+ }.merge(options))
22
+ response.body = Fog::JSON.decode(response.body) unless response.body.nil?
23
+ response
24
+ end
25
+ end
26
+
27
+ class Mock
28
+ def list_streams(options={})
29
+ response = Excon::Response.new
30
+ response.status = 200
31
+ response.body = {
32
+ "HasMoreStreams" => false,
33
+ "StreamNames" => data[:kinesis_streams].map{ |stream| stream["StreamName"] }
34
+ }
35
+ response
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,57 @@
1
+ module Fog
2
+ module AWS
3
+ class Kinesis
4
+ class Real
5
+ # Lists the tags for the specified Amazon Kinesis stream.
6
+ #
7
+ # ==== Options
8
+ # * ExclusiveStartTagKey<~String>: The key to use as the starting point for the list of tags.
9
+ # * Limit<~Number>: The number of tags to return.
10
+ # * StreamName<~String>: The name of the stream.
11
+ # ==== Returns
12
+ # * response<~Excon::Response>:
13
+ #
14
+ # ==== See Also
15
+ # https://docs.aws.amazon.com/kinesis/latest/APIReference/API_ListTagsForStream.html
16
+ #
17
+ def list_tags_for_stream(options={})
18
+ body = {
19
+ "ExclusiveStartTagKey" => options.delete("ExclusiveStartTagKey"),
20
+ "Limit" => options.delete("Limit"),
21
+ "StreamName" => options.delete("StreamName")
22
+ }.reject{ |_,v| v.nil? }
23
+
24
+ response = request({
25
+ :idempotent => true,
26
+ 'X-Amz-Target' => "Kinesis_#{@version}.ListTagsForStream",
27
+ :body => body,
28
+ }.merge(options))
29
+ response.body = Fog::JSON.decode(response.body) unless response.body.nil?
30
+ response.body
31
+ response
32
+ end
33
+ end
34
+
35
+ class Mock
36
+ def list_tags_for_stream(options={})
37
+ stream_name = options.delete("StreamName")
38
+
39
+ unless stream = data[:kinesis_streams].detect{ |s| s["StreamName"] == stream_name }
40
+ raise Fog::AWS::Kinesis::ResourceNotFound.new("Stream #{stream_name} under account #{@account_id} not found.")
41
+ end
42
+
43
+ response = Excon::Response.new
44
+ response.status = 200
45
+ response.body = {
46
+ "HasMoreTags" => false,
47
+ "Tags" => stream["Tags"].map{ |k,v|
48
+ {"Key" => k, "Value" => v}
49
+ }
50
+
51
+ }
52
+ response
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end