|
| 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']}") |
0 commit comments