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

Add validation to Template API endpoints #4344

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

Conversation

marrobi
Copy link
Member

@marrobi marrobi commented Feb 7, 2025

Fixes #1123

Add validation to API endpoints to ensure correct resourceType in template registration payloads.

  • Workspace Service Templates: Add validation in api_app/api/routes/workspace_service_templates.py to check if resourceType is WorkspaceService before registering the template. Return a 422 Unprocessable Entity error if the resourceType does not match.
  • Workspace Templates: Add validation in api_app/api/routes/workspace_templates.py to check if resourceType is Workspace before registering the template. Return a 422 Unprocessable Entity error if the resourceType does not match.
  • User Resource Templates: Add validation in api_app/api/routes/user_resource_templates.py to check if resourceType is UserResource before registering the template. Return a 422 Unprocessable Entity error if the resourceType does not match.
  • Shared Service Templates: Add validation in api_app/api/routes/shared_service_templates.py to check if resourceType is SharedService before registering the template. Return a 422 Unprocessable Entity error if the resourceType does not match.
  • Common Error Message: Add a common error message string INVALID_RESOURCE_TYPE in api_app/resources/strings.py for validation errors, including the expected and received resourceType.
  • Tests: Add tests in api_app/tests_ma/test_api/test_routes/test_workspace_service_templates.py, api_app/tests_ma/test_api/test_routes/test_workspace_templates.py, api_app/tests_ma/test_api/test_routes/test_user_resource_templates.py, and api_app/tests_ma/test_api/test_routes/test_shared_service_templates.py to cover validation for each template registration

For more details, open the Copilot Workspace session.

Fixes #1123

Add validation to API endpoints to ensure correct resourceType in template registration payloads.

* **Workspace Service Templates**: Add validation in `api_app/api/routes/workspace_service_templates.py` to check if `resourceType` is `WorkspaceService` before registering the template. Return a 422 Unprocessable Entity error if the `resourceType` does not match.
* **Workspace Templates**: Add validation in `api_app/api/routes/workspace_templates.py` to check if `resourceType` is `Workspace` before registering the template. Return a 422 Unprocessable Entity error if the `resourceType` does not match.
* **User Resource Templates**: Add validation in `api_app/api/routes/user_resource_templates.py` to check if `resourceType` is `UserResource` before registering the template. Return a 422 Unprocessable Entity error if the `resourceType` does not match.
* **Shared Service Templates**: Add validation in `api_app/api/routes/shared_service_templates.py` to check if `resourceType` is `SharedService` before registering the template. Return a 422 Unprocessable Entity error if the `resourceType` does not match.
* **Common Error Message**: Add a common error message string `INVALID_RESOURCE_TYPE` in `api_app/resources/strings.py` for validation errors, including the expected and received resourceType.
* **Tests**: Add tests in `api_app/tests_ma/test_api/test_routes/test_workspace_service_templates.py`, `api_app/tests_ma/test_api/test_routes/test_workspace_templates.py`, `api_app/tests_ma/test_api/test_routes/test_user_resource_templates.py`, and `api_app/tests_ma/test_api/test_routes/test_shared_service_templates.py` to cover validation for each template registration

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/microsoft/AzureTRE/issues/1123?shareId=XXXX-XXXX-XXXX-XXXX).
Copy link

github-actions bot commented Feb 7, 2025

Unit Test Results

600 tests   600 ✅  6s ⏱️
  1 suites    0 💤
  1 files      0 ❌

Results for commit 85f14fa.

♻️ This comment has been updated with latest results.

@marrobi marrobi marked this pull request as draft February 7, 2025 21:42
@marrobi
Copy link
Member Author

marrobi commented Feb 7, 2025

This PR uncovered a few test bugs, however we are inconsistent with our resourceType naming. In the CI and makefile we use workspace_service, in the Python API we use workspace-service`.

Going to leave this here, but should resolve this inconsistency. Suggest by amending the CI and makefile to use -.

image
vs
image

@marrobi
Copy link
Member Author

marrobi commented Feb 12, 2025

Propose we should handle the naming difference in the Python code, and deal with the script update later, add notes to the release, then revert the Python in the future.

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.

Validation Missing from API Endpoints
1 participant