cartodb-postgresql/test/CDB_Username.sql

23 lines
731 B
MySQL
Raw Permalink Normal View History

SELECT session_user; -- postgres
2019-02-20 17:38:00 +08:00
SELECT CDB_Username(); -- (NULL)
-- Add the role fulano with api_key and connect with it
2019-02-20 17:38:00 +08:00
\set QUIET on
2019-02-20 20:34:11 +08:00
CREATE ROLE fulano LOGIN;
GRANT USAGE ON SCHEMA cartodb TO fulano;
GRANT EXECUTE ON FUNCTION CDB_Username() TO fulano;
INSERT INTO cdb_conf (key, value) VALUES ('api_keys_fulano', '{"username": "fulanito", "permissions":[]}');
SET SESSION AUTHORIZATION fulano;
2019-02-20 17:38:00 +08:00
\set QUIET off
SELECT session_user; -- fulano
2019-02-20 20:34:11 +08:00
SELECT CDB_Username(); -- fulanito
-- Remove fulano
\set QUIET on
SET SESSION AUTHORIZATION postgres;
2019-02-20 20:34:11 +08:00
REVOKE USAGE ON SCHEMA cartodb FROM fulano;
REVOKE EXECUTE ON FUNCTION CDB_Username() FROM fulano;
DROP ROLE fulano;
2019-03-08 19:03:55 +08:00
DELETE FROM cdb_conf WHERE key = 'api_keys_fulano';
\set QUIET off