Skip to content

Commit

Permalink
Merge pull request #140 from guzman-raphael/flush
Browse files Browse the repository at this point in the history
Allow flushing privileges if admin user is available
  • Loading branch information
jverswijver authored Oct 31, 2022
2 parents 69ef260 + c3b549e commit 4f745c1
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 7 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

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.5.6] - 2022-10-29

### Added

- Add option to flush user privileges if root user available using env vars: `DJ_HOST`, `DJ_ROOT_USER`, `DJ_ROOT_PASS` [#140](https://github.com/datajoint/pharus/pull/140)

## [0.5.5] - 2022-10-26

### Fixed
Expand Down Expand Up @@ -194,6 +200,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.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
[0.5.4]: https://github.com/datajoint/pharus/compare/0.5.3...0.5.4
[0.5.3]: https://github.com/datajoint/pharus/compare/0.5.2...0.5.3
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.5.5 docker-compose -f docker-compose-deploy.yaml up -d
PHARUS_VERSION=0.5.6 docker-compose -f docker-compose-deploy.yaml up -d
To stop the API server, use the command:

.. code-block:: bash
PHARUS_VERSION=0.5.5 docker-compose -f docker-compose-deploy.yaml down
PHARUS_VERSION=0.5.6 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.5.5 docker-compose -f docker-compose-deploy.yaml pull
# PHARUS_VERSION=0.5.5 docker-compose -f docker-compose-deploy.yaml up -d
# PHARUS_VERSION=0.5.6 docker-compose -f docker-compose-deploy.yaml pull
# PHARUS_VERSION=0.5.6 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
22 changes: 20 additions & 2 deletions pharus/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import Callable
from functools import wraps
from typing import Union
import pymysql

# Crypto libaries
from cryptography.hazmat.primitives import serialization as crypto_serialization
Expand Down Expand Up @@ -117,7 +118,7 @@ def api_version() -> str:
Content-Type: application/json
{
"version": "0.5.5"
"version": "0.5.6"
}
:statuscode 200: No error.
Expand Down Expand Up @@ -248,7 +249,24 @@ def login() -> dict:
connect_creds = request.json
if connect_creds.keys() < {"databaseAddress", "username", "password"}:
return dict(error="Invalid Request, check headers and/or json body")
_DJConnector._attempt_login(**connect_creds)
try:
_DJConnector._attempt_login(**connect_creds)
except pymysql.err.OperationalError as e:
if (
(root_host := environ.get("DJ_HOST"))
and (root_user := environ.get("DJ_ROOT_USER"))
and (root_password := environ.get("DJ_ROOT_PASS"))
):
conn = dj.conn(
host=root_host,
user=root_user,
password=root_password,
reset=True,
)
conn.query("FLUSH PRIVILEGES")
_DJConnector._attempt_login(**connect_creds)
else:
raise e
return dict(**auth_info)
except Exception as e:
return str(e), 500
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.5.5"
__version__ = "0.5.6"

0 comments on commit 4f745c1

Please sign in to comment.