labtech
Database
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
sp_SecurityTokenCleanup
Description
Clears out old and disabled security tokens
Parameters
Name
Type
Mode
Definition
BEGIN DECLARE customExpirationHours INT DEFAULT 1; -- Attempt to get any token expiration override that an Admin may have set SELECT VALUE FROM properties WHERE NAME = 'CCTokenExpirationHrs' INTO customExpirationHours; IF customExpirationHours < 2 || customExpirationHours > 999 THEN -- If someone tried to set the expire setting to outside the allowed range then fall back on the default of 2 hrs SET customExpirationHours = 2; END IF; -- Add 7 days to the custom token expiration to add a retention buffer SET customExpirationHours = -(customExpirationHours + 168); -- Delete all records that are either a) disabled and issued more than 7 days ago, or b) absolute expiration is older than one week plus whatever the Admin configured CC refresh time limit to be DELETE FROM automate_api_security WHERE (IsEnabled = 0 AND IssuedDate < DATE_ADD(UTC_TIMESTAMP(), INTERVAL -7 DAY)) OR AbsoluteExpirationDate < DATE_ADD(UTC_TIMESTAMP(), INTERVAL customExpirationHours HOUR); END