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

Improve validation for TfsEndpoint PAT tokens and message #2368

Merged
merged 9 commits into from
Sep 15, 2024

Conversation

MrHinsh
Copy link
Member

@MrHinsh MrHinsh commented Sep 15, 2024

Both @soodgautam and @nkofctg ran into issues with the when you are migrating to Azure DevOps you MUST provide an PAT so that we can call the REST API for certain actions. For example, we would be unable to deal with a Work item Type change. message!

This was due to the SourceName and/or TargetName on the Processor being set to null. The validator now checks for this!

It now checks for:

  • SourceName and/or TargetName being Set
  • SourceName and/or TargetName existing
  • SourceName and/or TargetName of correct type

…it details

♻️ (TfsAuthenticationOptions): implement IValidateOptions for validation
♻️ (TfsEndpointOptions): refactor validation logic to use IValidateOptions
♻️ (TfsLanguageMapOptions): implement IValidateOptions for validation
♻️ (TfsWorkItemMigrationProcessorOptions): enhance validation logic

Update the MigrationTools.xml documentation to reflect the latest branch and commit details, ensuring the documentation is current. Implement IValidateOptions in TfsAuthenticationOptions and TfsLanguageMapOptions to standardize and improve validation logic. Refactor TfsEndpointOptions to utilize the new validation methods, enhancing code maintainability and readability. Enhance validation logic in TfsWorkItemMigrationProcessorOptions to ensure required fields and conditions are met, improving robustness and error handling.

♻️ (EndpointRegistrationExtensions.cs): pass endpointName to InvokeValidator for better context
🐛 (Processor.cs): remove duplicate exception tracking to avoid redundant telemetry

Passing the `endpointName` to `InvokeValidator` provides better context during validation, which can help in debugging and logging. Removing the duplicate `Telemetry.TrackException` call in `Processor.cs` prevents redundant telemetry data, ensuring cleaner logs and more accurate error tracking.
♻️ (TfsTeamProjectAuthentication): add validation for NetworkCredentials
✨ (NetworkCredentialsOptions): implement IValidateOptions for NetworkCredentials

The documentation is updated to reflect the latest branch and commit details, ensuring accuracy. The TfsTeamProjectAuthentication class now includes validation for NetworkCredentials, improving error handling and robustness. The NetworkCredentials class implements IValidateOptions to provide a structured way to validate its properties, ensuring that Domain, UserName, and Password are not null or empty.
…ror messages to include documentation links

Enhance error messages with links to relevant documentation for better user guidance. This helps users quickly find detailed instructions and reduces confusion when encountering errors.
♻️ (ProcessorOptions): integrate validation logic into ProcessorOptions class
♻️ (TfsWorkItemMigrationProcessorOptions): remove redundant validator class
🔧 (ServiceCollectionExtensions): change validator registration to transient
🐛 (ConfigurationValidationException): fix property name and add constructor overload
🐛 (Processor): throw ConfigurationValidationException for missing endpoints

Renaming endpoint keys in `configuration.json` improves clarity and consistency. Integrating validation logic directly into `ProcessorOptions` and `TfsWorkItemMigrationProcessorOptions` simplifies the codebase by removing redundant classes. Changing the validator registration to transient ensures a new instance is created each time, which is more appropriate for validation. Fixing the property name in `ConfigurationValidationException` and adding a constructor overload enhances error reporting. Finally, throwing `ConfigurationValidationException` for missing endpoints ensures proper error handling.
… separate validator class

The validation logic is moved from `TfsWorkItemMigrationProcessorOptions` to a new class `TfsWorkItemMigrationProcessorOptionsValidator`. This change improves the single responsibility principle by separating the concerns of option definition and validation. It also enhances code maintainability and readability by isolating validation logic in its own class.
…or TfsWorkItemMigrationProcessorOptions validation

The type registered for validating `TfsWorkItemMigrationProcessorOptions` is corrected from `TfsWorkItemMigrationProcessorOptions` to `TfsWorkItemMigrationProcessorOptionsValidator`. This ensures that the correct validation logic is applied, preventing potential runtime errors and improving the robustness of the service configuration.
📝 (MigrationTools.xml): update generated documentation with new commit details
✅ (TfsWorkItemMigrationProcessorTests.cs): add SourceName and TargetName to test validation
♻️ (Processor.cs): remove redundant Telemetry.TrackException call

Updating the EndpointType in configuration.json to AzureDevOpsEndpoint reflects the current naming conventions and services used. The generated documentation in MigrationTools.xml is updated to reflect the latest commit details, ensuring accuracy. Adding SourceName and TargetName in the TfsWorkItemMigrationProcessorTests.cs improves the test coverage and validation accuracy. Removing the redundant Telemetry.TrackException call in Processor.cs simplifies the error handling and logging process.
…e type validation

✨ (TfsProcessor.cs): add ConfigurationValidationException for invalid endpoint types

The Source and Target properties now include type validation to ensure they are of type TfsTeamProjectEndpoint. If the type is incorrect, a ConfigurationValidationException is thrown, providing a clear error message. This change improves robustness by preventing misconfigurations and ensuring that the endpoints are of the expected type.
Change EndpointType from AzureDevOpsEndpoint to TfsTeamProjectEndpoint for both Source and Target endpoints. This change is necessary to align with the updated endpoint configuration requirements and ensure compatibility with the TFS Team Project endpoints.
@MrHinsh MrHinsh merged commit c1dc8d1 into main Sep 15, 2024
12 checks passed
@MrHinsh MrHinsh deleted the topic/validation-refactor branch September 15, 2024 23:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation This is an item for a Documentation enhancement enhancement enhancement-modern feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant