Skip to content

Commit

Permalink
add endpoint for job wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
bisgaard-itis committed Oct 10, 2023
1 parent d0bbb78 commit 9f363ca
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from fastapi.responses import RedirectResponse
from fastapi_pagination.api import create_page
from models_library.api_schemas_webserver.projects import ProjectCreateNew, ProjectGet
from models_library.api_schemas_webserver.wallets import WalletGet
from models_library.clusters import ClusterID
from models_library.projects_nodes_io import BaseFileLink
from pydantic.types import PositiveInt
Expand Down Expand Up @@ -533,3 +534,28 @@ async def replace_job_custom_metadata(
f"Cannot find job={job_name} ",
status_code=status.HTTP_404_NOT_FOUND,
)


@router.get(
"/{solver_key:path}/releases/{version}/jobs/{job_id:uuid}/wallet",
response_model=WalletGet,
responses={**_COMMON_ERROR_RESPONSES},
include_in_schema=API_SERVER_DEV_FEATURES_ENABLED,
)
async def get_job_wallet(
solver_key: SolverKeyId,
version: VersionStr,
job_id: JobID,
webserver_api: Annotated[AuthSession, Depends(get_webserver_session)],
):
job_name = _compose_job_resource_name(solver_key, version, job_id)
_logger.debug("Getting wallet for job '%s'", job_name)

try:
return await webserver_api.get_project_wallet(project_id=job_id)

except ProjectNotFoundError:
return create_error_json_response(
f"Cannot find job={job_name} to delete",
status_code=status.HTTP_404_NOT_FOUND,
)
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
ProjectMetadataGet,
ProjectMetadataUpdate,
)
from models_library.api_schemas_webserver.wallets import WalletGet
from models_library.generics import Envelope
from models_library.projects import ProjectID
from models_library.rest_pagination import Page
Expand Down Expand Up @@ -368,6 +369,17 @@ async def update_project_metadata(
assert data # nosec
return data

async def get_project_wallet(self, project_id: ProjectID) -> WalletGet:
with _handle_webserver_api_errors():
response = await self.client.patch(
f"/projects/{project_id}/wallet",
cookies=self.session_cookies,
)
response.raise_for_status()
data = Envelope[WalletGet].parse_raw(response.text).data
assert data # nosec
return data


# MODULES APP SETUP -------------------------------------------------------------

Expand Down

0 comments on commit 9f363ca

Please sign in to comment.