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

Adds the ability to specify an appsettings file for user-jwts #58605

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ChrisAnn
Copy link

Adds the ability to specify an appsettings file for user-jwts

Adds the ability to specify an appsettings file for user-jwts

Description

Currently the user-jwts tool amends appsettings.Development.json when adding a mock JWT scheme for local testing. Many people use appsettings.Development.json for environments other than local development, i.e. a cloud Development environment, and so this amendment causes issues. In my particular case, we have appsettings.Local.json instead and so the tool fails to execute because it cannot find appsettings.Development.json.

As described in #56169 this affects multiple other teams too.

This PR allows for an appsettings file to be specified which will be amended instead of the default appsettings.Development.json. The tool still assumes the file lives next to the project, as it currently does, and checks that the file both exists and ends in .json. Tests have been added to confirm the functionality.

Fixes #56169

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI label Oct 24, 2024
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Oct 24, 2024
@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Oct 31, 2024
@ChrisAnn
Copy link
Author

@dotnet-policy-service agree company="Stack Overflow"

Copy link
Member

@captainsafia captainsafia left a comment

Choose a reason for hiding this comment

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

LGTM overall!

It might be a good idea to move the validation logic that is duplicated across different source files into a single helper to make it easier to keep the validation logic in sync across the different commands.

@halter73 Can you sanity check my review here?

@captainsafia
Copy link
Member

/azp run

@captainsafia captainsafia removed the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Dec 16, 2024
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@ChrisAnn
Copy link
Author

Thanks for taking a look @captainsafia

I've moved the validation logic to reduce duplication as suggested :)

@captainsafia captainsafia requested a review from Copilot December 17, 2024 18:01
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 5 out of 7 changed files in this pull request and generated 2 comments.

Files not reviewed (2)
  • src/Tools/dotnet-user-jwts/src/Resources.resx: Language not supported
  • src/Tools/dotnet-user-jwts/src/Commands/RemoveCommand.cs: Evaluated as low risk
Comments suppressed due to low confidence (1)

src/Tools/dotnet-user-jwts/src/Helpers/DevJwtCliHelpers.cs:55

  • The error message 'Resources.RemoveCommand_InvalidAppsettingsFile_Error' is unclear. It should be more descriptive, such as 'The specified appsettings file is invalid. Please provide a valid JSON file.'
reporter.Error(Resources.RemoveCommand_InvalidAppsettingsFile_Error);


var appSettings = JsonSerializer.Deserialize<JsonObject>(File.ReadAllText(appsettings));
Assert.Equal("dotnet-user-jwts", appSettings["Authentication"]["Schemes"]["Bearer"]["ValidIssuer"].GetValue<string>());
app.Run(["create", "--project", project, "--issuer", "new-issuer", "--appsettings-file", "appsettings.Local.json"]);
Copy link
Preview

Copilot AI Dec 17, 2024

Choose a reason for hiding this comment

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

The method call should use parentheses instead of square brackets.

Suggested change
app.Run(["create", "--project", project, "--issuer", "new-issuer", "--appsettings-file", "appsettings.Local.json"]);
app.Run(new[] { "create", "--project", project, "--issuer", "new-issuer", "--appsettings-file", "appsettings.Local.json" });

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
Copy link
Member

Choose a reason for hiding this comment

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

This isn't a good suggestion. We're taking advantage of the new collection expressions language feature here.

}
else if (!File.Exists(Path.Combine(Path.GetDirectoryName(projectPath), appsettingsFile)))
{
reporter.Error(Resources.FormatRemoveCommand_AppsettingsFileNotFound_Error(Path.GetDirectoryName(projectPath)));
Copy link
Preview

Copilot AI Dec 17, 2024

Choose a reason for hiding this comment

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

The error message 'Resources.FormatRemoveCommand_AppsettingsFileNotFound_Error' should include the filename that was not found to provide more context to the user.

Suggested change
reporter.Error(Resources.FormatRemoveCommand_AppsettingsFileNotFound_Error(Path.GetDirectoryName(projectPath)));
reporter.Error(Resources.FormatRemoveCommand_AppsettingsFileNotFound_Error(Path.Combine(Path.GetDirectoryName(projectPath), appsettingsFile)));

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
Copy link
Member

Choose a reason for hiding this comment

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

This seems like a good suggestion, especially if the user has provided a non-default value for the upsettings file. @ChrisAnn thoughts?

Copy link
Author

Choose a reason for hiding this comment

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

Seems reasonable to me, along with the suggested wording change copilot made above.
I've pushed the changes :)

Copy link
Member

@captainsafia captainsafia left a comment

Choose a reason for hiding this comment

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

LGTM overall!

Copilot provided one helpful suggestion that might be worthwhile to apply.

@captainsafia
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@captainsafia captainsafia enabled auto-merge (squash) December 18, 2024 23:49
auto-merge was automatically disabled December 20, 2024 17:38

Head branch was pushed to by a user without write access

@ChrisAnn
Copy link
Author

Apologies for not running the tests locally after changing the error messages 🙈
That should be fixed now 🤞🏻

@captainsafia
Copy link
Member

Apologies for not running the tests locally after changing the error messages 🙈 That should be fixed now 🤞🏻

🙊 Oops -- I should've caught that before approving and putting this PR on auto-merge. 😬 But hey....hurrah for CI catching human error? I wonder if Copilot would've flagged it. 🤔

Copy link
Contributor

Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime.
To make sure no conflicting changes have occurred, please rerun validation before merging. You can do this by leaving an /azp run comment here (requires commit rights), or by simply closing and reopening.

@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Dec 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI community-contribution Indicates that the PR has been added by a community member pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make dotnet-user-jwts support custom appsettings json file
3 participants