mirror of
https://github.com/gravitational/teleport.git
synced 2026-11-03 16:38:35 +08:00
* add AWS RDS MariaDB e2e tests * fix spurious teardown error logs * if a role or user doesn't exist, that is not an error nor is it worth logging during auto user teardown. * check for admin option * add some extra secret fetching checkings * only drop redshift user if the user exists
22 lines
774 B
PL/PgSQL
22 lines
774 B
PL/PgSQL
CREATE OR REPLACE PROCEDURE teleport_delete_user(username varchar, inout state varchar default 'TP003')
|
|
LANGUAGE plpgsql
|
|
AS $$
|
|
DECLARE
|
|
role_ varchar;
|
|
BEGIN
|
|
-- Only drop if the user doesn't have other active sessions.
|
|
IF EXISTS (SELECT usename FROM pg_stat_activity WHERE usename = username) THEN
|
|
RAISE NOTICE 'User has active connections';
|
|
ELSE
|
|
BEGIN
|
|
EXECUTE FORMAT('DROP USER IF EXISTS %I', username);
|
|
EXCEPTION
|
|
WHEN SQLSTATE '2BP01' THEN
|
|
state := 'TP004';
|
|
-- Drop user/role will fail if user has dependent objects.
|
|
-- In this scenario, fallback into disabling the user.
|
|
CALL teleport_deactivate_user(username);
|
|
END;
|
|
END IF;
|
|
END;$$;
|