|
| 1 | +''' |
| 2 | +Created on October 12, 2023 |
| 3 | +@author: kumykov |
| 4 | +
|
| 5 | +Copyright (C) 2023 Synopsys, Inc. |
| 6 | +http://www.synopsys.com/ |
| 7 | +
|
| 8 | +Licensed to the Apache Software Foundation (ASF) under one |
| 9 | +or more contributor license agreements. See the NOTICE file |
| 10 | +distributed with this work for additional information |
| 11 | +regarding copyright ownership. The ASF licenses this file |
| 12 | +to you under the Apache License, Version 2.0 (the |
| 13 | +"License"); you may not use this file except in compliance |
| 14 | +with the License. You may obtain a copy of the License at |
| 15 | +
|
| 16 | +http://www.apache.org/licenses/LICENSE-2.0 |
| 17 | +
|
| 18 | +Unless required by applicable law or agreed to in writing, |
| 19 | +software distributed under the License is distributed on an |
| 20 | +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 21 | +KIND, either express or implied. See the License for the |
| 22 | +specific language governing permissions and limitations |
| 23 | +under the License. |
| 24 | +
|
| 25 | +This script is provided as an example of populating custom field data |
| 26 | +based on BOM components crypto information. |
| 27 | +The goal is to enable policy functionality that would be triggered by |
| 28 | +cryptographic features of a component. |
| 29 | +
|
| 30 | +The scriot will analyze ciphers included in a component and will set |
| 31 | +a BOM Component custom field value to reflec that. |
| 32 | +
|
| 33 | +Requirements |
| 34 | +
|
| 35 | +- python3 version 3.8 or newer recommended |
| 36 | +- the following packages are used by the script and should be installed |
| 37 | + prior to use: |
| 38 | + argparse |
| 39 | + blackduck |
| 40 | + logging |
| 41 | + sys |
| 42 | + json |
| 43 | + pprint |
| 44 | +- Blackduck instance |
| 45 | +- API token with sufficient privileges to perform project version phase |
| 46 | + change. |
| 47 | +
|
| 48 | +Install python packages with the following command: |
| 49 | +
|
| 50 | + pip3 install argparse blackduck logging sys json pprint |
| 51 | +
|
| 52 | +Using |
| 53 | +
|
| 54 | +Script expects a boolean custom field labeled "BadCrypto" on a BOM Component. |
| 55 | +A policy that is triggered by BadCrypto custom field value used to visualise |
| 56 | +results. |
| 57 | +
|
| 58 | +usage: crypto-to-custom.py [-h] -u BASE_URL -t TOKEN_FILE -pn PROJECT_NAME -vn VERSION_NAME [-nv] [--reset] |
| 59 | +
|
| 60 | +options: |
| 61 | + -h, --help show this help message and exit |
| 62 | + -u BASE_URL, --base-url BASE_URL |
| 63 | + Hub server URL e.g. https://your.blackduck.url |
| 64 | + -t TOKEN_FILE, --token-file TOKEN_FILE |
| 65 | + File containing access token |
| 66 | + -pn PROJECT_NAME, --project-name PROJECT_NAME |
| 67 | + Project Name |
| 68 | + -vn VERSION_NAME, --version-name VERSION_NAME |
| 69 | + Version Name |
| 70 | + -nv, --no-verify Disable TLS certificate verification |
| 71 | + --reset Undo the changes made by thjis script |
| 72 | +
|
| 73 | +
|
| 74 | +''' |
| 75 | + |
1 | 76 | import argparse
|
2 | 77 | from blackduck import Client
|
3 | 78 | from pprint import pprint
|
@@ -32,13 +107,13 @@ def find_project_version_by_name(project, version_name):
|
32 | 107 |
|
33 | 108 | def parse_command_args():
|
34 | 109 |
|
35 |
| - parser = argparse.ArgumentParser("product-from-bom.py") |
| 110 | + parser = argparse.ArgumentParser("crypto-to-custom.py") |
36 | 111 | parser.add_argument("-u", "--base-url", required=True, help="Hub server URL e.g. https://your.blackduck.url")
|
37 | 112 | parser.add_argument("-t", "--token-file", required=True, help="File containing access token")
|
38 | 113 | parser.add_argument("-pn", "--project-name", required=True, help="Project Name")
|
39 | 114 | parser.add_argument("-vn", "--version-name", required=True, help="Version Name")
|
40 | 115 | parser.add_argument("-nv", "--no-verify", action='store_false', help="Disable TLS certificate verification")
|
41 |
| - parser.add_argument("--reset", action='store_true') |
| 116 | + parser.add_argument("--reset", action='store_true', help="Undo the changes made by thjis script") |
42 | 117 | return parser.parse_args()
|
43 | 118 |
|
44 | 119 | def set_custom_field(field, url, value):
|
|
0 commit comments