kheeklab / privacyidea-docker

This is a build environment to build a docker image for privacyIDEA based on official Python image and PrivacyIDEA.
MIT License
35 stars 20 forks source link

Muti-node DB configuration #141

Closed gitalexch closed 4 months ago

gitalexch commented 4 months ago

Is your feature request related to a problem? Please describe. There is no possibility to provide multi-node DB configuraation into Docker image Describe the solution you'd like Something like coma separate values in PI_DB_HOST and DP_PORT(auto-added by host count ) AND something like PI_DB_ARGS for additional arguments like: &target_session_attrs=primary&keepalives=1&keepalives_idle=30&keepalives_interval=10&keepalives_count=3 The full SQL connection line should look like: postgresql+psycopg2://user:password@/dbname?host=HostA,HostB,HostC&port=PortA,,PortC&target_session_attrs=primary&keepalives=1&keepalives_idle=30&keepalives_interval=10&keepalives_count=3

Documentation available here: https://docs.sqlalchemy.org/en/20/dialects/postgresql.html#specifying-multiple-fallback-hosts

Describe alternatives you've considered Full SQLALCHEMY_DATABASE_URI аз variable

Additional context Seems that it should be easy to add this feature

mr-ssd commented 4 months ago

@gitalexch thank you for the idea.

Seems that it should be easy to add this feature

yeah, that's an easy task and if you already have coded this please don't hesitate to file a PR

mr-ssd commented 4 months ago

TODO:

gitalexch commented 4 months ago

Have made a PR but I am not very strong in programming.

gitalexch commented 4 months ago

Need to be reviewed and tested: https://github.com/Khalibre/privacyidea-docker/pull/142 Usage example: for PG: PI_DB_HOST="host1, host2, host3" PI_DB_PORT="5432, , " PI_DB_ARGS="target_session_attrs=primary, keepalives=1, keepalives_idle=30, keepalives_interval=10, keepalives_count=3"

for MySQL/MariaDB: PI_DB_ARGS="ssl_check_hostname=false"

OR just full connection string, like: SQLALCHEMY_DATABASE_URI="oracle+cx_oracle://user:pass@hostname:port[/dbname][?service_name=[&key=value&key=value...]]"

mr-ssd commented 4 months ago

@gitalexch thank you for the PR.

gitalexch commented 4 months ago

I think backport to current 3.9.x tag is needed.... And if you omit port in PG sql connection query the connection would processed to default port, but in case of multiple nodes you always need correct coma count, so my IDEA of replacing PI_DB_HOST with comas seems to be useful &port=${PI_DB_PORT:-${PI_DB_HOST//[!,]/}} and I think you should add space striping into check_and_clean_vars() function something like: var_value=${var_value// /} @mr-ssd

mr-ssd commented 4 months ago

@gitalexch thank for your feedback. I'll check these.