Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support auth and unsignedPayload #3054

Merged
merged 9 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ def eventstream?(shape_or_shape_ref, api)
# @return [Boolean]
def streaming_input?(shape, operation)
shape['streaming'] && operation &&
operation['authtype'] == "v4-unsigned-body"
(operation['unsignedPayload'] ||
operation['authtype'] == 'v4-unsigned-body')
end

def plural?(resource)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def initialize(options)
@protocol_settings = metadata['protocolSettings'] || {}
@api_version = metadata['apiVersion']
@signature_version = metadata['signatureVersion']
@auth = api.fetch('metadata')['auth']
@full_name = metadata['serviceFullName']
@short_name = metadata['serviceAbbreviation'] || @full_name

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

# @return [Array<String>] A list of supported auth types
attr_reader :auth

# @return [String] The full product name for the service,
# e.g. "Amazon Simple Storage Service".
attr_reader :full_name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ def operations
end
o.authorizer = operation['authorizer'] if operation.key?('authorizer')
o.authtype = operation['authtype'] if operation.key?('authtype')
o.unsigned_payload = operation['unsignedPayload'] if operation.key?('unsignedPayload')
o.auth = operation['auth'] if operation.key?('auth')
o.require_apikey = operation['requiresApiKey'] if operation.key?('requiresApiKey')
o.pager = pager(operation_name)
o.async = @service.protocol_settings['h2'] == 'eventstream' &&
Expand Down Expand Up @@ -598,6 +600,12 @@ def initialize
# @return [String,nil]
attr_accessor :authtype

# @return [Boolean,nil]
attr_accessor :unsigned_payload

# @return [Array<String>]
attr_accessor :auth

# @return [Boolean]
attr_accessor :endpoint_trait

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{
"version":"2.0",
"metadata":{
"endpointPrefix":"svc",
"protocol": "rest-json",
"signatureVersion":"v4"
},
"operations": {
"Streaming": {
"name": "Streaming",
"http": {
"method": "POST",
"requestUri": "/"
},
"input": {"shape": "StreamingRequest"}
},
"NonStreaming": {
"name": "NonStreaming",
"http": {
"method": "POST",
"requestUri": "/"
},
"input": {"shape": "NonStreamingRequest"}
},
"UnsignedRequireLenStreaming": {
"name": "UnsignedRequireLenStreaming",
"http": {
"method": "POST",
"requestUri": "/"
},
"input": {"shape": "UnsignedRequireLenStreamingRequest"},
"authtype":"v4-unsigned-body"
},
"UnsignedStreaming": {
"name": "UnsignedStreaming",
"http": {
"method": "POST",
"requestUri": "/"
},
"input": {"shape": "UnsignedStreamingRequest"},
"authtype":"v4-unsigned-body"
}
},
"shapes": {
"StreamingRequest": {
"type": "structure",
"members": {
"Body": {
"shape": "Body",
"requiresLength": true,
"streaming": true
}
},
"payload": "Body"
},
"UnsignedStreamingRequest": {
"type": "structure",
"members": {
"Body": {
"shape": "StreamingBody"
}
},
"payload": "Body"
},
"UnsignedRequireLenStreamingRequest": {
"type": "structure",
"members": {
"Body": {
"shape": "Body",
"requiresLength": true,
"streaming": true
}
},
"payload": "Body"
},
"NonStreamingRequest": {
"type": "structure",
"members": {
"Body": {
"shape": "Body"
}
}
},
"Body": {"type": "blob"},
"StreamingBody": {
"type": "blob",
"streaming": true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"metadata":{
"endpointPrefix":"svc",
"protocol": "rest-json",
"signatureVersion":"v4"
"auth":["aws.auth#sigv4"]
},
"operations": {
"Streaming": {
Expand All @@ -22,23 +22,23 @@
},
"input": {"shape": "NonStreamingRequest"}
},
"UnsignRequireLenStreaming": {
"name": "UnsignRequireLenStreaming",
"UnsignedRequireLenStreaming": {
"name": "UnsignedRequireLenStreaming",
"http": {
"method": "POST",
"requestUri": "/"
},
"input": {"shape": "UnsignRequireLenStreamingRequest"},
"authtype":"v4-unsigned-body"
"input": {"shape": "UnsignedRequireLenStreamingRequest"},
"unsignedPayload":true
},
"UnsignStreaming": {
"name": "UnsignStreaming",
"UnsignedStreaming": {
"name": "UnsignedStreaming",
"http": {
"method": "POST",
"requestUri": "/"
},
"input": {"shape": "UnsignStreamingRequest"},
"authtype":"v4-unsigned-body"
"input": {"shape": "UnsignedStreamingRequest"},
"unsignedPayload":true
}
},
"shapes": {
Expand All @@ -53,7 +53,7 @@
},
"payload": "Body"
},
"UnsignStreamingRequest": {
"UnsignedStreamingRequest": {
"type": "structure",
"members": {
"Body": {
Expand All @@ -62,7 +62,7 @@
},
"payload": "Body"
},
"UnsignRequireLenStreamingRequest": {
"UnsignedRequireLenStreamingRequest": {
"type": "structure",
"members": {
"Body": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
describe 'Client Interface:' do
describe 'SignatureVersion: bearer' do
before(:all) do
SpecHelper.generate_service(['BearerAuth'], multiple_files: false)
SpecHelper.generate_service(['LegacySignBearerAuth'], multiple_files: false)
end

let(:token) { 'token' }

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

let(:client) do
BearerAuth::Client.new(
LegacySignBearerAuth::Client.new(
region: 'us-west-2',
stub_responses: true,
token_provider: token_provider,
Expand Down Expand Up @@ -51,15 +51,15 @@

describe 'SignatureVersion: v4' do
before(:all) do
SpecHelper.generate_service(['V4WithBearer'], multiple_files: false)
SpecHelper.generate_service(['LegacySignV4WithBearer'], multiple_files: false)
end

let(:token) { 'token' }

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

let(:client) do
V4WithBearer::Client.new(
LegacySignV4WithBearer::Client.new(
region: 'us-west-2',
stub_responses: true,
token_provider: token_provider,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# frozen_string_literal: true

require_relative '../../spec_helper'

describe 'Client Interface:' do
describe 'Legacy Transfer Encoding' do
before(:all) do
SpecHelper.generate_service(['LegacyTransferEncoding'], multiple_files: false)
end

let(:client) do
LegacyTransferEncoding::Client.new(stub_responses: true)
end

it 'adds `Transfer-Encoding` header for `v4-unsigned-body` auth types' do
resp = client.unsigned_streaming(body: StringIO.new('hey'))
expect(resp.context.http_request.headers['Transfer-Encoding']).to be(nil)
expect(resp.context.http_request.headers['Content-Length']).to eq('3')

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

resp = client.unsigned_streaming(body: io)
expect(
resp.context.http_request.headers['Transfer-Encoding']
).to eq('chunked')
expect(resp.context.http_request.headers['Content-Length']).to eq(nil)

tf.close
tf.unlink
end

it 'raises error when `Content-Length` header is required but cannot be set' do
tf = Tempfile.new('transfer-encoding-test')
tf.write('hey')
io = IO.new(IO.sysopen(tf))

msg = 'Required `Content-Length` value missing for the request.'
expect do
client.streaming(body: io)
end.to raise_error(Aws::Errors::MissingContentLength, msg)
expect do
client.unsigned_require_len_streaming(body: io)
end.to raise_error(Aws::Errors::MissingContentLength, msg)

tf.close
tf.unlink
end

it 'allows `requireLength` and `v4-unsigned-body` for streaming operations' do
resp = client.unsigned_require_len_streaming(body: StringIO.new('hey'))
expect(resp.context.http_request.headers['Transfer-Encoding']).to be(nil)
expect(resp.context.http_request.headers['Content-Length']).to eq('3')
end

it 'sets `Content-Length` header for streaming operations' do
resp = client.streaming(body: 'heyhey')
expect(resp.context.http_request.headers['Content-Length']).to eq('6')
end

it 'sets `Content-Length` header for non streaming operations' do
resp = client.non_streaming(body: 'heyhey')
expect(resp.context.http_request.headers['Content-Length']).to eq('19')
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,19 @@
end

let(:client) do
TransferEncoding::Client.new(
region: 'us-west-2',
access_key_id: 'akid',
secret_access_key: 'secret',
stub_responses: true,
endpoint: 'https://svc.us-west-2.amazonaws.com'
)
TransferEncoding::Client.new(stub_responses: true)
end

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

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

resp = client.unsign_streaming(body: io)
resp = client.unsigned_streaming(body: io)
expect(
resp.context.http_request.headers['Transfer-Encoding']
).to eq('chunked')
Expand All @@ -47,15 +41,15 @@
client.streaming(body: io)
end.to raise_error(Aws::Errors::MissingContentLength, msg)
expect do
client.unsign_require_len_streaming(body: io)
client.unsigned_require_len_streaming(body: io)
end.to raise_error(Aws::Errors::MissingContentLength, msg)

tf.close
tf.unlink
end

it 'allows `requireLength` and `v4-unsigned-body` for streaming operations' do
resp = client.unsign_require_len_streaming(body: StringIO.new('hey'))
it 'allows `requireLength` and `unsignedPayload` for streaming operations' do
resp = client.unsigned_require_len_streaming(body: StringIO.new('hey'))
expect(resp.context.http_request.headers['Transfer-Encoding']).to be(nil)
expect(resp.context.http_request.headers['Content-Length']).to eq('3')
end
Expand All @@ -69,6 +63,5 @@
resp = client.non_streaming(body: 'heyhey')
expect(resp.context.http_request.headers['Content-Length']).to eq('19')
end

end
end
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ module {{module_name}}
{{#authtype}}
o['authtype'] = "{{.}}"
{{/authtype}}
{{#unsigned_payload}}
o['unsignedPayload'] = true
{{/unsigned_payload}}
{{#auth}}
o['auth'] = {{&auth}}
{{/auth}}
{{#endpoint_trait}}
o.endpoint_pattern = {
{{#endpoint_pattern}}
Expand Down
2 changes: 1 addition & 1 deletion build_tools/customizations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def dynamodb_example_deep_transform(subsegment, keys)
api('STS') do |api|
operations = %w(AssumeRoleWithSAML AssumeRoleWithWebIdentity)
operations.each do |operation|
api['operations'][operation]['authtype'] = 'none'
api['operations'][operation]['auth'] = ['smithy.api#noAuth']
end
end
end
Expand Down
Loading
Loading