Skip to content

Conversation

@ChrisAnn
Copy link
Contributor

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

@ghost ghost 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
Contributor 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
@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@ChrisAnn
Copy link
Contributor 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
Contributor

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);

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

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 uses AI. Check for mistakes.
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
Contributor 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

@azure-pipelines
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
Contributor 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. 🤔

@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
@captainsafia
Copy link
Member

/azp run

@dotnet-policy-service dotnet-policy-service bot removed the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Jan 3, 2025
@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@captainsafia captainsafia enabled auto-merge (squash) January 3, 2025 16:02
@captainsafia captainsafia merged commit af70e57 into dotnet:main Jan 3, 2025
26 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the 10.0-preview1 milestone Jan 3, 2025
@ChrisAnn ChrisAnn deleted the user-jwts-appsettings branch January 4, 2025 15:21
captainsafia pushed a commit that referenced this pull request Feb 11, 2025
* Adds the ability to specify an appsettings file for user-jwts

Addresses #56169

* Move the validation logic into a central location

* Adds copilot suggestions to improve error messages

* Fix tests after changing error message when appsettings not found
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make dotnet-user-jwts support custom appsettings json file

3 participants