Skip to content

Commit aa20677

Browse files
committed
.
1 parent 4582c73 commit aa20677

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
'''
2+
Created on Jan 18, 2024
3+
4+
@author: kumykov
5+
6+
Update project settings script.
7+
8+
This script will modify project settings accessible via API
9+
10+
Parameter list and their default values:
11+
"customSignatureEnabled" : false,
12+
"customSignatureDepth" : "5",
13+
"unmatchedFileRetentionEnabled" : false,
14+
15+
'''
16+
17+
from blackduck import Client
18+
19+
import argparse
20+
import json
21+
import logging
22+
import sys
23+
import time
24+
from pprint import pprint
25+
26+
logging.basicConfig(
27+
level=logging.DEBUG,
28+
format="[%(asctime)s] {%(module)s:%(lineno)d} %(levelname)s - %(message)s"
29+
)
30+
31+
parser = argparse.ArgumentParser(sys.argv[0])
32+
parser.add_argument("-u", "--bd-url", help="Hub server URL e.g. https://your.blackduck.url")
33+
parser.add_argument("-t", "--token-file", help="File name of a file containing access token")
34+
parser.add_argument("-nv", '--no-verify', dest='verify', action='store_false', help="disable TLS certificate verification")
35+
parser.add_argument("-cse", '--custom-signature-enabled', dest='cs_enable', action='store_true', help="enable custom signature flag")
36+
parser.add_argument("-csd", '--custom-signature-depth', dest='cs_depth', required=False, default="5", help="set custom signature depth")
37+
parser.add_argument("-ruf", '--retain-unmatched-files', dest='retain_uf', action='store_true', help="set retain unmatched files flag")
38+
parser.add_argument("project_name")
39+
40+
args = parser.parse_args()
41+
42+
logging.basicConfig(format='%(asctime)s:%(levelname)s:%(message)s', stream=sys.stderr, level=logging.DEBUG)
43+
logging.getLogger("requests").setLevel(logging.WARNING)
44+
logging.getLogger("urllib3").setLevel(logging.WARNING)
45+
logging.getLogger("blackduck").setLevel(logging.WARNING)
46+
47+
with open(args.token_file, 'r') as tf:
48+
access_token = tf.readline().strip()
49+
50+
bd = Client(base_url=args.bd_url, token=access_token, verify=args.verify)
51+
pprint (args.project_name)
52+
params = {
53+
'q': [f"name:{args.project_name}"]
54+
}
55+
projects = [p for p in bd.get_resource('projects', params=params) if p['name'] == args.project_name]
56+
assert len(projects) == 1, f"There should be one, and only one project named {args.project_name}. We found {len(projects)}"
57+
project = projects[0]
58+
59+
url = project['_meta']['href']
60+
project['customSignatureEnabled'] = args.cs_enable
61+
project['customSignatureDepth'] = args.cs_depth
62+
project['unmatchedFileRetentionEnabled'] = args.retain_uf
63+
64+
response = bd.session.put(url, json=project)
65+
logging.info(f"Project setting update status {response}")

0 commit comments

Comments
 (0)