-
Notifications
You must be signed in to change notification settings - Fork 334
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
Updating workflow collection to allow for use of API Token validation #1141
Conversation
Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #1141 +/- ##
==========================================
+ Coverage 66.45% 66.47% +0.02%
==========================================
Files 171 171
Lines 5750 5754 +4
Branches 624 624
==========================================
+ Hits 3821 3825 +4
Misses 1782 1782
Partials 147 147
Flags with carried forward coverage won't be shown. Click here to find out more.
☔ View full report in Codecov by Sentry. 📢 Have feedback on the report? Share it here. |
|
||
public static IServiceCollection ConfigureDurableGrpcClient(this IServiceCollection services, string apiToken) | ||
{ | ||
services.AddHttpClient(ClientName) |
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.
For my understanding: Why do we need to add HttpClient while configuring Grpc Client?
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.
Under the hood, the gRPC client uses the HttpClient. It's all HTTP/2 for transport iirc.
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.
Can you update the example readme with how to use the API token?
DaprClient daprClient; | ||
string apiToken = Environment.GetEnvironmentVariable("DAPR_API_TOKEN"); | ||
if (!string.IsNullOrEmpty(apiToken)) | ||
{ | ||
daprClient = new DaprClientBuilder().UseDaprApiToken(apiToken).Build(); | ||
} | ||
else | ||
{ | ||
daprClient = new DaprClientBuilder().Build(); | ||
} |
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 still need the using
. After the initialization, you can just wrap the while
in this:
using (daprClient)
{
// Loop here.
}
@@ -57,7 +59,19 @@ public static class WorkflowServiceCollectionExtensions | |||
|
|||
if (TryGetGrpcAddress(out string address)) | |||
{ | |||
builder.UseGrpc(address); | |||
string? apiToken = Environment.GetEnvironmentVariable("DAPR_API_TOKEN"); |
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.
For consistency, please use var
where you can.
serviceCollection.ConfigureDurableGrpcClient(apiToken); | ||
HttpClient client = new HttpClient(); | ||
client.DefaultRequestHeaders.Add("Dapr-Api-Token", apiToken); | ||
builder.UseGrpc(CreateChannel(client)); |
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.
This seems to repeat the code in the ConfigureDurableGrpcClient
do we need both methods?
Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>
…flow-api-token-fix
8723c3b
to
b4a1095
Compare
Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>
// serviceCollection.ConfigureDurableGrpcClient(apiToken); | ||
HttpClient client = new HttpClient(); | ||
client.DefaultRequestHeaders.Add("Dapr-Api-Token", apiToken); | ||
builder.UseGrpc(CreateChannel(client)); |
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.
The address
variable should be passed to the builder, otherwise if users configured Dapr to use a non-localhost endpoint, this will not be propagated correctly to the underlying Durable Task client. Good find by @alicejgibbons
Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>
Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>
Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>
Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>
Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>
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.
One question and a few nits. Did you ensure that the various places where we call the DaprDefault
methods all handle an empty/null case instead of just a null case? It shouldn't be too many places to check.
Description
Updated the service collection for workflow in the .NET SDK to allow for the use of api token authentication. Since the durable task framework allows for the passing in of a gRPC channel when configuring the gRPC client, we now create a gRPC channel object to have the API Token headers as well as the address we want to use and pass that through to the DTFx.
Issue reference
The issue this PR will close: #[1134]
Checklist
Please make sure you've completed the relevant tasks for this PR, out of the following list: