#security #token #cron-job #password

bin+lib permesi-genesis

Token Zero generator for permesi

15 releases

new 0.1.14 Dec 10, 2024
0.1.13 Dec 2, 2024
0.1.12 Nov 24, 2024
0.1.10 Sep 3, 2024
0.1.3 Jan 31, 2024

#182 in HTTP server

Download history 144/week @ 2024-08-26 173/week @ 2024-09-02 41/week @ 2024-09-16 8/week @ 2024-09-23 7/week @ 2024-09-30 142/week @ 2024-11-18 120/week @ 2024-11-25 164/week @ 2024-12-02

426 downloads per month

BSD-3-Clause

60KB
1K SLoC

genesis

Deploy Test & Build codecov

Token Zero generator

Why Ulid?

Helps find(group) tokens for the same period of time but still unique.

> select id, id::timestamp from tokens;
+----------------------------+-------------------------+
| id                         | id                      |
|----------------------------+-------------------------|
| 01HQAS6A6SGD3Z1V7VF86Q0B6P | 2024-02-23 10:46:47.769 |
| 01HQAS6A6SV2A93NMKH0S03CD1 | 2024-02-23 10:46:47.769 |
| 01HQAS6A6S8ZRMC0RZP8DEQ1Q5 | 2024-02-23 10:46:47.769 |
| 01HQAS6A6S1Q8TT1E8XE1J7JS8 | 2024-02-23 10:46:47.769 |
+----------------------------+-------------------------+

Expire tokens by time using pg_cron

SELECT cron.schedule('*/30 * * * *', $$DELETE
FROM tokens
WHERE id::timestamp < NOW() - INTERVAL '120 seconds'$$);

Update the database of the cron job with the following SQL command:

UPDATE cron.job SET database='genesis' WHERE jobid=5;

Check the cron.job table with the following SQL command:

SELECT * FROM cron.job;
+-------+--------------+------------------------------------------------------+-----------+----------+----------+----------+--------+---------+
| jobid | schedule     | command                                              | nodename  | nodeport | database | username | active | jobname |
|-------+--------------+------------------------------------------------------+-----------+----------+----------+----------+--------+---------|
| 2     | 0 0 * * *    | DELETE                                               | localhost | 5432     | postgres | postgres | True   | <null>  |
|       |              |     FROM cron.job_run_details                        |           |          |          |          |        |         |
|       |              |     WHERE end_time < now() - interval '7 days'       |           |          |          |          |        |         |
| 5     | */30 * * * * | DELETE                                               | localhost | 5432     | genesis  | postgres | True   | <null>  |
|       |              | FROM tokens                                          |           |          |          |          |        |         |
|       |              | WHERE id::timestamp < NOW() - INTERVAL '120 seconds' |           |          |          |          |        |         |
+-------+--------------+------------------------------------------------------+-----------+----------+----------+----------+--------+---------+

Check the status of the cron job with the following SQL command:

SELECT * FROM cron.job_run_details order by start_time DESC limit 5;

Dependencies

~76MB
~1.5M SLoC