From 0bf26a56be48323c4f2c6c15b02793eabc9c98da Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Apr 11 2018 16:35:44 +0000 Subject: Add a --get parameter to search if there are waivers This is far from ideal, the current implementation basically does not allow having multiple actions on the same script, we cannot do things like: waiverdb-cli new waiverdb-cli get waiverdb-cli delete ... without breaking backward compatibility. So in order to get the functionality for retrieving waivers, I have added a --get parameter which allows, using the same syntax to either set or get waivers against the specified subject. It's not ideal, but from my testing it does work as expected. We may consider refactoring this one day, but it is not a priority for the moment. Fixes https://pagure.io/waiverdb/issue/152 Signed-off-by: Pierre-Yves Chibon --- diff --git a/README.md b/README.md index 611aff1..fd9d6be 100644 --- a/README.md +++ b/README.md @@ -84,15 +84,22 @@ to specify one. ``` Usage: waiverdb-cli [OPTIONS] - Creates new waivers against test results. + Creates new waiver or retrieve recorded waivers against test results - Examples: + Examples to set a waiver: waiverdb-cli -r 47 -r 48 -p "fedora-28" -c "This is fine" -or - waiverdb-cli -t dist.rpmdeplint -s '{"item": "qclib-1.3.1-3.fc28", "type": "koji_build"}' -p "fedora-28" -c "This is expected for non-x86 packages" + or + waiverdb-cli -t dist.rpmdeplint -s '{"item": "qclib-1.3.1-3.fc28", + "type": "koji_build"}' -p "fedora-28" -c "This is expected for non-x86 + packages" + + Example to retrieve waivers: + + waiverdb-cli --get -t dist.rpmdeplint -s '{"item": + "qclib-1.3.1-3.fc28", "type": "koji_build"}' -p fedora-28 Options: -C, --config-file PATH Specify a config file to use @@ -101,7 +108,8 @@ Options: -t, --testcase TEXT Specify a testcase for the subject -p, --product-version TEXT Specify one of PDC's product version identifiers. - --waived / --no-waived Whether or not the result is waived + --waived / --no-waived Waive or unwaive the result, defaults to "waive" + --get Search if the result has been waived -c, --comment TEXT A comment explaining why the result is waived -h, --help Show this message and exit. ``` diff --git a/waiverdb/cli.py b/waiverdb/cli.py index bef7481..c49931c 100644 --- a/waiverdb/cli.py +++ b/waiverdb/cli.py @@ -66,22 +66,27 @@ def check_response(resp, data, result_id=None): @click.option('--product-version', '-p', help='Specify one of PDC\'s product version identifiers.') @click.option('--waived/--no-waived', default=True, - help='Whether or not the result is waived') + help='Waive or unwaive the result, defaults to "waive"') +@click.option('--get', default=False, is_flag=True, + help='Search if the result has been waived') @click.option('--comment', '-c', help='A comment explaining why the result is waived') -def cli(comment, waived, product_version, testcase, subject, result_id, config_file): +def cli(comment, get, waived, product_version, testcase, subject, + result_id, config_file): """ - Creates new waiver against test results. + Creates new waiver or retrieve recorded waivers against test results - Examples: + Examples to set a waiver: waiverdb-cli -r 47 -r 48 -p "fedora-28" -c "This is fine" or - waiverdb-cli -t dist.rpmdeplint -s '{"item": "qclib-1.3.1-3.fc28", - "type": "koji_build"}' - -p "fedora-28" -c "This is expected for non-x86 packages" + waiverdb-cli -t dist.rpmdeplint -s '{"item": "qclib-1.3.1-3.fc28", "type": "koji_build"}' -p "fedora-28" -c "This is expected for non-x86 packages" + + Example to retrieve waivers: + + waiverdb-cli --get -t dist.rpmdeplint -s '{"item": "qclib-1.3.1-3.fc28", "type": "koji_build"}' -p fedora-28 """ config = configparser.SafeConfigParser() @@ -120,6 +125,27 @@ def cli(comment, waived, product_version, testcase, subject, result_id, config_f }) api_url = config.get('waiverdb', 'api_url') + if get: + req = requests.get( + url='{0}/waivers/'.format(api_url.rstrip('/')), + params={'results': json.dumps(data_list)}, + timeout=60, + ) + if req.ok: + data = req.json() + cnt_waiver = len(data['data']) + if cnt_waiver == 1: + print('{0} waiver found'.format(cnt_waiver)) + else: + print('{0} waiver(s) found'.format(cnt_waiver)) + + for waiver in data['data']: + print('Waiver from {0}, created on {1} for: {2}'.format( + waiver['username'], waiver['timestamp'], + waiver['comment'])) + + return 0 + if auth_method == 'OIDC': # Try to import this now so the user gets immediate feedback if # it isn't installed