Skip to content

Commit a8b16ea

Browse files
authored
Support auth and unsignedPayload (#3054)
1 parent 294deae commit a8b16ea

File tree

48 files changed

+60420
-10745
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+60420
-10745
lines changed

build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/api.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ def eventstream?(shape_or_shape_ref, api)
131131
# @return [Boolean]
132132
def streaming_input?(shape, operation)
133133
shape['streaming'] && operation &&
134-
operation['authtype'] == "v4-unsigned-body"
134+
(operation['unsignedPayload'] ||
135+
operation['authtype'] == 'v4-unsigned-body')
135136
end
136137

137138
def plural?(resource)

build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/service.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def initialize(options)
5252
@protocol_settings = metadata['protocolSettings'] || {}
5353
@api_version = metadata['apiVersion']
5454
@signature_version = metadata['signatureVersion']
55+
@auth = api.fetch('metadata')['auth']
5556
@full_name = metadata['serviceFullName']
5657
@short_name = metadata['serviceAbbreviation'] || @full_name
5758

@@ -159,6 +160,9 @@ def included_in_core?
159160
# @return [String] The signature version, e.g. "v4"
160161
attr_reader :signature_version
161162

163+
# @return [Array<String>] A list of supported auth types
164+
attr_reader :auth
165+
162166
# @return [String] The full product name for the service,
163167
# e.g. "Amazon Simple Storage Service".
164168
attr_reader :full_name

build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/views/client_api_module.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,8 @@ def operations
251251
end
252252
o.authorizer = operation['authorizer'] if operation.key?('authorizer')
253253
o.authtype = operation['authtype'] if operation.key?('authtype')
254+
o.unsigned_payload = operation['unsignedPayload'] if operation.key?('unsignedPayload')
255+
o.auth = operation['auth'] if operation.key?('auth')
254256
o.require_apikey = operation['requiresApiKey'] if operation.key?('requiresApiKey')
255257
o.pager = pager(operation_name)
256258
o.async = @service.protocol_settings['h2'] == 'eventstream' &&
@@ -598,6 +600,12 @@ def initialize
598600
# @return [String,nil]
599601
attr_accessor :authtype
600602

603+
# @return [Boolean,nil]
604+
attr_accessor :unsigned_payload
605+
606+
# @return [Array<String>]
607+
attr_accessor :auth
608+
601609
# @return [Boolean]
602610
attr_accessor :endpoint_trait
603611

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
{
2+
"version":"2.0",
3+
"metadata":{
4+
"endpointPrefix":"svc",
5+
"protocol": "rest-json",
6+
"signatureVersion":"v4"
7+
},
8+
"operations": {
9+
"Streaming": {
10+
"name": "Streaming",
11+
"http": {
12+
"method": "POST",
13+
"requestUri": "/"
14+
},
15+
"input": {"shape": "StreamingRequest"}
16+
},
17+
"NonStreaming": {
18+
"name": "NonStreaming",
19+
"http": {
20+
"method": "POST",
21+
"requestUri": "/"
22+
},
23+
"input": {"shape": "NonStreamingRequest"}
24+
},
25+
"UnsignedRequireLenStreaming": {
26+
"name": "UnsignedRequireLenStreaming",
27+
"http": {
28+
"method": "POST",
29+
"requestUri": "/"
30+
},
31+
"input": {"shape": "UnsignedRequireLenStreamingRequest"},
32+
"authtype":"v4-unsigned-body"
33+
},
34+
"UnsignedStreaming": {
35+
"name": "UnsignedStreaming",
36+
"http": {
37+
"method": "POST",
38+
"requestUri": "/"
39+
},
40+
"input": {"shape": "UnsignedStreamingRequest"},
41+
"authtype":"v4-unsigned-body"
42+
}
43+
},
44+
"shapes": {
45+
"StreamingRequest": {
46+
"type": "structure",
47+
"members": {
48+
"Body": {
49+
"shape": "Body",
50+
"requiresLength": true,
51+
"streaming": true
52+
}
53+
},
54+
"payload": "Body"
55+
},
56+
"UnsignedStreamingRequest": {
57+
"type": "structure",
58+
"members": {
59+
"Body": {
60+
"shape": "StreamingBody"
61+
}
62+
},
63+
"payload": "Body"
64+
},
65+
"UnsignedRequireLenStreamingRequest": {
66+
"type": "structure",
67+
"members": {
68+
"Body": {
69+
"shape": "Body",
70+
"requiresLength": true,
71+
"streaming": true
72+
}
73+
},
74+
"payload": "Body"
75+
},
76+
"NonStreamingRequest": {
77+
"type": "structure",
78+
"members": {
79+
"Body": {
80+
"shape": "Body"
81+
}
82+
}
83+
},
84+
"Body": {"type": "blob"},
85+
"StreamingBody": {
86+
"type": "blob",
87+
"streaming": true
88+
}
89+
}
90+
}

build_tools/aws-sdk-code-generator/spec/fixtures/interfaces/transfer_encoding/api.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"metadata":{
44
"endpointPrefix":"svc",
55
"protocol": "rest-json",
6-
"signatureVersion":"v4"
6+
"auth":["aws.auth#sigv4"]
77
},
88
"operations": {
99
"Streaming": {
@@ -22,23 +22,23 @@
2222
},
2323
"input": {"shape": "NonStreamingRequest"}
2424
},
25-
"UnsignRequireLenStreaming": {
26-
"name": "UnsignRequireLenStreaming",
25+
"UnsignedRequireLenStreaming": {
26+
"name": "UnsignedRequireLenStreaming",
2727
"http": {
2828
"method": "POST",
2929
"requestUri": "/"
3030
},
31-
"input": {"shape": "UnsignRequireLenStreamingRequest"},
32-
"authtype":"v4-unsigned-body"
31+
"input": {"shape": "UnsignedRequireLenStreamingRequest"},
32+
"unsignedPayload":true
3333
},
34-
"UnsignStreaming": {
35-
"name": "UnsignStreaming",
34+
"UnsignedStreaming": {
35+
"name": "UnsignedStreaming",
3636
"http": {
3737
"method": "POST",
3838
"requestUri": "/"
3939
},
40-
"input": {"shape": "UnsignStreamingRequest"},
41-
"authtype":"v4-unsigned-body"
40+
"input": {"shape": "UnsignedStreamingRequest"},
41+
"unsignedPayload":true
4242
}
4343
},
4444
"shapes": {
@@ -53,7 +53,7 @@
5353
},
5454
"payload": "Body"
5555
},
56-
"UnsignStreamingRequest": {
56+
"UnsignedStreamingRequest": {
5757
"type": "structure",
5858
"members": {
5959
"Body": {
@@ -62,7 +62,7 @@
6262
},
6363
"payload": "Body"
6464
},
65-
"UnsignRequireLenStreamingRequest": {
65+
"UnsignedRequireLenStreamingRequest": {
6666
"type": "structure",
6767
"members": {
6868
"Body": {

build_tools/aws-sdk-code-generator/spec/interfaces/client/bearer_authorization_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
describe 'Client Interface:' do
66
describe 'SignatureVersion: bearer' do
77
before(:all) do
8-
SpecHelper.generate_service(['BearerAuth'], multiple_files: false)
8+
SpecHelper.generate_service(['LegacySignBearerAuth'], multiple_files: false)
99
end
1010

1111
let(:token) { 'token' }
1212

1313
let(:token_provider) { Aws::StaticTokenProvider.new(token) }
1414

1515
let(:client) do
16-
BearerAuth::Client.new(
16+
LegacySignBearerAuth::Client.new(
1717
region: 'us-west-2',
1818
stub_responses: true,
1919
token_provider: token_provider,
@@ -51,15 +51,15 @@
5151

5252
describe 'SignatureVersion: v4' do
5353
before(:all) do
54-
SpecHelper.generate_service(['V4WithBearer'], multiple_files: false)
54+
SpecHelper.generate_service(['LegacySignV4WithBearer'], multiple_files: false)
5555
end
5656

5757
let(:token) { 'token' }
5858

5959
let(:token_provider) { Aws::StaticTokenProvider.new(token) }
6060

6161
let(:client) do
62-
V4WithBearer::Client.new(
62+
LegacySignV4WithBearer::Client.new(
6363
region: 'us-west-2',
6464
stub_responses: true,
6565
token_provider: token_provider,
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../../spec_helper'
4+
5+
describe 'Client Interface:' do
6+
describe 'Legacy Transfer Encoding' do
7+
before(:all) do
8+
SpecHelper.generate_service(['LegacyTransferEncoding'], multiple_files: false)
9+
end
10+
11+
let(:client) do
12+
LegacyTransferEncoding::Client.new(stub_responses: true)
13+
end
14+
15+
it 'adds `Transfer-Encoding` header for `v4-unsigned-body` auth types' do
16+
resp = client.unsigned_streaming(body: StringIO.new('hey'))
17+
expect(resp.context.http_request.headers['Transfer-Encoding']).to be(nil)
18+
expect(resp.context.http_request.headers['Content-Length']).to eq('3')
19+
20+
tf = Tempfile.new('transfer-encoding-test')
21+
tf.write('hey')
22+
io = IO.new(IO.sysopen(tf))
23+
24+
resp = client.unsigned_streaming(body: io)
25+
expect(
26+
resp.context.http_request.headers['Transfer-Encoding']
27+
).to eq('chunked')
28+
expect(resp.context.http_request.headers['Content-Length']).to eq(nil)
29+
30+
tf.close
31+
tf.unlink
32+
end
33+
34+
it 'raises error when `Content-Length` header is required but cannot be set' do
35+
tf = Tempfile.new('transfer-encoding-test')
36+
tf.write('hey')
37+
io = IO.new(IO.sysopen(tf))
38+
39+
msg = 'Required `Content-Length` value missing for the request.'
40+
expect do
41+
client.streaming(body: io)
42+
end.to raise_error(Aws::Errors::MissingContentLength, msg)
43+
expect do
44+
client.unsigned_require_len_streaming(body: io)
45+
end.to raise_error(Aws::Errors::MissingContentLength, msg)
46+
47+
tf.close
48+
tf.unlink
49+
end
50+
51+
it 'allows `requireLength` and `v4-unsigned-body` for streaming operations' do
52+
resp = client.unsigned_require_len_streaming(body: StringIO.new('hey'))
53+
expect(resp.context.http_request.headers['Transfer-Encoding']).to be(nil)
54+
expect(resp.context.http_request.headers['Content-Length']).to eq('3')
55+
end
56+
57+
it 'sets `Content-Length` header for streaming operations' do
58+
resp = client.streaming(body: 'heyhey')
59+
expect(resp.context.http_request.headers['Content-Length']).to eq('6')
60+
end
61+
62+
it 'sets `Content-Length` header for non streaming operations' do
63+
resp = client.non_streaming(body: 'heyhey')
64+
expect(resp.context.http_request.headers['Content-Length']).to eq('19')
65+
end
66+
end
67+
end

build_tools/aws-sdk-code-generator/spec/interfaces/client/transfer_encoding_spec.rb

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,19 @@
99
end
1010

1111
let(:client) do
12-
TransferEncoding::Client.new(
13-
region: 'us-west-2',
14-
access_key_id: 'akid',
15-
secret_access_key: 'secret',
16-
stub_responses: true,
17-
endpoint: 'https://svc.us-west-2.amazonaws.com'
18-
)
12+
TransferEncoding::Client.new(stub_responses: true)
1913
end
2014

21-
it 'adds `Transfer-Encoding` header for `v4-unsigned-body` auth types' do
22-
resp = client.unsign_streaming(body: StringIO.new('hey'))
15+
it 'adds `Transfer-Encoding` header for `unsignedPayload` v4 auth' do
16+
resp = client.unsigned_streaming(body: StringIO.new('hey'))
2317
expect(resp.context.http_request.headers['Transfer-Encoding']).to be(nil)
2418
expect(resp.context.http_request.headers['Content-Length']).to eq('3')
2519

2620
tf = Tempfile.new('transfer-encoding-test')
2721
tf.write('hey')
2822
io = IO.new(IO.sysopen(tf))
2923

30-
resp = client.unsign_streaming(body: io)
24+
resp = client.unsigned_streaming(body: io)
3125
expect(
3226
resp.context.http_request.headers['Transfer-Encoding']
3327
).to eq('chunked')
@@ -47,15 +41,15 @@
4741
client.streaming(body: io)
4842
end.to raise_error(Aws::Errors::MissingContentLength, msg)
4943
expect do
50-
client.unsign_require_len_streaming(body: io)
44+
client.unsigned_require_len_streaming(body: io)
5145
end.to raise_error(Aws::Errors::MissingContentLength, msg)
5246

5347
tf.close
5448
tf.unlink
5549
end
5650

57-
it 'allows `requireLength` and `v4-unsigned-body` for streaming operations' do
58-
resp = client.unsign_require_len_streaming(body: StringIO.new('hey'))
51+
it 'allows `requireLength` and `unsignedPayload` for streaming operations' do
52+
resp = client.unsigned_require_len_streaming(body: StringIO.new('hey'))
5953
expect(resp.context.http_request.headers['Transfer-Encoding']).to be(nil)
6054
expect(resp.context.http_request.headers['Content-Length']).to eq('3')
6155
end
@@ -69,6 +63,5 @@
6963
resp = client.non_streaming(body: 'heyhey')
7064
expect(resp.context.http_request.headers['Content-Length']).to eq('19')
7165
end
72-
7366
end
7467
end

0 commit comments

Comments
 (0)