-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from cramshaw/develop
Merge develop
- Loading branch information
Showing
6 changed files
with
55 additions
and
32 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ DATABASES = { | |
} | ||
} | ||
``` | ||
|
||
And you've discovered that after ~15 minutes you make a request and receive `Access Denied for user@instance` because the password has expired. | ||
|
||
This package allows you to generate the password at connection time by passing a callable instead: | ||
|
@@ -62,20 +63,21 @@ def generate_pw(): | |
pip install django-mysql-rds | ||
``` | ||
|
||
or | ||
or | ||
|
||
``` | ||
git clone [email protected]:cramshaw/django-mysql-rds.git | ||
``` | ||
|
||
## Why? | ||
|
||
When I searched for a way to connect to an AWS RDS MySQL instance using SSL inside Django, I was unable to find anything that could handle the fact that the db auth token generated by AWS would expire every 15 minutes. | ||
|
||
The problem is that when anything in the settings module changes, Django needs to reload. This isn't practical in a long running web app. I needed a way for the password to be generated at the time of connection. | ||
|
||
## How? | ||
|
||
On close inspection of the `django.db.backends.mysql` code, it became clear that the `DatabaseWrapper.get_connection_params` method takes the settings dict, and transforms it into the kwargs that are passed to `mysql.connect`. I have subclassed this and extended to recognise if the password passed in is a callable, and if so, to call it and pass on the returned value. This leads to | ||
On close inspection of the `django.db.backends.mysql` code, it became clear that the `DatabaseWrapper.get_connection_params` method takes the settings dict, and transforms it into the kwargs that are passed to `mysql.connect`. I have subclassed this and extended to recognise if the password passed in is a callable, and if so, to call it and pass on the returned value. This leads to | ||
Django receiving a fresh password every time a connection is created. | ||
|
||
A very similar thing happens in the `DatabaseClient.settings_to_cmd_args` which is used for things like dumping and loading data. This has also been subclassed and changed to ensure the password generation method actually runs before attempting to create a run a shell. | ||
|
@@ -98,8 +100,9 @@ python -m unittest tests/test* | |
|
||
Bump version in setup.py | ||
then: | ||
|
||
``` | ||
rm -rf dist/ | ||
python3 setup.py sdist bdist_wheel | ||
python3 -m twine upload dist/* | ||
``` | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters