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

Improve tokens semantics and clean up gateway feature gates #3052

Merged
merged 6 commits into from
Nov 22, 2024

Conversation

mkrasnitski
Copy link
Collaborator

This divorces the gateway feature from the model/http code such that there is no cross-contamination (setting the stage for a crate split). A few doctests got rewritten to not rely on the gateway, and the Http::token method was removed. The gateway structs now carry their own copy of the token, and the Http token field was made optional for users who only care about webhooks.

Furthermore, renamed the secret_string module to secrets and added a Token type that can partially validate token strings. This type is what is now passed in to the client. The user is expected to call either str::parse::<Token>() or Token::from_str in order to create a Client.

@github-actions github-actions bot added model Related to the `model` module. http Related to the `http` module. utils Related to the `utils` module. gateway Related to the `gateway` module. examples Related to Serenity's examples. labels Nov 19, 2024
@mkrasnitski mkrasnitski force-pushed the token-rework branch 2 times, most recently from c4b13f2 to 0bccd4c Compare November 19, 2024 03:07
Copy link
Member

@GnomedDev GnomedDev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks mainly good just some minor issues:

  • Can you add a Token::from_env("DISCORD_TOKEN") helper for the examples?
  • Can you remove the Http::default implementation, and have Http::new take the token with a Http::wthout_token constructor for webhook-only use, since this is the super minority of use cases.

@mkrasnitski
Copy link
Collaborator Author

Done.

src/http/client.rs Outdated Show resolved Hide resolved
src/http/client.rs Outdated Show resolved Hide resolved
Comment on lines +50 to +53
/// An error from the [`secrets`] module.
///
/// [`secrets`]: crate::secrets
Token(TokenError),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this have to be a part of this enum? I can't see a spot that returns this instead of just Result<T, TokenError>.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured this would be useful when using ? so that TokenError could coerce to Error.

@GnomedDev GnomedDev merged commit 2369544 into serenity-rs:next Nov 22, 2024
21 checks passed
@mkrasnitski mkrasnitski added the breaking change The public API is changed, resulting in miscompilations or unexpected new behaviour for users label Nov 22, 2024
@mkrasnitski mkrasnitski deleted the token-rework branch November 22, 2024 19:57
mkrasnitski added a commit to mkrasnitski/serenity that referenced this pull request Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change The public API is changed, resulting in miscompilations or unexpected new behaviour for users examples Related to Serenity's examples. gateway Related to the `gateway` module. http Related to the `http` module. model Related to the `model` module. utils Related to the `utils` module.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants