Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(frontend): support special chars in postgresql client [#1775] #1818

Merged
merged 1 commit into from
Jul 10, 2023

Conversation

mrl5
Copy link
Contributor

@mrl5 mrl5 commented Jul 9, 2023

Fix #1775

tested with:

  1. setup fresh postgres15.3 container with POSTGRES_PASSWORD kot@behemot#zonk
  2. get DB URI with
const args = { user: 'postgres', password: 'kot@behemot#zonk', host: '0.0.0.0', dbname: 'postgres', sslmode: 'disable' };
const u = new URL(`postgres://${args.user}:${args.password}@${args.host}:${args.port ?? 5432}/${args.dbname}?sslmode=${args.sslmode}`);
u.hash = '';
u.search = `?sslmode=${args.sslmode}`;
u.pathname = args.dbname;
u.host = args.host;
u.password = args.password;
u.username = args.user;

u.toString();
  1. connect to db
psql 'postgres://postgres:kot%40behemot%23zonk@0.0.0.0/postgres?sslmode=disable'

@mrl5 mrl5 changed the title fix(frontend): support special chars in postgresql client fix(frontend): support special chars in postgresql client [#1775] Jul 9, 2023
@mrl5
Copy link
Contributor Author

mrl5 commented Jul 9, 2023

I also checked if there is something similar for mysql or mongo but didn't found anything similar to modified code

@rubenfiszel
Copy link
Contributor

Thanks for the PR, I just reworked that part and the change need to be applied to TestConnection.svelte

Side-note: I'm working on adding mysql as a first class language too :)

@@ -19,7 +19,14 @@
content: `
import { Client } from 'https://deno.land/x/postgres/mod.ts'
export async function main(args: any) {
const client = new Client("postgres://" + args.user + ":" + args.password + "@" + args.host + ":" + (args.port ?? 5432) + "/" + args.dbname + "?sslmode=" + args.sslmode)
const u = new URL(`postgres://${args.user}:${args.password}@${args.host}:${args.port ?? 5432}/${args.dbname}?sslmode=${args.sslmode}`)
Copy link
Contributor Author

@mrl5 mrl5 Jul 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if there's anything that's stopping us with using ClientOptions here?

The only reason that I came up with was some backwards compatibility with args interface. Simple adapter like this could work:

-import { Client } from 'https://deno.land/x/postgres/mod.ts'
+import { Client, ClientOptions } from 'https://deno.land/x/postgres/mod.ts';
 export async function main(args: any) {
-       const client = new Client("postgres://" + args.user + ":" + args.password + "@" + args.host + ":" + (args.port ?? 5432) + "/" + args.dbname + "?sslmode=" + args.sslmode)
+       const clientOptions: ClientOptions = {
+               database: args.dbname,
+               port: args.port ?? 5432,
+               hostname: args.host,
+               password: args.password,
+               user: args.user,
+       };
+       const client = new Client(clientOptions)
        await client.connect()
        return 'Connection successful'
 }

however there would be issues with mapping TLSOptions to psql sslmode - notice lack of args.sslmode in proposed adapter

@rubenfiszel rubenfiszel merged commit 9e385d9 into windmill-labs:main Jul 10, 2023
2 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jul 10, 2023
@mrl5 mrl5 deleted the issue-1775 branch July 10, 2023 20:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

bug: special characters in postgresql password cause resource to fail
2 participants