Skip to content

Commit 5e38ac6

Browse files
authored
Improve error handling for GET call to /groups API (#47)
* Improve error handling for GET call to /groups API * Improve error handling for GET call to /groups API
1 parent 7d4a901 commit 5e38ac6

File tree

2 files changed

+30
-22
lines changed

2 files changed

+30
-22
lines changed

project-collections/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,7 @@ remove_collection -a \<snyk-auth-token\> -g "kevin.matthews Group" -o "PR Test O
5555
- --effective_severity_level "Comma separated list of severities to be identified in tagged project issues payload"
5656
- --api_ver "The version of the Snyk API to be used (default recommended)"
5757

58+
### Note
59+
Some of the APIs used are in beta. Others are GA. As the beta's become GA, I will remove the 'hard-coded' use of their
60+
beta counterparts. Meantime, please DO NOT specify a beta version of an API should you wish to choose a specific
61+
version. It is recommended at this time that you allow the default version to be used.

project-collections/utils/util_func.py

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,32 @@ def process_collection(headers, args, func):
2121
# Retrieve all my groups
2222
g_response = json.loads(utils.rest_api.groups(headers, args["api_ver"]))
2323

24-
# Iterate to the named group
25-
for group in g_response['data']:
26-
if group['attributes']['name'] == args['grp_name']:
27-
go_pagination = None
28-
while True:
29-
go_response = json.loads(utils.rest_api.group_orgs(headers, args["api_ver"], group, go_pagination))
30-
31-
# Iterate to the named Org
32-
for org in go_response['data']:
33-
if org['attributes']['name'] == args["org_name"]:
34-
35-
# Find the collection id
36-
collection_id = find_collection(headers, args, org)
37-
38-
# Do the collection process within the passed function
39-
func(headers, args, org, collection_id)
40-
41-
# Next page?
42-
go_pagination = next_page(go_response)
43-
if go_pagination is None:
44-
break
45-
24+
try:
25+
# Iterate to the named group
26+
for group in g_response['data']:
27+
if group['attributes']['name'] == args['grp_name']:
28+
go_pagination = None
29+
while True:
30+
go_response = json.loads(utils.rest_api.group_orgs(headers, args["api_ver"], group, go_pagination))
31+
32+
# Iterate to the named Org
33+
for org in go_response['data']:
34+
if org['attributes']['name'] == args["org_name"]:
35+
36+
# Find the collection id
37+
collection_id = find_collection(headers, args, org)
38+
39+
# Do the collection process within the passed function
40+
func(headers, args, org, collection_id)
41+
42+
# Next page?
43+
go_pagination = next_page(go_response)
44+
if go_pagination is None:
45+
break
46+
except Exception:
47+
print("GET call to /groups API returned no 'data'")
48+
print(json.dumps(g_response, indent=4))
49+
return
4650

4751

4852
def find_collection(headers, args, org):

0 commit comments

Comments
 (0)