~sircmpwn/core.sr.ht

a1c6d0d6bca279a8e265bedde0da203e4455f159 — Drew DeVault 2 months ago 23b57d8 master
srht.oauth: add prometheus metric for legacy use

To get an idea of the current usage of the legacy API in preparation for
its removal.
1 files changed, 4 insertions(+), 0 deletions(-)

M srht/oauth/decorator.py
M srht/oauth/decorator.py => srht/oauth/decorator.py +4 -0
@@ 8,11 8,14 @@ from srht.database import db
from srht.oauth import OAuthError, UserType
from srht.oauth.scope import OAuthScope
from srht.validation import Validation
from prometheus_client import Counter
import hashlib
import requests

metasrht = get_origin("meta.sr.ht")

deprecated_oauth_counter = Counter("deprecated_oauth", "Deprecated legacy OAuth token use")

def _internal_auth(f, auth, *args, **kwargs):
    # Used for authenticating internal API users, like other sr.ht sites.
    oauth_service = current_app.oauth_service


@@ 84,6 87,7 @@ def oauth(scopes):

            token = token[1]
            token_hash = hashlib.sha512(token.encode()).hexdigest()
            deprecated_auth_counter.inc()

            try:
                if scopes: