-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add an RBS signature for sigv4 #3152
base: version-3
Are you sure you want to change the base?
Add an RBS signature for sigv4 #3152
Conversation
Thank you, we will review this. I think you will also need: a changelog entry, add sig/ to gemspec files, and ensure rbs test passes (see tasks/rbs.rake). |
@ksss may also be interested in reviewing if you'd like. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution, this is looking good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Private API types should be removed.
- The intent and syntax are different.
- Hash arguments should be supported as well as keyword arguments.
- What about RBS testing?
gems/aws-sigv4/sig/credentials.rbs
Outdated
@@ -0,0 +1,30 @@ | |||
module Aws | |||
module Sigv4 | |||
class Credentials |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a private API.
aws-sdk-ruby/gems/aws-sigv4/lib/aws-sigv4/credentials.rb
Lines 5 to 8 in 8c6f65f
# Users that wish to configure static credentials can use the | |
# `:access_key_id` and `:secret_access_key` constructor options. | |
# @api private | |
class Credentials |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I deleted it.
a72b3bc
gems/aws-sigv4/sig/credentials.rbs
Outdated
def set?: () -> bool | ||
end | ||
|
||
class StaticCredentialsProvider |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto.
aws-sdk-ruby/gems/aws-sigv4/lib/aws-sigv4/credentials.rb
Lines 43 to 46 in 8c6f65f
# Users that wish to configure static credentials can use the | |
# `:access_key_id` and `:secret_access_key` constructor options. | |
# @api private | |
class StaticCredentialsProvider |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I deleted it.
a72b3bc
gems/aws-sigv4/sig/request.rbs
Outdated
@@ -0,0 +1,24 @@ | |||
module AWS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
module AWS | |
module Aws |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
a522cc1
gems/aws-sigv4/sig/signer.rbs
Outdated
def sign_event: ( | ||
prior_signature: String, | ||
payload: String, | ||
encoder: Object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use untyped
when you do not know what the type is or when you want to put off a decision.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, I fixed it.
2a780e6
signing_algorithm?: Symbol, | ||
omit_session_token?: bool, | ||
normalize_path?: bool, | ||
) -> void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you are writing the overload to match the YARD notation, but there is a tradeoff with maintenance costs.
Either way, we can't make a strict type determination when dealing with hash arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried combining all the overloads of the initialize method into a single definition. Would you mind sharing your thoughts on this approach?
2a780e6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hash arguments should be supported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me confirm: Do you mean I should revise it as follows?
def initialize: (
options: {
service: String,
region: String,
access_key_id?: String,
secret_access_key?: String,
session_token?: String,
credentials?: untyped,
credentials_provider?: untyped,
unsigned_headers?: Array[String],
uri_escape_path?: bool,
apply_checksum_header?: bool,
signing_algorithm?: :sigv4 | :sigv4a | :'sigv4-s3express',
omit_session_token?: bool,
normalize_path?: bool,
}
) -> void
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. "Hash arguments" is same as #3152 (comment)
How are you testing the behavior?
I don't think it will pass in steep with the proposed signature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry about that, I've updated the code.
3c34687
I replaced |
Let me know when this is ready for re-review and I can allocate some time. |
gems/aws-sigv4/sig/signer.rbs
Outdated
def initialize: ( | ||
service: String, | ||
region: String, | ||
access_key_id?: String, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as #3152 (comment)
foo?: String
is not optional keyword syntax.
It support to call method like m(foo?: 'bar')
. This is a very rare case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry about that, I've updated the code.
I've made changes based on your feedback. Please review the updated code at your convenience. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should modify tasks/rbs.rake to run the RBS test.
signing_algorithm?: Symbol, | ||
omit_session_token?: bool, | ||
normalize_path?: bool, | ||
) -> void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hash arguments should be supported.
Is this ready for re-review from our side? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good and definitely an improvement!
?credentials: untyped, | ||
?credentials_provider: untyped, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there are classes in this gem you could use for these, or possibly use some interface for "responds to"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that aws-sigv4/credentials.rb
is marked @api private
, so I removed its RBS definitions. Do you think it’s better to restore them or just define an interface (requiring #credentials
returning access keys, etc.) directly in signer.rbs
? I’m unsure which approach is more suitable, given the private status. Any thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is true. I think sigv4/credentials.rb
serves as an intermediary. Technically these would be Aws::Credentials
from aws-sdk-core. We can leave these untyped for now, and if you're interested in adding rbs for credentials in aws-sdk-core, we can fill these in. I'm not sure how rbs works with across packages, since aws-sigv4 does not depend on aws-sdk-core.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So you’re suggesting that if we create RBS files corresponding to gems/aws-sdk-core/lib/aws-sdk-core/credentials.rb
and gems/aws-sdk-core/lib/aws-sdk-core/credential_provider.rb
, we could then make use of those type definitions, right? For now, I'll keep it untyped
, but afterward I'm thinking of adding RBS definitions for aws-sdk-core
credentials. How does that sound?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While in most use cases, Aws::Credentials
from aws-sdk-core
would be used, this library is intended as a stand alone and doesn't depend on aws-sdk-core - I think from a typing perspective maybe we should define a credentials interface (ie: any object that responds to access_key_id, secret_access_key and session_token) since thats actually what is required. And probably an interface for credentials provider as well.
I received some advice suggesting, "Why not start with aws-sigv4?" in this PR: #3150.
Following that advice, I have added type definition files to
aws-sigv4
.