Skip to content

Commit ba99688

Browse files
author
Murat Kumykov
committed
2 parents bfd6554 + b09a4e4 commit ba99688

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

examples/client/get_users.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env python
2+
3+
'''
4+
Copyright (C) 2022 Synopsys, Inc.
5+
http://www.blackducksoftware.com/
6+
7+
Licensed to the Apache Software Foundation (ASF) under one
8+
or more contributor license agreements. See the NOTICE file
9+
distributed with this work for additional information
10+
regarding copyright ownership. The ASF licenses this file
11+
to you under the Apache License, Version 2.0 (the
12+
"License"); you may not use this file except in compliance
13+
with the License. You may obtain a copy of the License at
14+
15+
http://www.apache.org/licenses/LICENSE-2.0
16+
17+
Unless required by applicable law or agreed to in writing,
18+
software distributed under the License is distributed on an
19+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20+
KIND, either express or implied. See the License for the
21+
specific language governing permissions and limitations
22+
under the License.
23+
24+
'''
25+
import argparse
26+
import json
27+
import logging
28+
import sys
29+
30+
from blackduck import Client
31+
32+
parser = argparse.ArgumentParser("Get all the users")
33+
parser.add_argument("--base-url", required=True, help="Hub server URL e.g. https://your.blackduck.url")
34+
parser.add_argument("--token-file", dest='token_file', required=True, help="containing access token")
35+
parser.add_argument("--no-verify", dest='verify', action='store_false', help="disable TLS certificate verification")
36+
args = parser.parse_args()
37+
38+
39+
logging.basicConfig(format='%(asctime)s:%(levelname)s:%(message)s', stream=sys.stderr, level=logging.DEBUG)
40+
logging.getLogger("requests").setLevel(logging.WARNING)
41+
logging.getLogger("urllib3").setLevel(logging.WARNING)
42+
logging.getLogger("blackduck").setLevel(logging.WARNING)
43+
44+
with open(args.token_file, 'r') as tf:
45+
access_token = tf.readline().strip()
46+
47+
bd = Client(
48+
base_url=args.base_url,
49+
token=access_token,
50+
verify=args.verify
51+
)
52+
53+
for user in bd.get_resource("users"):
54+
print(f"User: {user['userName']}, First Name: {user['firstName']}, Last Name: {user['lastName']}")

examples/get_users.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414

1515
users = hub.get_users()
1616

17+
#
18+
# Note: The HubInstance interface does NOT handle paging of results
19+
# but the new Client interface does. See https://github.com/blackducksoftware/hub-rest-api-python/blob/master/examples/client/get_users.py
20+
# for an example of retrieving users using the new Client interface
21+
#
1722
if 'totalCount' in users and users['totalCount'] > 0:
1823
print(json.dumps(users))
1924
else:

0 commit comments

Comments
 (0)