From b41a2a9f45ef9e4dee16199d5bee9e0d1b5efc2f Mon Sep 17 00:00:00 2001 From: WrenIX Date: Tue, 13 Feb 2024 19:47:19 +0100 Subject: [PATCH] fix(postgresql): init job correct quote --- postgresql/Chart.yaml | 2 +- postgresql/README.adoc | 2 +- postgresql/ci/ct-values.yaml | 8 ++++++++ postgresql/files/10-init-user.sh | 8 ++++---- postgresql/files/20-init-db.sh | 10 +++++----- 5 files changed, 19 insertions(+), 11 deletions(-) create mode 100644 postgresql/ci/ct-values.yaml diff --git a/postgresql/Chart.yaml b/postgresql/Chart.yaml index 9aff055..42b3ea2 100644 --- a/postgresql/Chart.yaml +++ b/postgresql/Chart.yaml @@ -4,7 +4,7 @@ name: "postgresql" description: "A Helm chart for running PostgreSQL (Postgres) database" icon: https://wiki.postgresql.org/images/a/a4/PostgreSQL_logo.3colors.svg type: "application" -version: "0.1.6" +version: "0.1.7" # renovate: image=docker.io/library/postgres appVersion: "16.1-alpine" maintainers: diff --git a/postgresql/README.adoc b/postgresql/README.adoc index 2573de8..9039646 100644 --- a/postgresql/README.adoc +++ b/postgresql/README.adoc @@ -2,7 +2,7 @@ = postgresql -image::https://img.shields.io/badge/Version-0.1.6-informational?style=flat-square[Version: 0.1.6] +image::https://img.shields.io/badge/Version-0.1.7-informational?style=flat-square[Version: 0.1.7] image::https://img.shields.io/badge/Version-application-informational?style=flat-square[Type: application] image::https://img.shields.io/badge/AppVersion-16.1-alpine-informational?style=flat-square[AppVersion: 16.1-alpine] == Maintainers diff --git a/postgresql/ci/ct-values.yaml b/postgresql/ci/ct-values.yaml new file mode 100644 index 0000000..26e5e8e --- /dev/null +++ b/postgresql/ci/ct-values.yaml @@ -0,0 +1,8 @@ +job: + users: + user-name: "RandomPassword0#" + + databases: + "name_of_database": + owner: "existing_user_which_will_get_grant" + additionalParams: "" diff --git a/postgresql/files/10-init-user.sh b/postgresql/files/10-init-user.sh index 3a87be2..504d377 100644 --- a/postgresql/files/10-init-user.sh +++ b/postgresql/files/10-init-user.sh @@ -1,10 +1,10 @@ {{- range $username, $password := .Values.job.users }} -echo 'user "{{ $username }}":' -psql -tc "SELECT 1 FROM pg_user WHERE usename = '{{ $username }}'" | grep -q 1; +echo 'user {{ $username | quote }}:' +psql -tc "SELECT 1 FROM pg_user WHERE usename = {{ $username | squote }}" | grep -q 1; if [ $? -ne 0 ]; then - psql -c "CREATE USER {{ $username }} WITH ENCRYPTED PASSWORD '{{ $password }}'"; + psql -c "CREATE USER \"{{ $username }}\" WITH ENCRYPTED PASSWORD {{ $password | squote }}"; else - psql -c "ALTER USER {{ $username }} WITH ENCRYPTED PASSWORD '{{ $password }}'"; + psql -c "ALTER USER \"{{ $username }}\" WITH ENCRYPTED PASSWORD {{ $password | squote }}"; fi echo "" {{- end }} diff --git a/postgresql/files/20-init-db.sh b/postgresql/files/20-init-db.sh index 5dec00e..de42b09 100644 --- a/postgresql/files/20-init-db.sh +++ b/postgresql/files/20-init-db.sh @@ -1,10 +1,10 @@ {{- range $name, $config := .Values.job.databases }} -echo 'database "{{ $name }}":' -psql -tc "SELECT 1 FROM pg_database WHERE datname = '{{ $name }}'" | grep -q 1 +echo 'database {{ $name | quote }}:' +psql -tc "SELECT 1 FROM pg_database WHERE datname = {{ $name | squote }}" | grep -q 1 if [ $? -ne 0 ]; then - psql -c "CREATE DATABASE {{ $name }} {{ with $config.additionalParams }}{{ . }} {{ end }}"; + psql -c 'CREATE DATABASE {{ $name | quote }} {{ with $config.additionalParams }}{{ . }} {{ end }}'; fi -psql -c "ALTER DATABASE {{ $name }} OWNER TO {{ $config.owner }}"; -psql -c "GRANT ALL PRIVILEGES ON DATABASE {{ $name }} TO {{ $config.owner }}"; +psql -c 'ALTER DATABASE {{ $name | quote }} OWNER TO {{ $config.owner | quote }}'; +psql -c 'GRANT ALL PRIVILEGES ON DATABASE {{ $name | quote }} TO {{ $config.owner | quote }}'; echo "" {{- end }}