Skip to content

Support http lookup authentication(oauth2 and token) #300

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

Merged
merged 1 commit into from
Mar 7, 2025

Conversation

geniusjoe
Copy link
Contributor

support #299

Changes

  • Add function HasDataForHttp() and GetHttpHeaders() in AuthenticationDataProvider type to generate http headers authentication properties
  • Create a type class called PulsarHttpClient, this class will initialize authentication related members and expose a GetStreamAsync() function
  • Replace httpClient.GetStreamAsync() with pulsarHttpClient.GetStreamAsync() in HttpLookupService to enable authentication

@geniusjoe geniusjoe force-pushed the dev/http-authentication branch from 07b5325 to fe664cd Compare March 6, 2025 16:15
authenticationDataProvider.GetHttpHeaders() |> Seq.iter (
fun headerProperty -> request.Headers.Add(headerProperty.Key, headerProperty.Value)
)
let! response = httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead) |> Async.AwaitTask
Copy link
Member

@Lanayx Lanayx Mar 6, 2025

Choose a reason for hiding this comment

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

Async.AwaitTask is not needed here

Copy link
Member

Choose a reason for hiding this comment

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

Also, why is it HttpCompletionOption.ResponseHeadersRead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Async.AwaitTask is not needed here

Fixed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, why is it HttpCompletionOption.ResponseHeadersRead?

I changed HttpCompletionOption.ResponseHeadersRead to HttpCompletionOption.ResponseContentRead in my latest commit.

I found that GetStreamAsync() cannot pass custom header, so I searched StackOverflow and refer this answer.

However I think maybe there is no big difference between HttpCompletionOption.ResponseContentRead and HttpCompletionOption.ResponseHeadersRead in small size http response, because these two options are only determining when to read the response:

Indicates if HttpClient operations should be considered completed either as soon as a response is available, or after reading the entire response message including the content.

https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpcompletionoption?view=net-9.0

Copy link
Member

Choose a reason for hiding this comment

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

ResponseContentRead is default, so I think it can just be omitted

Copy link
Member

@Lanayx Lanayx Mar 7, 2025

Choose a reason for hiding this comment

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

Actually, I've just realized, that we don't have to have this function return stream. We can make it generic, just like in Java and leverage GetFromJsonAsync built-in method inside

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, I've just realized, that we don't have to have this function return stream. We can make it generic, just like in Java and leverage GetFromJsonAsync built-in method inside

@Lanayx
Fixed, please review again. And I change GetStreamAsync() name to Get() to make consistent with Java client.

@geniusjoe geniusjoe force-pushed the dev/http-authentication branch 5 times, most recently from 27bff25 to 04b849d Compare March 7, 2025 05:10
BrokerUrlTls: string;
HttpUrl: string;
HttpUrlTls: string |}>
|> Async.AwaitTask
Copy link
Member

Choose a reason for hiding this comment

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

Since this method is not recursive/retriable, we don't need async here, Async.AwaitTask as well, and GetBrokerInner is not needed, this code can be moved to just GetBroker

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed async and Async.AwaitTask in GetBrokerInner(), and migrate this code to GetBroker() with background{} wrapper.

randomServiceUri.AbsoluteUri + $"admin/v2/namespaces/%s{ns.ToString()}/topics?mode=%s{mode}"
|> httpClient.GetStreamAsync
|> pulsarHttpClient.Get<string seq>
Copy link
Member

Choose a reason for hiding this comment

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

Can you please change seq to array (in the interface as well)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I change HttpLookupService.fs ILookupService and BinaryLookupService GetTopicsUnderNamespace() return type. I think this function only used in PulsarClient.fs.GetTopicsByPattern() so that we don't need to change caller strategy.

@geniusjoe geniusjoe force-pushed the dev/http-authentication branch from 04b849d to b46cc1e Compare March 7, 2025 19:30
@geniusjoe geniusjoe force-pushed the dev/http-authentication branch from b46cc1e to c1b9588 Compare March 7, 2025 19:57
@Lanayx Lanayx self-requested a review March 7, 2025 20:15
@Lanayx Lanayx merged commit 1143c95 into fsprojects:develop Mar 7, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants