Skip to content

Commit

Permalink
Check minimal server version
Browse files Browse the repository at this point in the history
  • Loading branch information
robertdstein committed Feb 4, 2024
1 parent 305b06f commit 9237a60
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "winterapi"
version = "0.3.0"
version = "1.0.0"
description = ""
authors = [
{name = "Robert Stein", email = "[email protected]"}
Expand All @@ -29,6 +29,7 @@ classifiers = [
]
dependencies = [
"pandas",
"packaging",
"keyring",
"cryptography",
"pre-commit",
Expand Down
1 change: 1 addition & 0 deletions winterapi/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
run_local = os.getenv("WINTER_API_LOCAL", "0") in ["True", "true", "1"]
BASE_URL = "http://127.0.0.1:7000" if run_local else "http://winter.caltech.edu:82"
PING_URL = BASE_URL + "/ping"
VERSION_URL = BASE_URL + "/validation/version"
USER_URL = BASE_URL + "/validation/user"
PROGRAM_URL = BASE_URL + "/validation/program"
WINTER_TOO_URL = BASE_URL + "/too/winter"
Expand Down
31 changes: 30 additions & 1 deletion winterapi/messenger.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

import getpass
import logging
from importlib import metadata
from typing import Optional

import pandas as pd
import requests
from astropy import units as u
from astropy.time import Time
from packaging import version
from wintertoo.models import (
DEFAULT_IMAGE_TYPE,
ConeImageQuery,
Expand Down Expand Up @@ -42,6 +44,7 @@
SCHEDULE_SUMMARY_URL,
SUMMER_TOO_URL,
USER_URL,
VERSION_URL,
WINTER_TOO_URL,
)
from winterapi.fidelius import Fidelius
Expand All @@ -56,8 +59,12 @@ class WinterAPI(BaseAPI):

def __init__(self):
self.fidelius = Fidelius()
logger.info(f"API ping success is {self.ping()}")
ping = self.ping()
if not ping:
logger.warning("Could not successfully ping server")
logger.info(f"API ping success is {ping}")
self.auth = (None, None)
self.check_version()

@staticmethod
def ping():
Expand All @@ -73,6 +80,28 @@ def ping():
except requests.exceptions.ConnectionError:
return False

@staticmethod
def check_version():
"""
Check the version of the API.
:return: API response
"""
res = requests.get(VERSION_URL, timeout=MAX_TIMEOUT)
if res.status_code == 200:
server_version = version.parse(res.json()["body"])
local_version = version.parse(metadata.version("winterapi"))
logger.info(f"Server requires minimum winterapi version: {server_version}")
logger.info(f"Local winterapi version: {local_version}")
if server_version > local_version:
logger.warning(
f"Local winterapi version ({local_version}) is out of date! "
f"Server requires a minimum of {server_version}. "
f"Please update winterapi."
)
else:
logger.warning("Could not check minimum version of winterapi for server")

@staticmethod
def clear_cache():
"""
Expand Down

0 comments on commit 9237a60

Please sign in to comment.