Skip to content

Commit acdb21d

Browse files
dnicholdnichol
authored andcommitted
Updates after pull request
1 parent e347850 commit acdb21d

File tree

2 files changed

+61
-4
lines changed

2 files changed

+61
-4
lines changed

examples/update_usergroups_from_csv.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,37 @@
22
Created on Jan 27, 2023
33
@author: dnichol
44
Bulk update user group names from CSV. CSV file requires two columns, titled 'Existing' and 'New'. This script is case sensitive.
5+
6+
This script requires a .restconfig.json file present to configure the connection details. For more details see : https://community.synopsys.com/s/article/How-to-use-the-hub-rest-api-python-for-Black-Duck
7+
8+
The .restconfig.json file should be in the following format:
9+
10+
{
11+
"baseurl": "https://your-hub-dns",
12+
"api_token": "insert-token-here",
13+
"insecure": true,
14+
"debug": false
15+
}
16+
17+
Copyright (C) 2023 Synopsys, Inc.
18+
http://www.synopsys.com/
19+
20+
Licensed to the Apache Software Foundation (ASF) under one
21+
or more contributor license agreements. See the NOTICE file
22+
distributed with this work for additional information
23+
regarding copyright ownership. The ASF licenses this file
24+
to you under the Apache License, Version 2.0 (the
25+
"License"); you may not use this file except in compliance
26+
with the License. You may obtain a copy of the License at
27+
28+
http://www.apache.org/licenses/LICENSE-2.0
29+
30+
Unless required by applicable law or agreed to in writing,
31+
software distributed under the License is distributed on an
32+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
33+
KIND, either express or implied. See the License for the
34+
specific language governing permissions and limitations
35+
under the License.
536
'''
637

738
import csv
@@ -15,7 +46,6 @@
1546
from blackduck import Client
1647

1748
def log_config():
18-
# TODO: debug option in .restconfig file to be reflected
1949
logging.basicConfig(format='%(asctime)s:%(levelname)s:%(module)s: %(message)s', stream=sys.stderr, level=logging.DEBUG)
2050
logging.getLogger("requests").setLevel(logging.WARNING)
2151
logging.getLogger("urllib3").setLevel(logging.WARNING)
@@ -73,7 +103,7 @@ def update_user_group(hub_client, existing_name, new_name, user_group):
73103
# Update the name.
74104
user_group['name'] = new_name
75105

76-
logging.info(f"Updating user group {existing_name} to {user_group['name']} for user group {user_group_url}s")
106+
logging.info(f"Updating user group {existing_name} to {user_group['name']} for user group {user_group_url}")
77107
hub_client.session.put(user_group_url, json=user_group)
78108

79109

examples/update_users_from_csv.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,34 @@
22
Created on Jan 27, 2023
33
@author: dnichol
44
Bulk update users email addresses from CSV. CSV file requires two columns, titled 'Existing' and 'New'. This script is case sensitive.
5+
6+
This script requires a .restconfig.json file present to configure the connection details. For more details see : https://community.synopsys.com/s/article/How-to-use-the-hub-rest-api-python-for-Black-Duck
7+
8+
The .restconfig.json file should be in the following format:
9+
10+
{
11+
"baseurl": "https://your-hub-dns",
12+
"api_token": "insert-token-here",
13+
"insecure": true,
14+
"debug": false
15+
}
16+
17+
Licensed to the Apache Software Foundation (ASF) under one
18+
or more contributor license agreements. See the NOTICE file
19+
distributed with this work for additional information
20+
regarding copyright ownership. The ASF licenses this file
21+
to you under the Apache License, Version 2.0 (the
22+
"License"); you may not use this file except in compliance
23+
with the License. You may obtain a copy of the License at
24+
25+
http://www.apache.org/licenses/LICENSE-2.0
26+
27+
Unless required by applicable law or agreed to in writing,
28+
software distributed under the License is distributed on an
29+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
30+
KIND, either express or implied. See the License for the
31+
specific language governing permissions and limitations
32+
under the License.
533
'''
634

735
import csv
@@ -15,7 +43,6 @@
1543
from blackduck import Client
1644

1745
def log_config():
18-
# TODO: debug option in .restconfig file to be reflected
1946
logging.basicConfig(format='%(asctime)s:%(levelname)s:%(module)s: %(message)s', stream=sys.stderr, level=logging.DEBUG)
2047
logging.getLogger("requests").setLevel(logging.WARNING)
2148
logging.getLogger("urllib3").setLevel(logging.WARNING)
@@ -79,7 +106,7 @@ def update_user(hub_client, existing_email, new_email, user):
79106
if user.get('externalUserName') and user['externalUserName'] == existing_email:
80107
user['externalUserName'] = new_email
81108

82-
logging.info(f"Updating user {existing_email} to {user['email']} for user {user_url}s")
109+
logging.info(f"Updating user {existing_email} to {user['email']} for user {user_url}")
83110
hub_client.session.put(user_url, json=user)
84111

85112

0 commit comments

Comments
 (0)