-
Notifications
You must be signed in to change notification settings - Fork 21
Hotfix v6.0.1 into Main #592
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1004058
Updating version for hotfix v6.0.1
estohlmann 209bab3
prisma cache fix
dustins 5a9ef2a
fixed docs
dustins afe2355
Fix reducer caches
bedanley 0ffe169
Add admin status check for model operations and refactor related code
estohlmann 7b1a9e0
Remove 'MCP Workbench' from admin menu options in adminHelpers.ts
estohlmann 10cf14f
Update health endpoint
bedanley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 6.0.0 | ||
| 6.0.1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,7 @@ | |
|
|
||
| import boto3 | ||
| import botocore.session | ||
| from fastapi import FastAPI, Path, Request | ||
| from fastapi import FastAPI, HTTPException, Path, Request | ||
| from fastapi.encoders import jsonable_encoder | ||
| from fastapi.exceptions import RequestValidationError | ||
| from fastapi.middleware.cors import CORSMiddleware | ||
|
|
@@ -61,6 +61,21 @@ | |
| stepfunctions = boto3.client("stepfunctions", region_name=os.environ["AWS_REGION"], config=retry_config) | ||
|
|
||
|
|
||
| def get_admin_status_and_groups(request: Request) -> tuple[bool, list[str]]: | ||
| admin_status = False | ||
| user_groups = [] | ||
|
|
||
| if "aws.event" in request.scope: | ||
| event = request.scope["aws.event"] | ||
| try: | ||
| user_groups = get_groups(event) | ||
| admin_status = is_admin(event) | ||
| except Exception: | ||
| user_groups = [] | ||
| admin_status = False | ||
| return admin_status, user_groups | ||
|
|
||
|
|
||
| @app.exception_handler(ModelNotFoundError) | ||
| async def model_not_found_handler(request: Request, exc: ModelNotFoundError) -> JSONResponse: | ||
| """Handle exception when model cannot be found and translate to a 404 error.""" | ||
|
|
@@ -87,8 +102,11 @@ async def user_error_handler( | |
|
|
||
| @app.post(path="", include_in_schema=False) | ||
| @app.post(path="/") | ||
| async def create_model(create_request: CreateModelRequest) -> CreateModelResponse: | ||
| async def create_model(create_request: CreateModelRequest, request: Request) -> CreateModelResponse: | ||
| """Endpoint to create a model.""" | ||
| admin_status, _ = get_admin_status_and_groups(request) | ||
| if not admin_status: | ||
| raise HTTPException(status_code=403, detail="User does not have permission to create models.") | ||
|
Comment on lines
+107
to
+109
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The authorization check uses a generic error message. Consider including more context about what permissions are required or suggesting next steps for the user. |
||
| create_handler = CreateModelHandler( | ||
| autoscaling_client=autoscaling, | ||
| stepfunctions_client=stepfunctions, | ||
|
|
@@ -109,18 +127,7 @@ async def list_models(request: Request) -> ListModelsResponse: | |
| guardrails_table_resource=guardrails_table, | ||
| ) | ||
|
|
||
| user_groups = [] | ||
| admin_status = False | ||
|
|
||
| if "aws.event" in request.scope: | ||
| event = request.scope["aws.event"] | ||
| try: | ||
| user_groups = get_groups(event) | ||
| admin_status = is_admin(event) | ||
| except Exception: | ||
| user_groups = [] | ||
| admin_status = False | ||
|
|
||
| admin_status, user_groups = get_admin_status_and_groups(request) | ||
| return list_handler(user_groups=user_groups, is_admin=admin_status) | ||
|
|
||
|
|
||
|
|
@@ -136,27 +143,20 @@ async def get_model( | |
| guardrails_table_resource=guardrails_table, | ||
| ) | ||
|
|
||
| user_groups = [] | ||
| admin_status = False | ||
|
|
||
| if "aws.event" in request.scope: | ||
| event = request.scope["aws.event"] | ||
| try: | ||
| user_groups = get_groups(event) | ||
| admin_status = is_admin(event) | ||
| except Exception: | ||
| user_groups = [] | ||
| admin_status = False | ||
|
|
||
| admin_status, user_groups = get_admin_status_and_groups(request) | ||
| return get_handler(model_id=model_id, user_groups=user_groups, is_admin=admin_status) | ||
|
|
||
|
|
||
| @app.put(path="/{model_id}") | ||
| async def update_model( | ||
| model_id: Annotated[str, Path(title="The unique model ID of the model to update")], | ||
| update_request: UpdateModelRequest, | ||
| request: Request, | ||
| ) -> UpdateModelResponse: | ||
| """Endpoint to update a model.""" | ||
| admin_status, _ = get_admin_status_and_groups(request) | ||
| if not admin_status: | ||
| raise HTTPException(status_code=403, detail="User does not have permission to update models.") | ||
| update_handler = UpdateModelHandler( | ||
| autoscaling_client=autoscaling, | ||
| stepfunctions_client=stepfunctions, | ||
|
|
@@ -171,6 +171,9 @@ async def delete_model( | |
| model_id: Annotated[str, Path(title="The unique model ID of the model to delete")], request: Request | ||
| ) -> DeleteModelResponse: | ||
| """Endpoint to delete a model.""" | ||
| admin_status, _ = get_admin_status_and_groups(request) | ||
| if not admin_status: | ||
| raise HTTPException(status_code=403, detail="User does not have permission to delete models.") | ||
| delete_handler = DeleteModelHandler( | ||
| autoscaling_client=autoscaling, | ||
| stepfunctions_client=stepfunctions, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # Placeholder to ensure PRISMA_CACHE directory exists in build context | ||
| # For offline builds, populate this directory by copying the complete Prisma cache: | ||
| # 1. Install prisma: pip3 install prisma | ||
| # 2. Generate cache: prisma version | ||
| # 3. Copy cache: cp -r ~/.cache/prisma* lib/serve/rest-api/PRISMA_CACHE/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The
get_admin_status_and_groups()function silently catches all exceptions and returns default values. This could mask legitimate errors (e.g., network issues, malformed event data). Consider logging the exception or being more specific about which exceptions to catch.