Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Production fixes #619

Merged
merged 3 commits into from
Oct 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions fmn/delivery/backends/irc.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def dequote(self, text):

def send(self, nick, line):
for client in self.clients:
client.msg(nick.encode('utf-8'), line.encode('utf-8'))
client.msg(nick, line)

def cmd_start(self, nick, message):
log.info("CMD start: %r sent us %r" % (nick, message))
Expand Down Expand Up @@ -299,7 +299,12 @@ def cmd_default(self, nick, message):
if message.startswith('***'):
return

log.info("CMD unk: %r sent us %r" % (nick, message))
log.info("CMD unk: %r sent us %r" % (nick, message.encode('utf-8')))

if nick.lower() == 'nickserv':
log.info(" Bailing, no need to explain to NickServ how to interact with us")
return

self.send(nick, "say 'help' for help or 'stop' to stop messages")

def deliver(self, formatted_message, recipient, raw_fedmsg):
Expand Down Expand Up @@ -349,8 +354,8 @@ def deliver(self, formatted_message, recipient, raw_fedmsg):

for client in self.clients:
getattr(client, recipient.get('method', 'msg'))(
nickname.encode('utf-8'),
formatted_message.encode('utf-8'),
nickname,
formatted_message,
)

def _handle_confirmation(self, nick):
Expand Down
39 changes: 28 additions & 11 deletions fmn/fmn_fasshim.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from dogpile.cache import make_region

from fmn import config
from fasjson_client import Client
import fasjson_client

fedmsg.meta.make_processors(**config.app_conf)

Expand All @@ -27,7 +27,7 @@

fasjson = config.app_conf['fasjson']
if fasjson.get('active'):
client = Client(url=fasjson.get('url', default_url))
client = fasjson_client.Client(url=fasjson.get('url', default_url))
else:
client = fedora.client.fas2.AccountSystem(
base_url=creds.get('base_url', default_url),
Expand Down Expand Up @@ -92,14 +92,19 @@ def make_fas_cache(**config):


def _add_to_cache(users):
for user in users:
nicks = user.get('ircnicks', [])
for nick in nicks:
_cache.set(nick, user['username'])
if users is not None:
for user in users:
if type(user) is dict:
nicks = user.get('ircnicks', [])
if nicks is not None:
for nick in nicks:
_cache.set(
nick.removeprefix("irc:/").removeprefix("matrix:/"), user['username']
)

emails = user.get('emails', [])
for email in emails:
_cache.set(email, user['username'])
emails = user.get('emails', [])
for email in emails:
_cache.set(email, user['username'])


def update_nick(username):
Expand All @@ -108,9 +113,15 @@ def update_nick(username):
try:
log.info("Downloading FASJSON cache for %s*" % username)
response = client.get_user(username=username)
_add_to_cache([response["result"]])
if response:
# Result is string, not dict
# This means it contains error message
if type(response.result) is dict:
_add_to_cache(response.result)
except requests.exceptions.RequestException as e:
log.error("Something went wrong updating the cache with error: %s" % e)
except fasjson_client.errors.APIError as e:
log.error("Something went wrong updating the cache with error: %s" % e)
else:
try:
log.info("Downloading FAS cache for %s*" % username)
Expand Down Expand Up @@ -145,9 +156,15 @@ def update_email(email):
try:
log.info("Downloading FASJSON cache for %s*" % email)
response = client.search(email=email)
_add_to_cache(response['result'])
if response:
# Result is string, not dict
# This means it contains error message
if type(response.result) is dict:
_add_to_cache(response.result)
except requests.exceptions.RequestException as e:
log.error("Something went wrong updating the cache with error: %s" % e)
except fasjson_client.errors.APIError as e:
log.error("Something went wrong updating the cache with error: %s" % e)
else:
try:
log.info("Downloading FAS cache for %s" % email)
Expand Down
4 changes: 2 additions & 2 deletions fmn/rules/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def package_regex_filter(config, message, pattern=None, *args, **kw):
pattern = kw.get('pattern', pattern)
if pattern:
packages = fmn.rules.utils.msg2packages(message, **config)
regex = fmn.rules.utils.compile_regex(pattern.encode('utf-8'))
regex = fmn.rules.utils.compile_regex(pattern)
return any([regex.search(p.encode('utf-8')) for p in packages])


Expand All @@ -180,7 +180,7 @@ def regex_filter(config, message, pattern=None, *args, **kw):

pattern = kw.get('pattern', pattern)
if pattern:
regex = fmn.rules.utils.compile_regex(pattern.encode('utf-8'))
regex = fmn.rules.utils.compile_regex(pattern)
return bool(regex.search(
fedmsg.encoding.dumps(message['msg']).encode('utf-8')
))
Expand Down
12 changes: 7 additions & 5 deletions fmn/rules/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def get_fas(config):
log.warning("No fasjson config available. Unable to query FAS.")
return None

client = fasjson_client.Client(url=fasjson.get('url'))
_FAS = fasjson_client.Client(url=fasjson_config.get('url'))

return _FAS

Expand Down Expand Up @@ -401,7 +401,7 @@ def get_user_of_group(config, fas, groupname):
def creator():
if not fas:
return set()
return set([u["username"] for u in fas.list_group_members(groupname).result])
return set([u["username"] for u in fas.list_group_members(groupname=groupname).result])
return _cache.get_or_create(key, creator)


Expand All @@ -424,10 +424,12 @@ def creator():
if not fas:
return []
results = []
for group in fas.list_all_entities("groups"):
members = set([u["username"] for u in fas.list_group_members(group["groupname"]).result])
if username in members:
try:
for group in fas.list_user_groups(username=username).result:
results.append(group["groupname"])
except fasjson_client.errors.APIError as error:
# Error on FAS side
return []
return results

return _cache.get_or_create(key, creator)
Expand Down
2 changes: 1 addition & 1 deletion fmn/tests/test_confirmations.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_updating_details(self):

try:
preference.update_details(self.sess, 'wat')
assert(False)
assert False
except Exception:
self.sess.rollback()

Expand Down
2 changes: 0 additions & 2 deletions setup.cfg

This file was deleted.