LinuxForHealth / FHIR

The LinuxForHealth FHIR® Server and related projects

Home Page:https://linuxforhealth.github.io/FHIR

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Schematool does not accept `-` in usernames

bauerjs1 opened this issue · comments

Describe the bug
When there are dashes (-) in the Postgres username, the schematool fails with the following exception:

Running create-schemas task
2023-03-02 10:01:21.542 00000001    INFO forhealth.fhir.schema.app.Main Opening connection to: jdbc:postgresql://pg-albatross.databases:5432/polar_fhir_ibm
2023-03-02 10:01:22.186 00000001    INFO utils.postgres.PostgresAdapter The schema 'FHIR_ADMIN' is created or already exists
2023-03-02 10:01:22.189 00000001    INFO utils.postgres.PostgresAdapter The schema 'FHIRDATA' is created or already exists
2023-03-02 10:01:22.193 00000001    INFO utils.postgres.PostgresAdapter The schema 'FHIR_OAUTH' is created or already exists
2023-03-02 10:01:22.197 00000001    INFO utils.postgres.PostgresAdapter The schema 'FHIR_JBATCH' is created or already exists
2023-03-02 10:01:22.202 00000001    INFO forhealth.fhir.schema.app.Main Processing took:   0.673 s
2023-03-02 10:01:22.203 00000001    INFO forhealth.fhir.schema.app.Main SCHEMA CHANGE: OK
Running update-schema task
2023-03-02 10:01:22.934 00000001  SEVERE forhealth.fhir.schema.app.Main bad argument

Invalid SQL object name: 'my-user'
java.lang.IllegalArgumentException: Invalid SQL object name: 'my-user'
	at org.linuxforhealth.fhir.database.utils.common.DataDefinitionUtil.assertValidName(DataDefinitionUtil.java:152)
	at org.linuxforhealth.fhir.schema.app.Main.parseArgs(Main.java:1180)
	at org.linuxforhealth.fhir.schema.app.Main.main(Main.java:2006)
Usage: 
[...]
2023-03-02 10:01:23.062 00000001  SEVERE forhealth.fhir.schema.app.Main SCHEMA CHANGE: BAD ARGS

Names seem to be verified against this pattern.

Environment
Helm chart lfh-helm/fhir-server:0.9.1 using ghcr.io/linuxforhealth/fhir-schematool:5.1.1

To Reproduce
Execute in schematool container:

/opt/java/openjdk/bin/java -jar /opt/schematool/fhir-persistence-schema-*-cli.jar \
              --db-type postgresql \
              --prop db.host=${FHIR_DB_HOSTNAME} \
              --prop db.port=${FHIR_DB_PORT} \
              --prop db.database=${FHIR_DB_NAME} \
              --prop user=some-username-with-dashes-in-it \
              --prop password=${FHIR_DB_ADMIN_PASSWORD} \
              --schema-name fhirdata \
              --update-schema \
              --grant-to ${FHIR_DB_USER}

Expected behavior
The schematool should be able to connect to the database as usual.

Additional context
We are using Crunchy Postgres for Kubernetes to manage our databases. The operator cannot use _ in usernames, since it creates secrets containing them in their names (Kubernetes resource names must be DNS subdomain conformant). AFAIK, - in Postgres usernames are legal.

thanks for your patience, your PR is now merged and will be in the next release

Very nice, thank you!