-
Notifications
You must be signed in to change notification settings - Fork 1
Add list-all-resources endpoint #7
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
BobbyRBruce
merged 3 commits into
gem5:add-list-resources-endpoint
from
Harshil2107:add-list-resources-end-point
Dec 23, 2025
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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 |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| # Copyright (c) 2025 The Regents of the University of California | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
|
|
||
| import json | ||
| import logging | ||
|
|
||
| import azure.functions as func | ||
|
|
||
| from shared.database import RESOURCE_FIELDS | ||
| from shared.utils import ( | ||
| create_error_response, | ||
| get_latest_versions, | ||
| sanitize_version, | ||
| ) | ||
|
|
||
|
|
||
| def register_function(app, collection): | ||
| """Register the function with the app.""" | ||
|
|
||
| @app.function_name(name="list_all_resources") | ||
| @app.route( | ||
| route="resources/list-all-resources", | ||
| auth_level=func.AuthLevel.ANONYMOUS, | ||
| ) | ||
| def list_all_resources(req: func.HttpRequest) -> func.HttpResponse: | ||
| """ | ||
| Get all resources where a gem5 version in the resource is a prefix | ||
| of the specified version parameter. | ||
|
|
||
| Route: /resources/list-all-resources | ||
|
|
||
| Query Parameters: | ||
| - gem5-version: Required, the gem5 version to match against | ||
| (e.g., "25.0.0.1" will match resources with "25.0") | ||
| - latest-version: Optional, if set to "true", returns only the latest | ||
| compatible version of each resource instead of all | ||
| compatible versions. Default is false (return all). | ||
| """ | ||
| logging.info( | ||
| "Processing request to list all resources by gem5 version" | ||
| ) | ||
| try: | ||
| gem5_version = req.params.get("gem5-version") | ||
| latest_version_only = ( | ||
| req.params.get("latest-version", "false").lower() == "true" | ||
| ) | ||
|
|
||
| if not gem5_version: | ||
| return create_error_response( | ||
| 400, "'gem5-version' parameter is required" | ||
| ) | ||
|
|
||
| gem5_version = sanitize_version(gem5_version) | ||
|
|
||
| if not gem5_version: | ||
| return create_error_response( | ||
| 400, "Invalid 'gem5-version' parameter format" | ||
| ) | ||
|
|
||
| # Build a list of all possible prefixes from the version | ||
| # Starting from major.minor since gem5 versions always have at | ||
| # least one dot (e.g., "25.0", "23.1") | ||
| # e.g., "25.0.0.1" -> ["25.0", "25.0.0", "25.0.0.1"] | ||
| version_parts = gem5_version.split(".") | ||
| prefixes = [] | ||
| for i in range(2, len(version_parts) + 1): | ||
| prefixes.append(".".join(version_parts[:i])) | ||
|
BobbyRBruce marked this conversation as resolved.
|
||
|
|
||
| # If only one part provided (e.g., "25"), return error | ||
| if not prefixes: | ||
| return create_error_response( | ||
| 400, | ||
| "Invalid 'gem5-version' parameter: must have at least " | ||
| "major version format (e.g., '23.0', '25.1')", | ||
| ) | ||
|
|
||
| # Query for resources where any gem5_version matches one of | ||
| # the prefixes | ||
| query = {"gem5_versions": {"$in": prefixes}} | ||
|
|
||
| resources = list(collection.find(query, RESOURCE_FIELDS)) | ||
|
|
||
| # If latest-version is set, return only the latest version of | ||
| # each resource | ||
| if latest_version_only: | ||
| resources = get_latest_versions(resources) | ||
|
|
||
| return func.HttpResponse( | ||
| body=json.dumps(resources), | ||
| status_code=200, | ||
| headers={"Content-Type": "application/json"}, | ||
| ) | ||
|
Harshil2107 marked this conversation as resolved.
|
||
|
|
||
| except Exception as e: | ||
| logging.error(f"Error listing resources by gem5 version: {str(e)}") | ||
| return create_error_response(500, "Internal server error") | ||
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.
Uh oh!
There was an error while loading. Please reload this page.