Skip to content

Instantly share code, notes, and snippets.

@silenius
Created March 1, 2018 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save silenius/396a4a1e24c484453654ee654a185343 to your computer and use it in GitHub Desktop.
Save silenius/396a4a1e24c484453654ee654a185343 to your computer and use it in GitHub Desktop.
salt% cat auth_query.sh
psql ${PSQL_ARGS} <<EOF
CREATE OR REPLACE FUNCTION pgbouncer.user_lookup(in i_username text, out uname text, out phash text)
RETURNS record AS $$
BEGIN
SELECT usename, passwd FROM pg_catalog.pg_shadow
WHERE usename = i_username INTO uname, phash;
RETURN;
END;
$$ LANGUAGE plpgsql SECURITY DEFINER;
REVOKE ALL ON FUNCTION pgbouncer.user_lookup(text) FROM public, pgbouncer;
GRANT EXECUTE ON FUNCTION pgbouncer.user_lookup(text) TO pgbouncer;
EOF
salt% cat server.sls
cmd.script:
- source: salt://pgbouncer/files/auth_query.sh
- runas: pgsql
- env:
- PSQL_ARGS: -d {{ k }}
- require:
- postgres_schema: postgresql_database_{{ k }}_pgbouncer_schema
----------
ID: postgresql_database_ifbl_pgbouncer_lookup
Function: cmd.script
Result: True
Comment: Command 'postgresql_database_ifbl_pgbouncer_lookup' run
Started: 17:09:23.953912
Duration: 174.177 ms
Changes:
----------
pid:
79688
retcode:
0
stderr:
ERROR: syntax error at or near "$"
LINE 2: RETURNS record AS $
^
ERROR: syntax error at or near "RETURN"
LINE 1: RETURN;
^
WARNING: there is no transaction in progress
ERROR: syntax error at or near "$"
LINE 1: $ LANGUAGE plpgsql SECURITY DEFINER;
^
ERROR: function pgbouncer.user_lookup(text) does not exist
ERROR: function pgbouncer.user_lookup(text) does not exist
stdout:
COMMIT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment