Drop legacy webhooks

No one is using these in production.
This commit is contained in:
Drew DeVault 2021-09-21 14:48:48 +02:00
parent 3bbdbf08de
commit 48e2e8e288
7 changed files with 25 additions and 36 deletions

View File

@ -177,7 +177,6 @@ func (r *mutationResolver) Create(ctx context.Context, files []*graphql.Upload,
return nil, nil
}
// TODO: Schedule webhooks
return &paste, nil
}

View File

@ -8,7 +8,6 @@ Idempotent. If the tables already exist, they will not be re-created.
"""
import pastesrht.alembic
import pastesrht.types
import pastesrht.webhooks
import srht.alembic

View File

@ -2,7 +2,6 @@ from enum import IntFlag
from flask import abort
from hashlib import sha1
from pastesrht.types import Blob, User, Paste, PasteFile, PasteVisibility
from pastesrht.webhooks import PasteWebhook
from srht.database import db
from srht.oauth import current_user
@ -78,9 +77,6 @@ def paste_drop(paste):
if not pfile:
db.session.delete(blob)
db.session.commit()
PasteWebhook.deliver(PasteWebhook.Events.paste_delete,
{"id": paste.sha},
PasteWebhook.Subscription.user_id == paste.user_id)
class DbLock:
def __init__(self, lock_id, transaction=True):

View File

@ -0,0 +1,25 @@
"""Drop legacy webhooks support
Revision ID: 8565f92ed478
Revises: a9cfba1cedba
Create Date: 2021-09-21 14:48:13.225966
"""
# revision identifiers, used by Alembic.
revision = '8565f92ed478'
down_revision = 'a9cfba1cedba'
from alembic import op
import sqlalchemy as sa
def upgrade():
op.execute("""
DROP TABLE IF EXISTS paste_webhook_delivery;
DROP TABLE IF EXISTS paste_webhook_subscription;
""")
def downgrade():
pass

View File

@ -2,7 +2,6 @@ from flask import Blueprint, abort, request
from hashlib import sha1
from pastesrht.access import get_user_or_abort, has_access, paste_add_file, paste_drop, UserAccess
from pastesrht.types import Paste, Blob, PasteFile, PasteVisibility
from pastesrht.webhooks import PasteWebhook
from srht.api import paginated_response
from srht.database import db
from srht.oauth import oauth, current_token
@ -69,9 +68,6 @@ def pastes_POST():
paste_sha.update(str(current_token.user_id).encode())
paste_sha.update(str(paste.id).encode())
paste.sha = paste_sha.hexdigest()
PasteWebhook.deliver(PasteWebhook.Events.paste_create,
paste.to_dict(),
PasteWebhook.Subscription.user_id == paste.user_id)
db.session.commit()
return paste.to_dict(), 201
@ -119,5 +115,3 @@ def blob_by_id_GET(sha):
if not blob:
abort(404)
return blob.to_dict()
PasteWebhook.api_routes(blueprint=pastes, prefix="/api/pastes")

View File

@ -5,7 +5,6 @@ from hashlib import sha1
from jinja2 import Markup
from pastesrht.access import get_paste_or_abort, get_user_or_abort, has_access, paste_add_file, paste_drop, DbLock, UserAccess
from pastesrht.types import Paste, PasteFile, PasteVisibility, Blob
from pastesrht.webhooks import PasteWebhook
from pastesrht.search import apply_search
from pygments import highlight
from pygments.formatters import HtmlFormatter
@ -52,9 +51,6 @@ def new_paste_POST():
sha.update(f.blob.sha.encode())
sha.update(str(current_user.id).encode())
paste.sha = sha.hexdigest()
PasteWebhook.deliver(PasteWebhook.Events.paste_create,
paste.to_dict(),
PasteWebhook.Subscription.user_id == paste.user_id)
db.session.commit()
return redirect(url_for(".paste_GET",
user=current_user.username, sha=paste.sha))
@ -90,9 +86,6 @@ def new_paste_POST():
paste.sha = sha.hexdigest()
if visibility:
paste.visibility = visibility
PasteWebhook.deliver(PasteWebhook.Events.paste_create,
paste.to_dict(),
PasteWebhook.Subscription.user_id == paste.user_id)
db.session.add(paste)
db.session.commit()
return redirect(url_for(".paste_GET",

View File

@ -1,17 +0,0 @@
from srht.config import cfg
from srht.database import DbSession, db
if not hasattr(db, "session"):
# Initialize the database if not already configured (for running daemon)
db = DbSession(cfg("paste.sr.ht", "connection-string"))
import pastesrht.types
db.init()
from srht.webhook import Event
from srht.webhook.celery import CeleryWebhook, make_worker
worker = make_worker()
class PasteWebhook(CeleryWebhook):
events = [
Event("paste:create", "pastes:read"),
Event("paste:delete", "pastes:read"),
]