Skip to content

Commit

Permalink
Add openid2fas resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
bexelbie committed Jun 14, 2018
1 parent 53bb6ca commit cf2fe10
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions fedbadges/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import functools
import inspect
import transaction
import re

import fedmsg.config
import fedmsg.meta
Expand Down Expand Up @@ -50,6 +51,12 @@
except ImportError as e:
log.warn("Could not import email2fas: %r" % e)

# Match OpenID agent strings, i.e. http://FAS.id.fedoraproject.org
def openid2fas(openid, **config):
m = re.search('^https?://([a-z][a-z0-9]+)\.id\.fedoraproject\.org$', openid)
if m:
return m.group(1)
return openid

operators = frozenset([
"all",
Expand Down Expand Up @@ -87,6 +94,7 @@ class BadgeRule(object):
'recipient',
'recipient_nick2fas',
'recipient_email2fas',
'recipient_openid2fas',
])

banned_usernames = frozenset([
Expand Down Expand Up @@ -135,6 +143,7 @@ def __init__(self, badge_dict, tahrir_database, issuer_id):
self.recipient_key = self._d.get('recipient')
self.recipient_nick2fas = self._d.get('recipient_nick2fas')
self.recipient_email2fas = self._d.get('recipient_email2fas')
self.recipient_openid2fas = self._d.get('recipient_openid2fas')

# A sanity check before we kick things off.
if self.recipient_nick2fas and not nick2fas:
Expand Down Expand Up @@ -187,6 +196,11 @@ def matches(self, msg):
awardees = frozenset([
email2fas(email, **fedmsg_config) for email in awardees
])

if self.recipient_openid2fas:
awardees = frozenset([
openid2fas(openid, **fedmsg_config) for openid in awardees
])
else:
usernames = fedmsg.meta.msg2usernames(msg)
awardees = usernames.difference(self.banned_usernames)
Expand Down

0 comments on commit cf2fe10

Please sign in to comment.