From: Tom Hughes Date: Thu, 8 Aug 2024 19:45:10 +0000 (+0100) Subject: Move token expiry to a rake task X-Git-Tag: live~243^2 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/d17b5b6d4f61f247b8690840d0c3b75490c90657 Move token expiry to a rake task --- diff --git a/lib/tasks/cleanup.rake b/lib/tasks/cleanup.rake new file mode 100644 index 000000000..8c95a1783 --- /dev/null +++ b/lib/tasks/cleanup.rake @@ -0,0 +1,10 @@ +namespace :db do + desc "Expire old tokens" + task :expire_tokens => :environment do + OauthNonce.where("timestamp < EXTRACT(EPOCH FROM NOW() - INTERVAL '1 day')").delete_all + OauthToken.where("invalidated_at < NOW() - INTERVAL '28 days'").delete_all + RequestToken.where("authorized_at IS NULL AND created_at < NOW() - INTERVAL '28 days'").delete_all + Doorkeeper::AccessGrant.where("revoked_at < NOW() - INTERVAL '28 days' OR (created_at + expires_in * INTERVAL '1 second') < NOW() - INTERVAL '28 days'").delete_all + Doorkeeper::AccessToken.where("revoked_at < NOW() - INTERVAL '28 days' OR (created_at + expires_in * INTERVAL '1 second') < NOW() - INTERVAL '28 days'").delete_all + end +end diff --git a/script/cleanup b/script/cleanup deleted file mode 100755 index e829be176..000000000 --- a/script/cleanup +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env ruby - -require File.join(File.dirname(__FILE__), "..", "config", "environment") - -OauthNonce.where("timestamp < EXTRACT(EPOCH FROM NOW() - INTERVAL '1 day')").delete_all -OauthToken.where("invalidated_at < NOW() - INTERVAL '28 days'").delete_all -RequestToken.where("authorized_at IS NULL AND created_at < NOW() - INTERVAL '28 days'").delete_all - -Doorkeeper::AccessGrant.where("revoked_at < NOW() - INTERVAL '28 days' OR (created_at + expires_in * INTERVAL '1 second') < NOW() - INTERVAL '28 days'").delete_all -Doorkeeper::AccessToken.where("revoked_at < NOW() - INTERVAL '28 days' OR (created_at + expires_in * INTERVAL '1 second') < NOW() - INTERVAL '28 days'").delete_all - -exit 0