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.
- checksums.yaml +4 -4
- data/lib/fog/aws.rb +3 -1
- data/lib/fog/aws/errors.rb +3 -3
- data/lib/fog/aws/kinesis.rb +187 -0
- data/lib/fog/aws/lambda.rb +10 -2
- data/lib/fog/aws/models/dns/zones.rb +2 -2
- data/lib/fog/aws/parsers/compute/describe_route_tables.rb +3 -3
- data/lib/fog/aws/parsers/compute/describe_vpcs.rb +1 -1
- data/lib/fog/aws/requests/compute/describe_route_tables.rb +1 -0
- data/lib/fog/aws/requests/dns/change_resource_record_sets.rb +116 -107
- data/lib/fog/aws/requests/kinesis/add_tags_to_stream.rb +48 -0
- data/lib/fog/aws/requests/kinesis/create_stream.rb +70 -0
- data/lib/fog/aws/requests/kinesis/delete_stream.rb +45 -0
- data/lib/fog/aws/requests/kinesis/describe_stream.rb +54 -0
- data/lib/fog/aws/requests/kinesis/get_records.rb +72 -0
- data/lib/fog/aws/requests/kinesis/get_shard_iterator.rb +53 -0
- data/lib/fog/aws/requests/kinesis/list_streams.rb +40 -0
- data/lib/fog/aws/requests/kinesis/list_tags_for_stream.rb +57 -0
- data/lib/fog/aws/requests/kinesis/merge_shards.rb +85 -0
- data/lib/fog/aws/requests/kinesis/put_record.rb +70 -0
- data/lib/fog/aws/requests/kinesis/put_records.rb +68 -0
- data/lib/fog/aws/requests/kinesis/remove_tags_from_stream.rb +49 -0
- data/lib/fog/aws/requests/kinesis/split_shard.rb +85 -0
- data/lib/fog/aws/storage.rb +4 -8
- data/lib/fog/aws/version.rb +1 -1
- data/tests/helpers/mock_helper.rb +0 -1
- data/tests/requests/compute/route_tests.rb +8 -7
- data/tests/requests/dns/change_resource_record_sets_tests.rb +26 -2
- data/tests/requests/emr/helper.rb +0 -1
- data/tests/requests/kinesis/helper.rb +111 -0
- data/tests/requests/kinesis/stream_tests.rb +169 -0
- metadata +19 -4
@@ -0,0 +1,111 @@
|
|
1
|
+
class AWS
|
2
|
+
module Kinesis
|
3
|
+
|
4
|
+
def wait_for(&block)
|
5
|
+
Fog.wait_for do
|
6
|
+
block.call.tap do
|
7
|
+
print '.'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def wait_for_status(stream_name, status)
|
13
|
+
wait_for do
|
14
|
+
Fog::AWS[:kinesis].describe_stream("StreamName" => stream_name).body["StreamDescription"]["StreamStatus"] == status
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def delete_if_exists(stream_name)
|
19
|
+
if Fog::AWS[:kinesis].list_streams.body["StreamNames"].include?(stream_name)
|
20
|
+
wait_for_status(stream_name, "ACTIVE")
|
21
|
+
Fog::AWS[:kinesis].delete_stream("StreamName" => @stream_id)
|
22
|
+
wait_for do
|
23
|
+
begin
|
24
|
+
Fog::AWS[:kinesis].describe_stream("StreamName" => stream_name)
|
25
|
+
false
|
26
|
+
rescue Fog::AWS::Kinesis::ResourceNotFound
|
27
|
+
true
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
module Formats # optional keys are commented out
|
34
|
+
|
35
|
+
LIST_STREAMS_FORMAT = {
|
36
|
+
"HasMoreStreams" => Fog::Boolean,
|
37
|
+
"StreamNames" => [
|
38
|
+
String
|
39
|
+
]
|
40
|
+
}
|
41
|
+
|
42
|
+
DESCRIBE_STREAM_FORMAT = {
|
43
|
+
"StreamDescription" => {
|
44
|
+
"HasMoreShards" => Fog::Boolean,
|
45
|
+
"Shards" => [
|
46
|
+
{
|
47
|
+
#"AdjacentParentShardId" => String,
|
48
|
+
"HashKeyRange" => {
|
49
|
+
"EndingHashKey" => String,
|
50
|
+
"StartingHashKey" => String
|
51
|
+
},
|
52
|
+
#"ParentShardId" => String,
|
53
|
+
"SequenceNumberRange" => {
|
54
|
+
# "EndingSequenceNumber" => String,
|
55
|
+
"StartingSequenceNumber" => String
|
56
|
+
},
|
57
|
+
"ShardId" => String
|
58
|
+
}
|
59
|
+
],
|
60
|
+
"StreamARN" => String,
|
61
|
+
"StreamName" => String,
|
62
|
+
"StreamStatus" => String
|
63
|
+
}
|
64
|
+
}
|
65
|
+
|
66
|
+
GET_SHARD_ITERATOR_FORMAT = {
|
67
|
+
"ShardIterator" => String
|
68
|
+
}
|
69
|
+
|
70
|
+
PUT_RECORDS_FORMAT = {
|
71
|
+
"FailedRecordCount" => Integer,
|
72
|
+
"Records" => [
|
73
|
+
{
|
74
|
+
# "ErrorCode" => String,
|
75
|
+
# "ErrorMessage" => String,
|
76
|
+
"SequenceNumber" => String,
|
77
|
+
"ShardId" => String
|
78
|
+
}
|
79
|
+
]
|
80
|
+
}
|
81
|
+
|
82
|
+
PUT_RECORD_FORMAT = {
|
83
|
+
"SequenceNumber" => String,
|
84
|
+
"ShardId" => String
|
85
|
+
}
|
86
|
+
|
87
|
+
GET_RECORDS_FORMAT = {
|
88
|
+
"MillisBehindLatest" => Integer,
|
89
|
+
"NextShardIterator" => String,
|
90
|
+
"Records" => [
|
91
|
+
{
|
92
|
+
"Data" => String,
|
93
|
+
"PartitionKey" => String,
|
94
|
+
"SequenceNumber" => String
|
95
|
+
}
|
96
|
+
]
|
97
|
+
}
|
98
|
+
|
99
|
+
LIST_TAGS_FOR_STREAM_FORMAT = {
|
100
|
+
"HasMoreTags" => Fog::Boolean,
|
101
|
+
"Tags" => [
|
102
|
+
{
|
103
|
+
"Key" => String,
|
104
|
+
"Value" => String
|
105
|
+
}
|
106
|
+
]
|
107
|
+
}
|
108
|
+
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,169 @@
|
|
1
|
+
include AWS::Kinesis
|
2
|
+
|
3
|
+
Shindo.tests('AWS::Kinesis | stream requests', ['aws', 'kinesis']) do
|
4
|
+
Fog::AWS[:kinesis].reset_data if Fog.mocking?
|
5
|
+
|
6
|
+
@stream_id = 'fog-test-stream'
|
7
|
+
|
8
|
+
delete_if_exists(@stream_id) # ensure we start from a clean slate
|
9
|
+
|
10
|
+
tests("#create_stream").returns("") do
|
11
|
+
Fog::AWS[:kinesis].create_stream("StreamName" => @stream_id).body.tap do
|
12
|
+
wait_for_status(@stream_id, "ACTIVE")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
tests("#list_streams").formats(Formats::LIST_STREAMS_FORMAT, false) do
|
17
|
+
Fog::AWS[:kinesis].list_streams.body.tap do
|
18
|
+
returns(true) {
|
19
|
+
Fog::AWS[:kinesis].list_streams.body["StreamNames"].include?(@stream_id)
|
20
|
+
}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
tests("#describe_stream") do
|
25
|
+
tests("success").formats(AWS::Kinesis::Formats::DESCRIBE_STREAM_FORMAT) do
|
26
|
+
Fog::AWS[:kinesis].describe_stream("StreamName" => @stream_id).body
|
27
|
+
end
|
28
|
+
|
29
|
+
tests("ResourceNotFound").raises(Fog::AWS::Kinesis::ResourceNotFound) do
|
30
|
+
Fog::AWS[:kinesis].describe_stream("StreamName" => @stream_id + "-foo").body
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
tests("#put_records") do
|
35
|
+
records = [
|
36
|
+
{
|
37
|
+
"Data" => Base64.encode64("foo").chomp!,
|
38
|
+
"PartitionKey" => "1"
|
39
|
+
},
|
40
|
+
{
|
41
|
+
"Data" => Base64.encode64("bar").chomp!,
|
42
|
+
"PartitionKey" => "1"
|
43
|
+
}
|
44
|
+
]
|
45
|
+
|
46
|
+
tests("success").formats(AWS::Kinesis::Formats::PUT_RECORDS_FORMAT, false) do
|
47
|
+
Fog::AWS[:kinesis].put_records("StreamName" => @stream_id, "Records" => records).body
|
48
|
+
end
|
49
|
+
|
50
|
+
tests("ResourceNotFound").raises(Fog::AWS::Kinesis::ResourceNotFound) do
|
51
|
+
Fog::AWS[:kinesis].put_records("StreamName" => @stream_id + "-foo", "Records" => records).body
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
tests("#put_record").formats(AWS::Kinesis::Formats::PUT_RECORD_FORMAT) do
|
57
|
+
Fog::AWS[:kinesis].put_record("StreamName" => @stream_id, "Data" => Base64.encode64("baz").chomp!, "PartitionKey" => "1").body
|
58
|
+
end
|
59
|
+
|
60
|
+
tests("#get_shard_iterator").formats(AWS::Kinesis::Formats::GET_SHARD_ITERATOR_FORMAT) do
|
61
|
+
first_shard_id = Fog::AWS[:kinesis].describe_stream("StreamName" => @stream_id).body["StreamDescription"]["Shards"].first["ShardId"]
|
62
|
+
Fog::AWS[:kinesis].get_shard_iterator("StreamName" => @stream_id, "ShardId" => first_shard_id, "ShardIteratorType" => "TRIM_HORIZON").body
|
63
|
+
end
|
64
|
+
|
65
|
+
tests("#get_records").formats(AWS::Kinesis::Formats::GET_RECORDS_FORMAT) do
|
66
|
+
first_shard_id = Fog::AWS[:kinesis].describe_stream("StreamName" => @stream_id).body["StreamDescription"]["Shards"].first["ShardId"]
|
67
|
+
shard_iterator = Fog::AWS[:kinesis].get_shard_iterator("StreamName" => @stream_id, "ShardId" => first_shard_id, "ShardIteratorType" => "TRIM_HORIZON").body["ShardIterator"]
|
68
|
+
Fog::AWS[:kinesis].get_records("ShardIterator" => shard_iterator, "Limit" => 1).body
|
69
|
+
end
|
70
|
+
|
71
|
+
tests("#get_records").returns(["foo", "bar"]) do
|
72
|
+
first_shard_id = Fog::AWS[:kinesis].describe_stream("StreamName" => @stream_id).body["StreamDescription"]["Shards"].first["ShardId"]
|
73
|
+
shard_iterator = Fog::AWS[:kinesis].get_shard_iterator("StreamName" => @stream_id, "ShardId" => first_shard_id, "ShardIteratorType" => "TRIM_HORIZON").body["ShardIterator"]
|
74
|
+
|
75
|
+
data = []
|
76
|
+
2.times do
|
77
|
+
response = Fog::AWS[:kinesis].get_records("ShardIterator" => shard_iterator, "Limit" => 1).body
|
78
|
+
response["Records"].each do |record|
|
79
|
+
data << Base64.decode64(record["Data"])
|
80
|
+
end
|
81
|
+
shard_iterator = response["NextShardIterator"]
|
82
|
+
end
|
83
|
+
data
|
84
|
+
end
|
85
|
+
|
86
|
+
tests("#split_shard").returns("") do
|
87
|
+
shard = Fog::AWS[:kinesis].describe_stream("StreamName" => @stream_id).body["StreamDescription"]["Shards"].first
|
88
|
+
shard_id = shard["ShardId"]
|
89
|
+
ending_hash_key = shard["HashKeyRange"]["EndingHashKey"]
|
90
|
+
new_starting_hash_key = (ending_hash_key.to_i / 2).to_s
|
91
|
+
|
92
|
+
result = Fog::AWS[:kinesis].split_shard("StreamName" => @stream_id, "ShardToSplit" => shard_id, "NewStartingHashKey" => new_starting_hash_key).body
|
93
|
+
|
94
|
+
wait_for_status(@stream_id, "ACTIVE")
|
95
|
+
shards = Fog::AWS[:kinesis].describe_stream("StreamName" => @stream_id).body["StreamDescription"]["Shards"]
|
96
|
+
parent_shard = shards.detect{ |shard| shard["ShardId"] == shard_id }
|
97
|
+
child_shards = shards.select{ |shard| shard["ParentShardId"] == shard_id }.sort_by{ |shard| shard["ShardId"] }
|
98
|
+
|
99
|
+
returns(3) { shards.size }
|
100
|
+
returns(2) { child_shards.size }
|
101
|
+
# parent is closed
|
102
|
+
returns(false) { parent_shard["SequenceNumberRange"]["EndingSequenceNumber"].nil? }
|
103
|
+
|
104
|
+
# ensure new ranges are what we expect (mostly for testing the mock)
|
105
|
+
returns([
|
106
|
+
{
|
107
|
+
"StartingHashKey" => "0",
|
108
|
+
"EndingHashKey" => (new_starting_hash_key.to_i - 1).to_s
|
109
|
+
},
|
110
|
+
{
|
111
|
+
"StartingHashKey" => new_starting_hash_key,
|
112
|
+
"EndingHashKey" => ending_hash_key
|
113
|
+
}
|
114
|
+
]) { child_shards.map{ |shard| shard["HashKeyRange"] } }
|
115
|
+
|
116
|
+
result
|
117
|
+
end
|
118
|
+
|
119
|
+
tests("#merge_shards").returns("") do
|
120
|
+
shards = Fog::AWS[:kinesis].describe_stream("StreamName" => @stream_id).body["StreamDescription"]["Shards"]
|
121
|
+
child_shard_ids = shards.reject{ |shard| shard["SequenceNumberRange"].has_key?("EndingSequenceNumber") }.map{ |shard| shard["ShardId"] }.sort
|
122
|
+
result = Fog::AWS[:kinesis].merge_shards("StreamName" => @stream_id, "ShardToMerge" => child_shard_ids[0], "AdjacentShardToMerge" => child_shard_ids[1]).body
|
123
|
+
|
124
|
+
wait_for_status(@stream_id, "ACTIVE")
|
125
|
+
shards = Fog::AWS[:kinesis].describe_stream("StreamName" => @stream_id).body["StreamDescription"]["Shards"]
|
126
|
+
parent_shards = shards.select{ |shard| child_shard_ids.include?(shard["ShardId"]) }
|
127
|
+
child_shard = shards.detect{ |shard|
|
128
|
+
shard["ParentShardId"] == child_shard_ids[0] &&
|
129
|
+
shard["AdjacentParentShardId"] == child_shard_ids[1]
|
130
|
+
}
|
131
|
+
|
132
|
+
returns(2) { parent_shards.size }
|
133
|
+
returns(false) { child_shard.nil? }
|
134
|
+
returns({
|
135
|
+
"EndingHashKey" => "340282366920938463463374607431768211455",
|
136
|
+
"StartingHashKey" => "0"
|
137
|
+
}) {
|
138
|
+
child_shard["HashKeyRange"]
|
139
|
+
}
|
140
|
+
|
141
|
+
result
|
142
|
+
end
|
143
|
+
|
144
|
+
tests("#add_tags_to_stream").returns("") do
|
145
|
+
Fog::AWS[:kinesis].add_tags_to_stream("StreamName" => @stream_id, "Tags" => {"a" => "1", "b" => "2"}).body
|
146
|
+
end
|
147
|
+
|
148
|
+
tests("#list_tags_for_stream").formats(AWS::Kinesis::Formats::LIST_TAGS_FOR_STREAM_FORMAT) do
|
149
|
+
Fog::AWS[:kinesis].list_tags_for_stream("StreamName" => @stream_id).body.tap do |body|
|
150
|
+
returns({"a" => "1", "b" => "2"}) {
|
151
|
+
body["Tags"].inject({}){ |m, tag| m.merge(tag["Key"] => tag["Value"]) }
|
152
|
+
}
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
tests("#remove_tags_from_stream").returns("") do
|
157
|
+
Fog::AWS[:kinesis].remove_tags_from_stream("StreamName" => @stream_id, "TagKeys" => %w[b]).body.tap do
|
158
|
+
returns({"a" => "1"}) {
|
159
|
+
body = Fog::AWS[:kinesis].list_tags_for_stream("StreamName" => @stream_id).body
|
160
|
+
body["Tags"].inject({}){ |m, tag| m.merge(tag["Key"] => tag["Value"]) }
|
161
|
+
}
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
tests("#delete_stream").returns("") do
|
166
|
+
Fog::AWS[:kinesis].delete_stream("StreamName" => @stream_id).body
|
167
|
+
end
|
168
|
+
|
169
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fog-aws
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Lane
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-07-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -168,6 +168,7 @@ files:
|
|
168
168
|
- lib/fog/aws/iam/default_policies.rb
|
169
169
|
- lib/fog/aws/iam/default_policy_versions.json
|
170
170
|
- lib/fog/aws/iam/paged_collection.rb
|
171
|
+
- lib/fog/aws/kinesis.rb
|
171
172
|
- lib/fog/aws/kms.rb
|
172
173
|
- lib/fog/aws/lambda.rb
|
173
174
|
- lib/fog/aws/mock.rb
|
@@ -1108,6 +1109,19 @@ files:
|
|
1108
1109
|
- lib/fog/aws/requests/iam/update_user.rb
|
1109
1110
|
- lib/fog/aws/requests/iam/upload_server_certificate.rb
|
1110
1111
|
- lib/fog/aws/requests/iam/upload_signing_certificate.rb
|
1112
|
+
- lib/fog/aws/requests/kinesis/add_tags_to_stream.rb
|
1113
|
+
- lib/fog/aws/requests/kinesis/create_stream.rb
|
1114
|
+
- lib/fog/aws/requests/kinesis/delete_stream.rb
|
1115
|
+
- lib/fog/aws/requests/kinesis/describe_stream.rb
|
1116
|
+
- lib/fog/aws/requests/kinesis/get_records.rb
|
1117
|
+
- lib/fog/aws/requests/kinesis/get_shard_iterator.rb
|
1118
|
+
- lib/fog/aws/requests/kinesis/list_streams.rb
|
1119
|
+
- lib/fog/aws/requests/kinesis/list_tags_for_stream.rb
|
1120
|
+
- lib/fog/aws/requests/kinesis/merge_shards.rb
|
1121
|
+
- lib/fog/aws/requests/kinesis/put_record.rb
|
1122
|
+
- lib/fog/aws/requests/kinesis/put_records.rb
|
1123
|
+
- lib/fog/aws/requests/kinesis/remove_tags_from_stream.rb
|
1124
|
+
- lib/fog/aws/requests/kinesis/split_shard.rb
|
1111
1125
|
- lib/fog/aws/requests/kms/create_key.rb
|
1112
1126
|
- lib/fog/aws/requests/kms/describe_key.rb
|
1113
1127
|
- lib/fog/aws/requests/kms/list_keys.rb
|
@@ -1497,6 +1511,8 @@ files:
|
|
1497
1511
|
- tests/requests/iam/server_certificate_tests.rb
|
1498
1512
|
- tests/requests/iam/user_policy_tests.rb
|
1499
1513
|
- tests/requests/iam/user_tests.rb
|
1514
|
+
- tests/requests/kinesis/helper.rb
|
1515
|
+
- tests/requests/kinesis/stream_tests.rb
|
1500
1516
|
- tests/requests/kms/helper.rb
|
1501
1517
|
- tests/requests/kms/key_tests.rb
|
1502
1518
|
- tests/requests/lambda/function_sample_1.js
|
@@ -1566,9 +1582,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
1566
1582
|
version: '0'
|
1567
1583
|
requirements: []
|
1568
1584
|
rubyforge_project:
|
1569
|
-
rubygems_version: 2.
|
1585
|
+
rubygems_version: 2.4.5
|
1570
1586
|
signing_key:
|
1571
1587
|
specification_version: 4
|
1572
1588
|
summary: Module for the 'fog' gem to support Amazon Web Services.
|
1573
1589
|
test_files: []
|
1574
|
-
has_rdoc:
|