-
Notifications
You must be signed in to change notification settings - Fork 154
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
base: main
Are you sure you want to change the base?
Conversation
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).
Unit Test Results600 tests 600 ✅ 6s ⏱️ Results for commit 85f14fa. ♻️ This comment has been updated with latest results. |
This PR uncovered a few test bugs, however we are inconsistent with our resourceType naming. In the CI and makefile we use Going to leave this here, but should resolve this inconsistency. Suggest by amending the CI and makefile to use |
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. |
Fixes #1123
Add validation to API endpoints to ensure correct resourceType in template registration payloads.
api_app/api/routes/workspace_service_templates.py
to check ifresourceType
isWorkspaceService
before registering the template. Return a 422 Unprocessable Entity error if theresourceType
does not match.api_app/api/routes/workspace_templates.py
to check ifresourceType
isWorkspace
before registering the template. Return a 422 Unprocessable Entity error if theresourceType
does not match.api_app/api/routes/user_resource_templates.py
to check ifresourceType
isUserResource
before registering the template. Return a 422 Unprocessable Entity error if theresourceType
does not match.api_app/api/routes/shared_service_templates.py
to check ifresourceType
isSharedService
before registering the template. Return a 422 Unprocessable Entity error if theresourceType
does not match.INVALID_RESOURCE_TYPE
inapi_app/resources/strings.py
for validation errors, including the expected and received resourceType.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
, andapi_app/tests_ma/test_api/test_routes/test_shared_service_templates.py
to cover validation for each template registrationFor more details, open the Copilot Workspace session.