Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions src/simdb/cli/remote_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ def __init__(

self._api_version = selected_version
self._api_url += f"{selected_version}/"
self.version = Version.coerce(self.get_api_version())
self.version = Version.coerce(selected_version.lstrip("v"))
self.server_version = Version.coerce(self.get_server_version())

def _load_cookies(
Expand Down Expand Up @@ -463,6 +463,32 @@ def get(
check_return(res)
return res

def get_root(
self,
headers: Optional[Dict] = None,
stream: bool = False,
) -> "requests.Response":
"""
Perform an HTTP GET request to the server root endpoint.

@param headers: additional headers to send with the request.
@param stream: True to enable streaming.
@return:
"""

headers = headers or {}
headers["Accept-encoding"] = "gzip"
headers["User-Agent"] = "it_script_basic"

res = requests.get(
self._url,
headers=headers,
cookies=self._cookies,
stream=stream,
)
check_return(res)
return res

def put(self, url: str, data: Dict, **kwargs) -> "requests.Response":
"""
Perform an HTTP PUT request.
Expand Down Expand Up @@ -651,7 +677,7 @@ def get_api_version(self) -> str:
@versioned_method("v1.2", "v1.3")
@try_request
def get_server_version(self) -> str:
res = self.get("", authenticate=False)
res = self.get_root()
data = res.json()
return data["server_version"]

Expand Down
2 changes: 0 additions & 2 deletions src/simdb/remote/apis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from flask import Blueprint, Response, jsonify, request
from flask_restx import Resource

from simdb import __version__
from simdb.database import Database
from simdb.remote.core.auth import AuthenticationError, User, requires_auth
from simdb.remote.core.typing import current_app
Expand Down Expand Up @@ -82,7 +81,6 @@ def get(self):
{
"api": "simdb",
"api_version": api.version,
"server_version": __version__,
"endpoints": [
request.url + "simulations",
request.url + "files",
Expand Down
2 changes: 2 additions & 0 deletions src/simdb/remote/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from flask_compress import Compress
from flask_cors import CORS

from simdb import __version__
from simdb.config import Config
from simdb.database.database import check_migrations, run_migrations

Expand Down Expand Up @@ -57,6 +58,7 @@ def index():
"endpoints": endpoints,
"authentication": authenticators[0].Name,
"authenticators": [auth.Name for auth in authenticators],
"server_version": __version__,
}
)

Expand Down
Loading