Skip to content

Commit e4a38a6

Browse files
author
Makoto Koishi
committed
Network error handling is reverted to the original one which only depends on the Client class
1 parent 986aee0 commit e4a38a6

File tree

1 file changed

+17
-23
lines changed

1 file changed

+17
-23
lines changed

examples/filtering_notifications.py

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"baseurl": "YOUR_BLACKDUCK_URL",
1818
"api_token": "YOUR_API_TOKEN",
1919
"insecure": <true or false>,
20-
"timeout": 15,
20+
"timeout": 15.0,
2121
"retries": 3,
2222
"filters": {
2323
"type":"VULNERABILITY",
@@ -109,6 +109,7 @@ def main():
109109
try:
110110
with open('.restconfig-notifications.json','r') as f:
111111
config = json.load(f)
112+
set_to_seen = 0
112113
hub_client = Client(token=config['api_token'],
113114
base_url=config['baseurl'],
114115
verify=not config['insecure'],
@@ -120,33 +121,26 @@ def main():
120121

121122
user = get_user(hub_client, user_name)
122123
if user:
123-
set_to_seen = 0
124-
failed = 0
125-
while True:
126-
try:
127-
for notification in read_notifications(
128-
hub_client,
129-
notification_filters,
130-
user,
131-
vuln_source=vuln_source):
132-
user_id = re.split("/", user['_meta']['href'])[-1]
133-
res = update_user_notification(hub_client, user_id, notification)
134-
set_to_seen += 1
135-
content = literal_eval(res.content.decode("UTF-8"))
136-
logging.info(f"Notification state is set to SEEN for {content['type']}")
137-
except RequestException as err:
138-
failed += 1
139-
logging.error(f"Failed to read or update notification and the reason is {str(err)}")
140-
continue
141-
logging.info(f"=== Updating Notifications Finished ===")
142-
logging.info(f"{set_to_seen} Notifications are set to SEEN.")
143-
logging.info(f"{failed} Notifications failed to read or update the state.")
144-
break
124+
for notification in read_notifications(
125+
hub_client,
126+
notification_filters,
127+
user,
128+
vuln_source=vuln_source):
129+
user_id = re.split("/", user['_meta']['href'])[-1]
130+
res = update_user_notification(hub_client, user_id, notification)
131+
set_to_seen += 1
132+
content = literal_eval(res.content.decode("UTF-8"))
133+
logging.info(f"Notification state is set to SEEN for {content['type']}")
145134
else:
146135
logging.error(f"User not found for {user_name}")
136+
except RequestException as err:
137+
logging.error(f"Failed to read or update notification and the reason is {str(err)}")
147138
except Exception as err:
148139
logging.error(f"Failed to perform the task with exception {str(err)}. See also the stack trace")
149140
traceback.print_exc()
141+
finally:
142+
logging.info(f"=== Updating Notifications Finished ===")
143+
logging.info(f"{set_to_seen} Notifications are set to SEEN.")
150144

151145
if __name__ == '__main__':
152146
sys.exit(main())

0 commit comments

Comments
 (0)