Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to setuptools, make python3 compatible, and reducing chattiness #75

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
82dbed2
fix #66
ryran Jun 27, 2017
f5225cf
readme update
ryran Jun 27, 2017
0c7a6f4
all: Packaging for setuptools and making python3 compatible
kyle-walker Jul 23, 2019
581924e
setup: Change the formatting for RPM compatibility
kyle-walker Jul 23, 2019
442ad19
rhsecapi: Remove the "less" pager use
kyle-walker Jul 23, 2019
c58ae4e
all: Change the "See <>" URL to reflect the new location
kyle-walker Jul 23, 2019
059e69d
rhsecapi: Set the default log level to WARNING
kyle-walker Jul 24, 2019
251b71e
setup: Bump the version to 1.0.2
kyle-walker Jul 24, 2019
57f66ca
build: Add a rpkg build configuration and specfile
kyle-walker Jul 24, 2019
7c9f756
All: Remove IAVAs as a query subject
kyle-walker Jul 25, 2019
8b91253
All: Remove the "python2" shebang callouts
kyle-walker Jul 25, 2019
bed8552
.gitignore; Omit the .vscode directory
kyle-walker Aug 18, 2021
4cbc406
rhsecapi: Bump the version to 1.0.3
kyle-walker Aug 18, 2021
b140adf
spec: Drop the python3-argparse Requires
kyle-walker Aug 18, 2021
33100bb
spec: Require the lib when installing the cli
kyle-walker Jan 7, 2022
3aff8af
rhsecapi: Fix the version
kyle-walker Jan 7, 2022
37f7652
git: Add .venv to .gitignore
kyle-walker Apr 3, 2024
dd7fd49
packaging: Add a requirements.txt
kyle-walker Apr 3, 2024
ac75afe
packaging: Bump the version to 1.0.5
kyle-walker Apr 3, 2024
16434e3
packaging: Remove rpkg entirely
kyle-walker Apr 3, 2024
c21874a
Initialized to use tito.
kyle-walker Apr 3, 2024
658618a
Automatic commit of package [rhsecapi] release [1.0.6-1].
kyle-walker Apr 3, 2024
6de389d
Merge pull request #1 from kyle-walker/move-to-tito
kyle-walker Apr 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ celerybeat-schedule
.env

# virtualenv
.venv/
venv/
ENV/

Expand All @@ -87,3 +88,6 @@ ENV/

# Rope project settings
.ropeproject

#
.vscode/launch.json
3 changes: 3 additions & 0 deletions .tito/packages/.readme
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
the .tito/packages directory contains metadata files
named after their packages. Each file has the latest tagged
version and the project's relative directory.
1 change: 1 addition & 0 deletions .tito/packages/rhsecapi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0.6-1 ./
6 changes: 6 additions & 0 deletions .tito/tito.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[buildconfig]
builder = tito.builder.Builder
tagger = tito.tagger.VersionTagger
changelog_do_not_remove_cherrypick = 0
changelog_format = %s (%ae)

139 changes: 19 additions & 120 deletions README.md

Large diffs are not rendered by default.

57 changes: 15 additions & 42 deletions rhsecapi.py → bin/rhsecapi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python2
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# PYTHON_ARGCOMPLETE_OK
#-------------------------------------------------------------------------------
Expand Down Expand Up @@ -46,8 +46,8 @@
# Globals
prog = 'rhsecapi'
vers = {}
vers['version'] = '1.0.0_rc10'
vers['date'] = '2017/01/05'
vers['version'] = '1.0.5'
vers['date'] = '2024/04/03'


# Logging
Expand Down Expand Up @@ -151,7 +151,7 @@ def parse_args():
epilog = (
"VERSION:\n"
" {0}\n"
" See <http://github.com/ryran/rhsecapi> to report bugs or RFEs").format(version)
" See <https://github.com/RedHatOfficial/rhsecapi> to report bugs or RFEs").format(version)
fmt = lambda prog: CustomFormatter(prog)
p = argparse.ArgumentParser(
prog=prog,
Expand Down Expand Up @@ -179,7 +179,7 @@ def parse_args():
help="Narrow down results by severity rating (specify one of 'low', 'moderate', 'important', or 'critical')")
g_listByAttr.add_argument(
'--q-product', metavar="PRODUCT",
help="Narrow down results by product name via case-insensitive regex (e.g.: 'linux 7' or openstack platform [89]'); the API checks this against the 'FIXED_RELEASES' field so will only match CVEs where PRODUCT matches the 'product_name' of some released errata")
help="Narrow down results by product name via case-insensitive regex (e.g.: 'linux 7' or 'openstack platform [89]'); the API checks this against the 'FIXED_RELEASES' field so will only match CVEs where PRODUCT matches the 'product_name' of some released errata")
g_listByAttr.add_argument(
'--q-package', metavar="PKG",
help="Narrow down results by package name (e.g.: 'samba' or 'thunderbird')")
Expand All @@ -205,20 +205,14 @@ def parse_args():
'--q-raw', metavar="RAWQUERY", action='append',
help="Narrow down results by RAWQUERY (e.g.: '--q-raw a=x --q-raw b=y'); this allows passing arbitrary params (e.g. something new that is unknown to {0})".format(prog))
# New group
g_listByIava = p.add_argument_group(
'RETRIEVE SPECIFIC IAVAS')
g_listByIava.add_argument(
'-i', '--iava', dest='iavas', metavar='YYYY-?-NNNN', action='append',
help="Retrieve notice details for an IAVA number; specify option multiple times to retrieve multiple IAVAs at once (use below --extract-cves option to lookup mapped CVEs)")
# New group
g_getCve = p.add_argument_group(
'RETRIEVE SPECIFIC CVES')
g_getCve.add_argument(
'cves', metavar="CVE-YYYY-NNNN", nargs='*',
help="Retrieve a CVE or list of CVEs (e.g.: 'CVE-2016-5387'); note that case-insensitive regex-matching is done -- extra characters & duplicate CVEs will be discarded")
g_getCve.add_argument(
'-x', '--extract-cves', action='store_true',
help="Extract CVEs from search query (as initiated by at least one of the --q-xxx options or the --iava option)")
help="Extract CVEs from search query (as initiated by at least one of the --q-xxx options)")
g_getCve.add_argument(
'-0', '--stdin', action='store_true',
help="Extract CVEs from stdin (CVEs will be matched by case-insensitive regex '{0}' and duplicates will be discarded); note that terminal width auto-detection is not possible in this mode and WIDTH defaults to '70' (but can be overridden with '--width')".format(rhsda.cve_regex_string))
Expand All @@ -228,7 +222,7 @@ def parse_args():
g_cveDisplay0 = g_cveDisplay.add_mutually_exclusive_group()
g_cveDisplay0.add_argument(
'-f', '--fields', metavar="FIELDS", default='BASE',
help="Customize field display via comma-separated case-insensitive list (default: {0}); see --all-fields option for full list of official API-provided fields; shorter field aliases: {1}; optionally prepend FIELDS with plus (+) sign to add fields to the default (e.g., '-f +iava,cvss3') or a caret (^) to remove fields from all-fields (e.g., '-f ^mitigation,severity')".format(", ".join(rhsda.cveFields.base), ", ".join(rhsda.cveFields.aliases_printable)))
help="Customize field display via comma-separated case-insensitive list (default: {0}); see --all-fields option for full list of official API-provided fields; shorter field aliases: {1}; optionally prepend FIELDS with plus (+) sign to add fields to the default (e.g., '-f +cvss3') or a caret (^) to remove fields from all-fields (e.g., '-f ^mitigation,severity')".format(", ".join(rhsda.cveFields.base), ", ".join(rhsda.cveFields.aliases_printable)))
g_cveDisplay0.add_argument(
'-a', '--all-fields', dest='fields', action='store_const',
const='ALL',
Expand Down Expand Up @@ -256,7 +250,7 @@ def parse_args():
'-c', '--count', action='store_true',
help="Exit after printing CVE counts")
g_general.add_argument(
'-l', '--loglevel', choices=['debug','info','notice','warning'], default='notice',
'-l', '--loglevel', choices=['debug','info','notice','warning'], default='warning',
help="Configure logging level threshold; lower from the default of 'notice' to see extra details printed to stderr")
g_general.add_argument(
'-t', '--threads', metavar="THREDS", type=int, default=rhsda.numThreadsDefault,
Expand All @@ -281,12 +275,7 @@ def parse_args():
argcomplete.autocomplete(p)
o = p.parse_args()
if o.showHelp:
from tempfile import NamedTemporaryFile
from subprocess import call
tmp = NamedTemporaryFile(prefix='{0}-help-'.format(prog), suffix='.txt')
p.print_help(file=tmp)
tmp.flush()
call(['less', tmp.name])
p.print_help()
sys.exit()
# Add search params to dict
o.searchParams = {
Expand All @@ -312,9 +301,6 @@ def parse_args():
o.doSearch = False
else:
o.doSearch = True
if o.iavas:
print("{0}: error: --q-xxx options not allowed in concert with -i/--iava".format(prog), file=sys.stderr)
sys.exit(1)
if o.cves or o.stdin:
print("{0}: error: --q-xxx options not allowed in concert with CVE args".format(prog), file=sys.stderr)
sys.exit(1)
Expand All @@ -326,8 +312,8 @@ def parse_args():
found = rhsda.extract_cves_from_input(sys.stdin)
o.cves.extend(found)
# If no search (--q-xxx) and no CVEs mentioned
if not o.showUsage and not (o.doSearch or o.cves or o.iavas):
logger.error("Must specify CVEs/IAVAs to retrieve or a search to perform (--q-xxx opts)")
if not o.showUsage and not (o.doSearch or o.cves):
logger.error("Must specify CVEs to retrieve or a search to perform (--q-xxx opts)")
o.showUsage = True
if o.showUsage:
p.print_usage()
Expand All @@ -346,11 +332,12 @@ def parse_args():

def main(opts):
apiclient = rhsda.ApiClient(opts.loglevel)

from os import environ
if environ.has_key('RHSDA_URL') and environ['RHSDA_URL'].startswith('http'):
if environ.get('RHSDA_URL', '').startswith('http'):
apiclient.cfg.apiUrl = environ['RHSDA_URL']

searchOutput = ""
iavaOutput = ""
cveOutput = ""
if opts.doSearch:
if opts.extract_cves:
Expand All @@ -366,18 +353,6 @@ def main(opts):
if not opts.pastebin:
print(file=sys.stderr)
print(searchOutput, end="")
if opts.iavas:
logger.debug("IAVAs: {0}".format(opts.iavas))
if opts.extract_cves:
result = apiclient.mget_iavas(iavas=opts.iavas, numThreads=opts.threads, onlyCount=opts.count, outFormat='list')
opts.cves.extend(result)
elif opts.count:
result = apiclient.mget_iavas(iavas=opts.iavas, numThreads=opts.threads, onlyCount=opts.count)
else:
iavaOutput = apiclient.mget_iavas(iavas=opts.iavas, numThreads=opts.threads, outFormat=opts.outFormat, urls=opts.printUrls)
if not opts.pastebin:
print(file=sys.stderr)
print(iavaOutput, end="")
if opts.cves:
originalCount = len(opts.cves)
# Converting to a set removes duplicates
Expand All @@ -389,16 +364,14 @@ def main(opts):
logger.log(25, "Skipping CVE retrieval due to --dryrun; would have retrieved: {0}".format(len(opts.cves)))
cveOutput = " ".join(opts.cves) + "\n"
else:
if iavaOutput:
print(file=sys.stderr)
cveOutput = apiclient.mget_cves(cves=opts.cves, numThreads=opts.threads, onlyCount=opts.count, outFormat=opts.outFormat, urls=opts.printUrls, fields=opts.fields, wrapWidth=opts.wrapWidth, product=opts.product)
if opts.count:
return
if opts.pastebin:
opts.p_lang = 'text'
if opts.json:
opts.p_lang = 'Python'
data = searchOutput + iavaOutput + cveOutput
data = searchOutput + cveOutput
try:
response = fpaste_it(inputdata=data, author=prog, lang=opts.p_lang, expire=opts.pexpire)
except ValueError as e:
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requests
Loading