-
Notifications
You must be signed in to change notification settings - Fork 172
Add validation to Template API endpoints #4344
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
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 Results612 tests 612 ✅ 7s ⏱️ Results for commit b72ca14. ♻️ 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. |
|
Marking as ready for review. |
martinpeck
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've left a question/comment but LGTM either way.
@martinpeck what think of best way to sort this? The scripts send resources with I don't want to break everyone's pipelines. Could do a replace of |
|
@marrobi honestly, I'm a bit confused about the underscore/hyphen issue. Perhaps let's chat. |
|
If we did patch up the problem in that script, I would suggest we do that only as a temp measure, generate a warning saying "WARNING: Fix this cos we won't patch this for you later", and then remove that patch code in a later release. |


Fixes #1123
Add validation to API endpoints to ensure correct resourceType in template registration payloads.
api_app/api/routes/workspace_service_templates.pyto check ifresourceTypeisWorkspaceServicebefore registering the template. Return a 422 Unprocessable Entity error if theresourceTypedoes not match.api_app/api/routes/workspace_templates.pyto check ifresourceTypeisWorkspacebefore registering the template. Return a 422 Unprocessable Entity error if theresourceTypedoes not match.api_app/api/routes/user_resource_templates.pyto check ifresourceTypeisUserResourcebefore registering the template. Return a 422 Unprocessable Entity error if theresourceTypedoes not match.api_app/api/routes/shared_service_templates.pyto check ifresourceTypeisSharedServicebefore registering the template. Return a 422 Unprocessable Entity error if theresourceTypedoes not match.INVALID_RESOURCE_TYPEinapi_app/resources/strings.pyfor 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.pyto cover validation for each template registrationFor more details, open the Copilot Workspace session.