-
Couldn't load subscription status.
- Fork 11
Use POST requests for perforations, completions and casings from SubsurfaceDataApi #1144
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
Open
HansKallekleiv
wants to merge
8
commits into
equinor:main
Choose a base branch
from
HansKallekleiv:use-ssdl-post-requests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+210
−107
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
67f2902
Use post request for SSDL. Retrieve for multiple wells
HansKallekleiv 6ec3c9d
fix
HansKallekleiv 8353e56
fix
HansKallekleiv 80864af
fix
HansKallekleiv 20c048d
fix
HansKallekleiv 3f8d0ce
fix
HansKallekleiv 12821d9
fix
HansKallekleiv 2d1dd05
correct endpoint
HansKallekleiv 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
50 changes: 0 additions & 50 deletions
50
backend_py/primary/primary/services/ssdl_access/_ssdl_get_request.py
This file was deleted.
Oops, something went wrong.
107 changes: 107 additions & 0 deletions
107
backend_py/primary/primary/services/ssdl_access/_ssdl_request.py
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,107 @@ | ||
| import logging | ||
| from typing import List, Optional | ||
|
|
||
| from webviz_pkg.core_utils.perf_timer import PerfTimer | ||
|
|
||
| from primary import config | ||
| from primary.services.utils.httpx_async_client_wrapper import HTTPX_ASYNC_CLIENT_WRAPPER | ||
| from primary.services.service_exceptions import ( | ||
| Service, | ||
| InvalidDataError, | ||
| InvalidParameterError, | ||
| AuthorizationError, | ||
| ) | ||
|
|
||
| LOGGER = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| async def ssdl_get_request_async(access_token: str, endpoint: str, params: Optional[dict] = None) -> List[dict]: | ||
| """Convenience function for GET requests. Always returns a list of dictionaries.""" | ||
| result = await _ssdl_request_async(access_token, endpoint, method="GET", params=params) | ||
| # GET requests always return List[dict], so we can safely cast | ||
| return result if isinstance(result, list) else [result] | ||
|
|
||
|
|
||
| async def ssdl_post_request_async( | ||
| access_token: str, | ||
| endpoint: str, | ||
| data: Optional[List[str]] = None, | ||
| params: Optional[dict] = None, | ||
| ) -> dict: | ||
| """Convenience function for POST requests. Always returns a single dictionary.""" | ||
| result = await _ssdl_request_async(access_token, endpoint, method="POST", data=data, params=params) | ||
| # POST requests always return dict, so we can safely cast | ||
| return result if isinstance(result, dict) else result[0] | ||
|
|
||
|
|
||
| async def _ssdl_request_async( | ||
| access_token: str, | ||
| endpoint: str, | ||
| method: str = "GET", | ||
| data: Optional[List[str]] = None, | ||
| params: Optional[dict] = None, | ||
| ) -> List[dict] | dict: | ||
| """ | ||
| Generic HTTP request to SSDL API. | ||
| Supports both GET and POST methods. | ||
|
|
||
| Args: | ||
| access_token: Bearer token for authentication | ||
| endpoint: SSDL API endpoint (without base URL) | ||
| method: HTTP method ("GET" or "POST") | ||
| data: Request body data for POST requests (list of strings) | ||
| params: URL query parameters | ||
|
|
||
| Returns: | ||
| For GET requests: List[dict] - collection of items | ||
| For POST requests: dict - single result object | ||
|
|
||
| Note: | ||
| GET requests always return collections (List[dict]). | ||
| POST requests always return a single object (dict). | ||
|
|
||
| Raises: | ||
| AuthorizationError: For 401/403 responses | ||
| InvalidDataError: For 404 responses | ||
| InvalidParameterError: For 400 and other error responses | ||
| """ | ||
| urlstring = f"https://api.gateway.equinor.com/subsurfacedata/v3/api/v3.0/{endpoint}?" | ||
| params = params if params else {} | ||
| headers = { | ||
| "Content-Type": "application/json", | ||
| "authorization": f"Bearer {access_token}", | ||
| "Ocp-Apim-Subscription-Key": config.ENTERPRISE_SUBSCRIPTION_KEY, | ||
| } | ||
| timer = PerfTimer() | ||
|
|
||
| # Make the HTTP request based on method | ||
| if method.upper() == "POST": | ||
| post_data = data if data else [] | ||
| response = await HTTPX_ASYNC_CLIENT_WRAPPER.client.post( | ||
| urlstring, json=post_data, params=params, headers=headers, timeout=60 | ||
| ) | ||
| elif method.upper() == "GET": | ||
| response = await HTTPX_ASYNC_CLIENT_WRAPPER.client.get(urlstring, params=params, headers=headers, timeout=60) | ||
| else: | ||
| raise InvalidParameterError(f"Unsupported HTTP method: {method}", Service.SSDL) | ||
|
|
||
| # Handle response | ||
| results = [] | ||
| if response.status_code in [200, 201]: | ||
| results = response.json() | ||
| elif response.status_code == 401: | ||
| raise AuthorizationError("Unauthorized access to SSDL", Service.SSDL) | ||
| elif response.status_code == 403: | ||
| raise AuthorizationError("Forbidden access to SSDL", Service.SSDL) | ||
| elif response.status_code == 404: | ||
| raise InvalidDataError(f"No data found for endpoint {endpoint} with given parameters", Service.SSDL) | ||
| elif response.status_code == 400: | ||
| raise InvalidParameterError(f"Bad request to endpoint {endpoint}: {response.text}", Service.SSDL) | ||
| else: | ||
| # Capture other errors | ||
| raise InvalidParameterError( | ||
| f"Cannot {method.lower()} data from endpoint {endpoint}: {response.text}", Service.SSDL | ||
| ) | ||
|
|
||
| LOGGER.debug(f"TIME SSDL {method.lower()} {endpoint} took {timer.lap_s():.2f} seconds") | ||
| return results | ||
HansKallekleiv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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.
You're not casting here? Is this comment outdated?