Skip to content

Commit

Permalink
Merge branch 'master' into fix-static-methods
Browse files Browse the repository at this point in the history
  • Loading branch information
sqqueak committed Feb 19, 2024
2 parents 0b1e483 + ebda6a0 commit 5675ab1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
21 changes: 16 additions & 5 deletions bin/osg-notify
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
A simple tool for generating notification emails to the OSG
"""
import os
import re
import sys
import getpass
import smtplib
Expand Down Expand Up @@ -116,10 +117,9 @@ def parseargs():
oparser.add_argument("--oim-owner-filter", dest="owner_vo",
help="Filter on resources that list VO(s) as a partial owner")

oparser.add_argument("--oim-contact-type", default="all", dest="contact_type",
choices=["all", "administrative", "miscellaneous", "security", "submitter", "site"],
help="Filter on contact type e.g. administrative, miscellaneous, security, submitter or site"
"(default: all)", )
oparser.add_argument("--oim-contact-type", action="append", dest="contact_type",
choices=["all"] + topology_utils.CONTACT_TYPES,
help="Filter on contact type (default: all)")
oparser.add_argument("--bypass-dns-check", action="store_true", dest="bypass_dns_check",
help="Bypass checking that one of the host's IP addresses matches with the hostanme resolution")
oparser.add_argument("--allow-non-ascii", action="store_true", dest="allow_non_ascii",
Expand All @@ -132,6 +132,10 @@ def parseargs():
if args.name_filter and args.fqdn_filter:
oparser.error("Can't specify both --oim-name-filter and --oim-fqdn-filter")

if not args.contact_type or ("all" in args.contact_type):
args.contact_type = ["all"]
args.contact_type = set(args.contact_type) # remove dupes

if args.from_name == 'security':
args.from_name = 'OSG Security Team'
args.from_addr = '[email protected]'
Expand All @@ -158,7 +162,12 @@ def network_ok(bypass_dns_check):

def replace_smart_quotes_and_dashes(contents):
# Replace smart quotes and em/en dashes
replaced = contents.replace('“','"').replace('”','"').replace("–","-").replace("—","-")
regex_sub_map = [(r'[“”]', '"'),
(r'[‘’]', "'"),
(r'[—–]', '-')]
replaced = contents
for pattern, sub in regex_sub_map:
replaced = re.sub(pattern, sub, replaced)
return replaced

def has_non_printable_ascii_characters(contents):
Expand All @@ -181,6 +190,7 @@ def main():
while attempts > 0:
try:
results = pm.get_vo_contacts(args)
break
except topology_utils.InvalidPathError as exc:
print(exc)
exit(1)
Expand All @@ -206,6 +216,7 @@ def main():
results = pm.get_resource_contacts_by_fqdn(args)
else:
results = pm.get_resource_contacts(args)
break
except topology_utils.InvalidPathError as exc:
exit(str(exc))
except topology_utils.IncorrectPasswordError as exc:
Expand Down
16 changes: 14 additions & 2 deletions src/topology_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@

import requests

# List of contact types stored in Topology data
# At time of writing, there isn't anything that restricts a contact to one of these types
CONTACT_TYPES = ["administrative",
"miscellaneous",
"security",
"submitter",
"site",
"local executive",
"local operational",
"local security"]

class Error(Exception):
pass

Expand Down Expand Up @@ -378,8 +389,9 @@ def filter_contacts(self, args, results):
contact_list = []
for contact in results[name]:
contact_type = contact['ContactType']
if contact_type.startswith(args.contact_type):
contact_list.append(contact)
for args_contact_type in args.contact_type:
if contact_type.startswith(args_contact_type):
contact_list.append(contact)
if contact_list == []:
del results[name]
else:
Expand Down

0 comments on commit 5675ab1

Please sign in to comment.