-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: add service info endpoint #5
base: base-sha/9e84a5b0225fccc065cb01c811b8b8bd1c655a07
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,34 @@ api: | |
swagger_ui: True | ||
serve_spec: True | ||
|
||
# Custom configuration | ||
# Cf. https://foca.readthedocs.io/en/latest/modules/foca.models.html#foca.models.config.CustomConfig | ||
custom: | ||
# ServiceInfo configuration based on ServiceInfo model | ||
service_info: | ||
id: org.ga4gh.myservice | ||
name: My project | ||
type: | ||
group: org.ga4gh | ||
artifact: tes | ||
version: 1.0.0 | ||
description: This service provides... | ||
organization: | ||
name: My organization | ||
url: https://example.com | ||
contactUrl: mailto:[email protected] | ||
documentationUrl: https://docs.myservice.example.com | ||
createdAt: '2019-06-04T12:58:19Z' | ||
updatedAt: '2019-06-04T12:58:19Z' | ||
environment: test | ||
version: 1.0.0 | ||
storage: | ||
- file:///path/to/local/funnel-storage | ||
- s3://ohsu-compbio-funnel/storage | ||
tesResources_backend_parameters: | ||
- VmSize | ||
- ParamToRecogniseDataComingFromConfig | ||
|
||
# Logging configuration | ||
# Cf. https://foca.readthedocs.io/en/latest/modules/foca.models.html#foca.models.config.LogConfig | ||
log: | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -5,6 +5,8 @@ | |||||||||||||
# from connexion import request # type: ignore | ||||||||||||||
from foca.utils.logging import log_traffic # type: ignore | ||||||||||||||
|
||||||||||||||
from tesk.api.ga4gh.tes.service_info.service_info import ServiceInfo | ||||||||||||||
|
||||||||||||||
# Get logger instance | ||||||||||||||
logger = logging.getLogger(__name__) | ||||||||||||||
|
||||||||||||||
|
@@ -36,14 +38,10 @@ def CreateTask(*args, **kwargs) -> dict: # type: ignore | |||||||||||||
|
||||||||||||||
# GET /tasks/service-info | ||||||||||||||
@log_traffic | ||||||||||||||
def GetServiceInfo(*args, **kwargs) -> dict: # type: ignore | ||||||||||||||
"""Get service info. | ||||||||||||||
|
||||||||||||||
Args: | ||||||||||||||
*args: Variable length argument list. | ||||||||||||||
**kwargs: Arbitrary keyword arguments. | ||||||||||||||
""" | ||||||||||||||
pass | ||||||||||||||
def GetServiceInfo() -> dict: # type: ignore | ||||||||||||||
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. suggestion: Consider handling potential exceptions The
Suggested change
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. Is this comment correct? 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. Is this comment helpful? 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. Is the comment type correct? 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. Is the comment area correct? 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. What type of LLM test could this comment become?
|
||||||||||||||
"""Get service info.""" | ||||||||||||||
service_info = ServiceInfo() | ||||||||||||||
return service_info.response() | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
# GET /tasks | ||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -353,7 +353,7 @@ class Service(BaseModel): | |
organization: Organization = Field( | ||
..., description="Organization providing the service" | ||
) | ||
contactUrl: Optional[AnyUrl] = Field( | ||
contactUrl: Optional[str] = Field( | ||
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. issue (bug_risk): Revert type change for contactUrl Changing the type of 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. Is this comment correct? 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. Is this comment helpful? 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. Is the comment type correct? 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. Is the comment area correct? 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. What type of LLM test could this comment become?
|
||
default=None, | ||
description="URL of the contact for the provider of this service, e.g. a link to a " | ||
"contact form (RFC 3986 format), or an email (RFC 2368 format).", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Package for the TES Service Info endpoint.""" |
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,87 @@ | ||||||||||||||
"""Service info for TES API.""" | ||||||||||||||
|
||||||||||||||
import json | ||||||||||||||
from typing import Any, Optional | ||||||||||||||
|
||||||||||||||
from pydantic import AnyUrl | ||||||||||||||
|
||||||||||||||
from tesk.api.ga4gh.tes.models import ( | ||||||||||||||
Artifact, | ||||||||||||||
Organization, | ||||||||||||||
TesServiceInfo, | ||||||||||||||
TesServiceType, | ||||||||||||||
) | ||||||||||||||
from tesk.exceptions import ConfigNotFoundError | ||||||||||||||
from tesk.tesk_app import TeskApp | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
class ServiceInfo: | ||||||||||||||
"""Service info for TES API.""" | ||||||||||||||
|
||||||||||||||
def __init__(self) -> None: | ||||||||||||||
"""Initializes the BaseServiceInfoRequest class.""" | ||||||||||||||
self.service_info: Optional[TesServiceInfo] = None | ||||||||||||||
self.config = TeskApp().conf | ||||||||||||||
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. suggestion: Consider dependency injection for configuration Directly instantiating
Suggested change
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. Is this comment correct? 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. Is this comment helpful? 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. Is the comment type correct? 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. Is the comment area correct? 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. What type of LLM test could this comment become?
|
||||||||||||||
|
||||||||||||||
def get_default_service_info(self) -> TesServiceInfo: | ||||||||||||||
"""Get the default service info. | ||||||||||||||
|
||||||||||||||
if service info is not provided in the config, | ||||||||||||||
this method will return the default service info. | ||||||||||||||
|
||||||||||||||
Returns: | ||||||||||||||
TesServiceInfo: Default service info. | ||||||||||||||
""" | ||||||||||||||
return TesServiceInfo( | ||||||||||||||
id="org.ga4gh.tes", | ||||||||||||||
name="TES", | ||||||||||||||
type=TesServiceType( | ||||||||||||||
group="org.ga4gh", | ||||||||||||||
artifact=Artifact.tes, | ||||||||||||||
version="1.1.0", | ||||||||||||||
), | ||||||||||||||
organization=Organization( | ||||||||||||||
name="my_organization", | ||||||||||||||
url=AnyUrl("https://example.com"), | ||||||||||||||
), | ||||||||||||||
version="1.1.0", | ||||||||||||||
) | ||||||||||||||
|
||||||||||||||
def get_service_info_from_config(self) -> TesServiceInfo: | ||||||||||||||
"""Returns service info from config. | ||||||||||||||
|
||||||||||||||
Returns: | ||||||||||||||
TesServiceInfo: Service info from config. | ||||||||||||||
|
||||||||||||||
Raises: | ||||||||||||||
ConfigNotFoundError: If custom config or part of it is not found | ||||||||||||||
in the config file. | ||||||||||||||
""" | ||||||||||||||
if not self.config.custom: | ||||||||||||||
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. suggestion (bug_risk): Check for None explicitly Using
Suggested change
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. Is this comment correct? 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. Is this comment helpful? 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. Is the comment type correct? 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. Is the comment area correct? 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. What type of LLM test could this comment become?
|
||||||||||||||
raise ConfigNotFoundError("Custom configuration not found.") | ||||||||||||||
|
||||||||||||||
service_info_data = self.config.custom.get("service_info") | ||||||||||||||
if not service_info_data: | ||||||||||||||
raise ConfigNotFoundError("Service info not found in custom configuration.") | ||||||||||||||
|
||||||||||||||
try: | ||||||||||||||
service_info = TesServiceInfo(**service_info_data) | ||||||||||||||
except TypeError as e: | ||||||||||||||
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. suggestion: Consider logging the exception Logging the exception can provide more context when debugging issues related to invalid service info format.
Suggested change
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. Is this comment correct? 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. Is this comment helpful? 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. Is the comment type correct? 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. Is the comment area correct? 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. What type of LLM test could this comment become?
|
||||||||||||||
raise ConfigNotFoundError(f"Invalid service info format: {e}") from None | ||||||||||||||
|
||||||||||||||
return service_info | ||||||||||||||
|
||||||||||||||
def response(self) -> dict[str, Any]: | ||||||||||||||
"""Returns serialized response for /service-info. | ||||||||||||||
|
||||||||||||||
Returns: | ||||||||||||||
dict: Serialized response. | ||||||||||||||
""" | ||||||||||||||
if self.service_info is None: | ||||||||||||||
try: | ||||||||||||||
self.service_info = self.get_service_info_from_config() | ||||||||||||||
except ConfigNotFoundError: | ||||||||||||||
self.service_info = self.get_default_service_info() | ||||||||||||||
|
||||||||||||||
# return self.service_info.dict() | ||||||||||||||
return dict(json.loads(self.service_info.json())) | ||||||||||||||
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. suggestion: Simplify JSON serialization The line
Suggested change
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. Is this comment correct? 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. Is this comment helpful? 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. Is the comment type correct? 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. Is the comment area correct? 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. What type of LLM test could this comment become?
|
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.
suggestion: Consider using a more generic contact URL
Using a mailto link directly in the configuration might limit flexibility. Consider using a more generic contact URL that can be updated without changing the configuration.
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.
Is this comment correct?
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.
Is this comment helpful?
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.
Is the comment type correct?
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.
Is the comment area correct?
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.
What type of LLM test could this comment become?