Skip to content

Commit

Permalink
Merge pull request #144 from datajoint/fix-instant-token
Browse files Browse the repository at this point in the history
Use a manual sleep due to instant token issue from jwt
  • Loading branch information
yambottle authored Nov 4, 2022
2 parents a9b2d8f + 847d530 commit 35234ae
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 17 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

Observes [Semantic Versioning](https://semver.org/spec/v2.0.0.html) standard and [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) convention.

## [0.6.1] - 2022-11-04

### Added

- Add debug traces for standard routes [#143](https://github.com/datajoint/pharus/pull/143)
- Set a manual sleep due to `jwt` package not validating tokens issued in less than 1 sec [#143](https://github.com/datajoint/pharus/pull/143)

## [0.6.0] - 2022-11-03

### Added
Expand Down Expand Up @@ -207,6 +214,7 @@ Observes [Semantic Versioning](https://semver.org/spec/v2.0.0.html) standard and
- Support for DataJoint attribute types: `varchar`, `int`, `float`, `datetime`, `date`, `time`, `decimal`, `uuid`.
- Check dependency utility to determine child table references.

[0.6.1]: https://github.com/datajoint/pharus/compare/0.6.0...0.6.1
[0.6.0]: https://github.com/datajoint/pharus/compare/0.5.6...0.6.0
[0.5.6]: https://github.com/datajoint/pharus/compare/0.5.5...0.5.6
[0.5.5]: https://github.com/datajoint/pharus/compare/0.5.4...0.5.5
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ To start the API server, use the command:

.. code-block:: bash
PHARUS_VERSION=0.6.0 docker-compose -f docker-compose-deploy.yaml up -d
PHARUS_VERSION=0.6.1 docker-compose -f docker-compose-deploy.yaml up -d
To stop the API server, use the command:

.. code-block:: bash
PHARUS_VERSION=0.6.0 docker-compose -f docker-compose-deploy.yaml down
PHARUS_VERSION=0.6.1 docker-compose -f docker-compose-deploy.yaml down
References
----------
Expand Down
4 changes: 2 additions & 2 deletions docker-compose-deploy.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# PHARUS_VERSION=0.6.0 docker-compose -f docker-compose-deploy.yaml pull
# PHARUS_VERSION=0.6.0 docker-compose -f docker-compose-deploy.yaml up -d
# PHARUS_VERSION=0.6.1 docker-compose -f docker-compose-deploy.yaml pull
# PHARUS_VERSION=0.6.1 docker-compose -f docker-compose-deploy.yaml up -d
#
# Intended for production deployment.
# Note: You must run both commands above for minimal outage
Expand Down
27 changes: 15 additions & 12 deletions pharus/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
from datajoint.errors import IntegrityError
from datajoint.table import foreign_key_error_regexp
from datajoint.utils import to_camel_case
import traceback
import time

app = Flask(__name__)
# Check if PRIVATE_KEY and PUBIC_KEY is set, if not generate them.
Expand Down Expand Up @@ -124,7 +126,7 @@ def api_version() -> str:
Content-Type: application/json
{
"version": "0.6.0"
"version": "0.6.1"
}
:statuscode 200: No error.
Expand Down Expand Up @@ -233,6 +235,7 @@ def login() -> dict:
auth_info = dict(
jwt=result.json()["access_token"], id=result.json()["id_token"]
)
time.sleep(1)
connect_creds = {
"databaseAddress": request.args["database_host"],
"username": jwt.decode(
Expand Down Expand Up @@ -281,7 +284,7 @@ def login() -> dict:
raise e
return dict(**auth_info)
except Exception as e:
return str(e), 500
return traceback.format_exc(), 500


@app.route(f"{environ.get('PHARUS_PREFIX', '')}/schema", methods=["GET"])
Expand Down Expand Up @@ -343,7 +346,7 @@ def schema(connection: dj.Connection) -> dict:
schemas_name = _DJConnector._list_schemas(connection)
return dict(schemaNames=schemas_name)
except Exception as e:
return str(e), 500
return traceback.format_exc(), 500


@app.route(
Expand Down Expand Up @@ -420,7 +423,7 @@ def table(
tables_dict_list = _DJConnector._list_tables(connection, schema_name)
return dict(tableTypes=tables_dict_list)
except Exception as e:
return str(e), 500
return traceback.format_exc(), 500


@app.route(
Expand Down Expand Up @@ -742,23 +745,23 @@ def record(
recordHeader=record_header, records=table_tuples, totalCount=total_count
)
except Exception as e:
return str(e), 500
return traceback.format_exc(), 500
elif request.method == "POST":
try:
_DJConnector._insert_tuple(
connection, schema_name, table_name, request.json["records"]
)
return "Insert Successful"
except Exception as e:
return str(e), 500
return traceback.format_exc(), 500
elif request.method == "PATCH":
try:
_DJConnector._update_tuple(
connection, schema_name, table_name, request.json["records"]
)
return "Update Successful"
except Exception as e:
return str(e), 500
return traceback.format_exc(), 500
elif request.method == "DELETE":
try:
_DJConnector._delete_records(
Expand Down Expand Up @@ -789,7 +792,7 @@ def record(
409,
)
except Exception as e:
return str(e), 500
return traceback.format_exc(), 500


@app.route(
Expand Down Expand Up @@ -872,7 +875,7 @@ def definition(
)
return table_definition
except Exception as e:
return str(e), 500
return traceback.format_exc(), 500


@app.route(
Expand Down Expand Up @@ -1051,7 +1054,7 @@ def attribute(
attributes=attributes_meta["attributes"],
)
except Exception as e:
return str(e), 500
return traceback.format_exc(), 500


@app.route(
Expand Down Expand Up @@ -1158,14 +1161,14 @@ def dependency(
)
return dict(dependencies=dependencies)
except Exception as e:
return str(e), 500
return traceback.format_exc(), 500


def run():
"""
Starts API server.
"""
app.run(host="0.0.0.0", port=environ.get("PHARUS_PORT", 5000), threaded=True)
app.run(host="0.0.0.0", port=environ.get("PHARUS_PORT", 5000), threaded=False)


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion pharus/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""Package metadata."""
__version__ = "0.6.0"
__version__ = "0.6.1"

0 comments on commit 35234ae

Please sign in to comment.