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

Update azure-autorust to append path and parameters via URL lib #1663

Merged
merged 3 commits into from
Jul 31, 2024

Conversation

andras-pinter
Copy link
Contributor

When returning a URL from Client::endpoint the URL contains a tailing slash in any case. This is handled by the URL lib which will append the tailing slash to the end upon calling Display::fmt. Therefore formatting the returned URL from Client::endpoint will result in a duplicated slash, which could cause some (not all) Azure endpoints to have some trouble.

For example:
Base URL: https://some-app-conf.azconfig.io/
AppConfigUrl: https://some-app-conf.azconfig.io//keys?api-version=2023-10-01 This resulted in a 404 response.

Removing the tailing slash from the base endpoint's URL manually does not solve the problem, due to the reason mentioned above.

This patch applies a fix to append (set) the formatted path via rust URL lib, which will handle the duplicated slash (or any other problem).

Although I tried to locally generate mgmt and svc crates, I encountered some problems, and autorust removed and added a bunch of new files and modules.
So I'd like to ask somebody to help me out with the generation.

@heaths
Copy link
Member

heaths commented May 15, 2024

Whether there's a trailing slash or not, any code formatting URLs using the endpoint should handle that. It's just as likely that some code erroneously expects a trailing slash, doesn't append on, and ends up with an invalid URL. Besides, in most cases services should canonicalize paths.

I'm reluctant to take this one. Is there some common issue you're seeing with code not appending paths to endpoints with a trialing slash? Can those be fixed? That seems the crux of the problem.

@andras-pinter
Copy link
Contributor Author

andras-pinter commented May 15, 2024

Hey @heaths,

Yes, there is a particular error, what I recently encountered. Please see: #1664

@heaths
Copy link
Member

heaths commented May 15, 2024

@ctaggart could you review this? If you're good with it, I can regenerate the service crates.

@andras-pinter
Copy link
Contributor Author

My goal was to let azure_core::Url handle URL creation :)

@cataggar
Copy link
Member

@ctaggart could you review this? If you're good with it, I can regenerate the service crates.

Sounds good. Please go ahead.

@kingofthehill444
Copy link

kingofthehill444 commented Jul 24, 2024

I'm facing this exact issue when trying to use the azure web pub sub crate.

I'm happy to help out but it seems like the change just needs to be merged? Can someone help push this through please?

To give more context, I have my azure web pubsub endpoint as "https://<service>.webpubsub.azure.com". It then gets into this line of code

let mut url = azure_core::Url::parse(&format!("{}/api/hubs/{}/:generateToken", self.client.endpoint(), &self.hub))?;

When I set a breakpoint here, it was showing https://<service>.webpubsub.azure.com//api/hubs/... instead of https://<service>.webpubsub.azure.com/api/hubs/....

The error I get back is "server returned error status which will not be retried: 404"

@andras-pinter andras-pinter marked this pull request as ready for review July 25, 2024 18:51
@andras-pinter
Copy link
Contributor Author

I made this as a PR instead of a draft. Still facing some issues, if somebody please help me finish this would be really nice! Thanks!

When returning a URL from Client::endpoint the URL contains a tailing slash
in any case. This is handled by the URL lib which will append the tailing
slash to the end upon calling Display::fmt. Therefore formatting the returned
URL from Client::endpoint will result in a duplicated slash, which could cause
some (not all) Azure endpoints to have some trouble.

For example:
Base URL: https://some-app-conf.azconfig.io/
AppConfigUrl: https://some-app-conf.azconfig.io//keys?api-version=2023-10-01
This resulted in a 404 response.

Removing the tailing slash from the URL manually does not solve the problem,
due to the reason mentioned above.

This patch applies a fix to append (set) the formatted path via rust URL lib,
which will handle the duplicated slash (or any other problem).
@heaths heaths force-pushed the endpoint-url-handling-refactor branch from 8e8f1e3 to 64dd020 Compare July 26, 2024 23:49
@heaths
Copy link
Member

heaths commented Jul 26, 2024

Most of the issues were with nightly tests failing due to evolving lints. Checking if a rebase on main fixes them first.

@heaths heaths requested a review from JeffreyRichter as a code owner July 26, 2024 23:54
@andras-pinter
Copy link
Contributor Author

@microsoft-github-policy-service agree

@andras-pinter andras-pinter force-pushed the endpoint-url-handling-refactor branch from 75b091d to e662682 Compare July 27, 2024 12:51
@andras-pinter andras-pinter force-pushed the endpoint-url-handling-refactor branch from e662682 to 90458dd Compare July 30, 2024 08:51
@heaths heaths enabled auto-merge (squash) July 31, 2024 00:22
@heaths heaths merged commit 2f22149 into Azure:main Jul 31, 2024
22 checks passed
@andras-pinter
Copy link
Contributor Author

🎉 Thanks everyone!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants