17
17
"baseurl": "YOUR_BLACKDUCK_URL",
18
18
"api_token": "YOUR_API_TOKEN",
19
19
"insecure": <true or false>,
20
- "timeout": 15,
20
+ "timeout": 15.0 ,
21
21
"retries": 3,
22
22
"filters": {
23
23
"type":"VULNERABILITY",
@@ -109,6 +109,7 @@ def main():
109
109
try :
110
110
with open ('.restconfig-notifications.json' ,'r' ) as f :
111
111
config = json .load (f )
112
+ set_to_seen = 0
112
113
hub_client = Client (token = config ['api_token' ],
113
114
base_url = config ['baseurl' ],
114
115
verify = not config ['insecure' ],
@@ -120,33 +121,26 @@ def main():
120
121
121
122
user = get_user (hub_client , user_name )
122
123
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' ]} " )
145
134
else :
146
135
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 )} " )
147
138
except Exception as err :
148
139
logging .error (f"Failed to perform the task with exception { str (err )} . See also the stack trace" )
149
140
traceback .print_exc ()
141
+ finally :
142
+ logging .info (f"=== Updating Notifications Finished ===" )
143
+ logging .info (f"{ set_to_seen } Notifications are set to SEEN." )
150
144
151
145
if __name__ == '__main__' :
152
146
sys .exit (main ())
0 commit comments