Skip to content

Commit

Permalink
Move fas by github to github module
Browse files Browse the repository at this point in the history
Signed-off-by: Mehmet Baran Geylani <[email protected]>
  • Loading branch information
brngylni committed Jul 24, 2024
1 parent ea07749 commit 4b72fb8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
17 changes: 16 additions & 1 deletion webhook_to_fedora_messaging/endpoints/parser/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
import hashlib
import hmac
from webhook_to_fedora_messaging_messages.github.github import GithubMessageV1
from ..util import fas_by_github
from webhook_to_fedora_messaging.exceptions import SignatureMatchError
import fasjson_client
from webhook_to_fedora_messaging.config.defaults import FASJSON_URL


def github_parser(secret: str) -> GithubMessageV1:
"""Convert Flask request objects into desired FedMsg format.
Expand Down Expand Up @@ -37,3 +39,16 @@ def verify_signature(secret_token: str, signature_header: str) -> bool:
expected_signature = "sha256=" + hash_object.hexdigest()

return hmac.compare_digest(expected_signature, signature_header)


def fas_by_github(username: str) -> str:
"""Get the Fedora Account System Username of the given github username
Args:
username: Github Username"""

fasjson = fasjson_client.Client(FASJSON_URL)
response = fasjson.search(github_username=username)
if response.result and len(response.result) == 1:
return response.result[0]["username"]
return None
15 changes: 1 addition & 14 deletions webhook_to_fedora_messaging/endpoints/util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from flask import Response, request, abort
from functools import wraps
import fasjson_client


def validate_request(fields=None):
fields = fields or ['username']
Expand All @@ -27,16 +27,3 @@ def wrapper(*args, **kwargs):
return decorator(func)

return decorator


def fas_by_github(username: str) -> str:
"""Get the Fedora Account System Username of the given github username
Args:
username: Github Username"""

fasjson = fasjson_client.Client(FASJSON_URL)
response = fasjson.search(github_username=username)
if response.result and len(response.result) == 1:
return response.result[0]["username"]
return None

0 comments on commit 4b72fb8

Please sign in to comment.