Skip to content

Commit 35234ae

Browse files
authored
Merge pull request #144 from datajoint/fix-instant-token
Use a manual sleep due to instant token issue from jwt
2 parents a9b2d8f + 847d530 commit 35234ae

File tree

5 files changed

+28
-17
lines changed

5 files changed

+28
-17
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

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

5+
## [0.6.1] - 2022-11-04
6+
7+
### Added
8+
9+
- Add debug traces for standard routes [#143](https://github.com/datajoint/pharus/pull/143)
10+
- 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)
11+
512
## [0.6.0] - 2022-11-03
613

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

217+
[0.6.1]: https://github.com/datajoint/pharus/compare/0.6.0...0.6.1
210218
[0.6.0]: https://github.com/datajoint/pharus/compare/0.5.6...0.6.0
211219
[0.5.6]: https://github.com/datajoint/pharus/compare/0.5.5...0.5.6
212220
[0.5.5]: https://github.com/datajoint/pharus/compare/0.5.4...0.5.5

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ To start the API server, use the command:
2929

3030
.. code-block:: bash
3131
32-
PHARUS_VERSION=0.6.0 docker-compose -f docker-compose-deploy.yaml up -d
32+
PHARUS_VERSION=0.6.1 docker-compose -f docker-compose-deploy.yaml up -d
3333
3434
To stop the API server, use the command:
3535

3636
.. code-block:: bash
3737
38-
PHARUS_VERSION=0.6.0 docker-compose -f docker-compose-deploy.yaml down
38+
PHARUS_VERSION=0.6.1 docker-compose -f docker-compose-deploy.yaml down
3939
4040
References
4141
----------

docker-compose-deploy.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# PHARUS_VERSION=0.6.0 docker-compose -f docker-compose-deploy.yaml pull
2-
# PHARUS_VERSION=0.6.0 docker-compose -f docker-compose-deploy.yaml up -d
1+
# PHARUS_VERSION=0.6.1 docker-compose -f docker-compose-deploy.yaml pull
2+
# PHARUS_VERSION=0.6.1 docker-compose -f docker-compose-deploy.yaml up -d
33
#
44
# Intended for production deployment.
55
# Note: You must run both commands above for minimal outage

pharus/server.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
from datajoint.errors import IntegrityError
2323
from datajoint.table import foreign_key_error_regexp
2424
from datajoint.utils import to_camel_case
25+
import traceback
26+
import time
2527

2628
app = Flask(__name__)
2729
# Check if PRIVATE_KEY and PUBIC_KEY is set, if not generate them.
@@ -124,7 +126,7 @@ def api_version() -> str:
124126
Content-Type: application/json
125127
126128
{
127-
"version": "0.6.0"
129+
"version": "0.6.1"
128130
}
129131
130132
:statuscode 200: No error.
@@ -233,6 +235,7 @@ def login() -> dict:
233235
auth_info = dict(
234236
jwt=result.json()["access_token"], id=result.json()["id_token"]
235237
)
238+
time.sleep(1)
236239
connect_creds = {
237240
"databaseAddress": request.args["database_host"],
238241
"username": jwt.decode(
@@ -281,7 +284,7 @@ def login() -> dict:
281284
raise e
282285
return dict(**auth_info)
283286
except Exception as e:
284-
return str(e), 500
287+
return traceback.format_exc(), 500
285288

286289

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

348351

349352
@app.route(
@@ -420,7 +423,7 @@ def table(
420423
tables_dict_list = _DJConnector._list_tables(connection, schema_name)
421424
return dict(tableTypes=tables_dict_list)
422425
except Exception as e:
423-
return str(e), 500
426+
return traceback.format_exc(), 500
424427

425428

426429
@app.route(
@@ -742,23 +745,23 @@ def record(
742745
recordHeader=record_header, records=table_tuples, totalCount=total_count
743746
)
744747
except Exception as e:
745-
return str(e), 500
748+
return traceback.format_exc(), 500
746749
elif request.method == "POST":
747750
try:
748751
_DJConnector._insert_tuple(
749752
connection, schema_name, table_name, request.json["records"]
750753
)
751754
return "Insert Successful"
752755
except Exception as e:
753-
return str(e), 500
756+
return traceback.format_exc(), 500
754757
elif request.method == "PATCH":
755758
try:
756759
_DJConnector._update_tuple(
757760
connection, schema_name, table_name, request.json["records"]
758761
)
759762
return "Update Successful"
760763
except Exception as e:
761-
return str(e), 500
764+
return traceback.format_exc(), 500
762765
elif request.method == "DELETE":
763766
try:
764767
_DJConnector._delete_records(
@@ -789,7 +792,7 @@ def record(
789792
409,
790793
)
791794
except Exception as e:
792-
return str(e), 500
795+
return traceback.format_exc(), 500
793796

794797

795798
@app.route(
@@ -872,7 +875,7 @@ def definition(
872875
)
873876
return table_definition
874877
except Exception as e:
875-
return str(e), 500
878+
return traceback.format_exc(), 500
876879

877880

878881
@app.route(
@@ -1051,7 +1054,7 @@ def attribute(
10511054
attributes=attributes_meta["attributes"],
10521055
)
10531056
except Exception as e:
1054-
return str(e), 500
1057+
return traceback.format_exc(), 500
10551058

10561059

10571060
@app.route(
@@ -1158,14 +1161,14 @@ def dependency(
11581161
)
11591162
return dict(dependencies=dependencies)
11601163
except Exception as e:
1161-
return str(e), 500
1164+
return traceback.format_exc(), 500
11621165

11631166

11641167
def run():
11651168
"""
11661169
Starts API server.
11671170
"""
1168-
app.run(host="0.0.0.0", port=environ.get("PHARUS_PORT", 5000), threaded=True)
1171+
app.run(host="0.0.0.0", port=environ.get("PHARUS_PORT", 5000), threaded=False)
11691172

11701173

11711174
if __name__ == "__main__":

pharus/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
"""Package metadata."""
2-
__version__ = "0.6.0"
2+
__version__ = "0.6.1"

0 commit comments

Comments
 (0)