Skip to content

Commit 25865b3

Browse files
committed
PATCH: updating API env vars to match veracode api signing module. @mastermargie
1 parent b166d15 commit 25865b3

12 files changed

Lines changed: 67 additions & 44 deletions

File tree

.gitlab-ci.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,6 @@ SCA Test: # run SCA on any branch
7373

7474
script:
7575
- curl -sSL https://download.sourceclear.com/ci.sh | bash
76-
# | tee sca_results.txt
77-
#
78-
# artifacts:
79-
# paths:
80-
# - sca_results.txt
8176

8277
only:
8378
- dev

veracode/API/core.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,19 @@ def __init__(self, status_code, data, res):
2121
self.res = res
2222

2323
def __init__(self, end_point, api_version, server=None):
24-
self.__api_id = os.environ.get('VERACODE_API_ID', None)
25-
self.__api_secret = os.environ.get('VERACODE_API_SECRET', None)
26-
24+
self.__api_id = os.environ.get('VERACODE_API_KEY_ID', None)
25+
self.__api_secret = os.environ.get('VERACODE_API_KEY_SECRET', None)
26+
2727
if not (self.__api_id and self.__api_secret):
2828
self.profile = os.environ.get('VERACODE_API_PROFILE', 'DEFAULT')
2929
conf = configparser.ConfigParser()
3030
conf.read(os.path.expanduser('~/.veracode/credentials'))
31-
self.__api_id = conf.get(self.profile, 'VERACODE_API_ID')
32-
self.__api_secret = conf.get(self.profile, 'VERACODE_API_SECRET')
31+
self.__api_id = conf.get(self.profile, 'VERACODE_API_KEY_ID')
32+
self.__api_secret = conf.get(self.profile,
33+
'VERACODE_API_KEY_SECRET')
3334

34-
self.__api_server = server or 'https://analysiscenter.veracode.com/api/'
35+
self.__api_server = server or \
36+
'https://analysiscenter.veracode.com/api/'
3537
self.__end_point = end_point
3638
if api_version:
3739
self.__server = '/'.join(map(lambda x: str(x).rstrip('/'),
@@ -53,7 +55,8 @@ def __veracode_hmac(self, host, url, method):
5355
codecs.decode(self.__api_secret, 'hex_codec'),
5456
codecs.decode(nonce, 'hex_codec'), sha256).digest()
5557

56-
key_date = hmac.new(key_nonce, str(timestamp).encode(), sha256).digest()
58+
key_date = hmac.new(
59+
key_nonce, str(timestamp).encode(), sha256).digest()
5760
signature_key = hmac.new(
5861
key_date, 'vcode_request_version_1'.encode(), sha256).digest()
5962
signature = hmac.new(
@@ -75,7 +78,8 @@ def __prepared_request(self, method, query, file=None):
7578
files=file)
7679
prepared_request = request.prepare()
7780
prepared_request.headers['Authorization'] = self.__veracode_hmac(
78-
urlparse(self.__server).hostname, prepared_request.path_url, method)
81+
urlparse(self.__server).hostname,
82+
prepared_request.path_url, method)
7983
res = session.send(prepared_request)
8084

8185
logger.debug('{}, {}, COMPLETED'.format(self.__end_point, query))

veracode/SDK/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
# from veracode import log
2-
# logger = log.veracode_logger('veracode')
3-
41
from veracode.SDK import core, admin, flawreport, mitigation, results, sandbox, upload, exceptions

veracode/build.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ def __init__(self, obj=None, app=None):
5252
self._modules = []
5353

5454
if obj:
55-
self.obj = obj
5655
if hasattr(obj, 'build'):
5756
self.version = obj.build.version
5857

veracode/log.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
import os
33

44
def veracode_logger(name):
5-
formatter = logging.Formatter(fmt='%(asctime)s, %(levelname)s, %(message)s')
5+
formatter = logging.Formatter(
6+
fmt='%(asctime)s, %(levelname)s, %(message)s')
67
handler = logging.StreamHandler()
78
handler.setFormatter(formatter)
89
logger = logging.getLogger(name)

veracode/sandbox.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ def __init__(self, obj=None):
7676
self.customfield = obj.customfield
7777

7878
def __repr__(self):
79-
return "<Veracode Sandbox: name='{}', id={}>".format(self.name, self.id)
79+
return "<Veracode Sandbox: name='{}', id={}>".format(
80+
self.name, self.id)
8081

8182
def __bool__(self):
8283
return self.name is not None

veracode/utils/app/commands.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
from veracode.build import Build
77
from veracode.utils.report import display
88

9-
@click.group()
9+
@click.group(help='Perform actions on an application.')
1010
def app():
1111
pass
1212

1313

14-
@app.command()
14+
@app.command(help='List applications.')
1515
@click.option('--format', '-f',
1616
help='Output format.')
1717
def list(format='simple'):
@@ -20,10 +20,12 @@ def list(format='simple'):
2020
display(data=data, headers=headers, format=format)
2121

2222

23-
@app.command()
24-
@click.option('--name', '-n', required=True)
25-
@click.option('--criticality', '-c', required=True, type=click.Choice(
26-
[ 'Very High', 'High', 'Medium', 'Low', 'Very Low' ]))
23+
@app.command(help='Create a new Application.')
24+
@click.option('--name', '-n', required=True,
25+
help='Name of application to create.')
26+
@click.option('--criticality', '-c', required=True,
27+
type=click.Choice(['Very High', 'High', 'Medium', 'Low', 'Very Low']),
28+
help='Business criticality of new application.')
2729

2830
@click.option('--sandbox', '-s')
2931
def create(name, criticality, sandbox=None):
@@ -37,9 +39,9 @@ def create(name, criticality, sandbox=None):
3739
app.sandbox = sbx
3840

3941

40-
@app.command()
42+
@app.command(help='Delete an existing application.')
4143
@click.option('--name', '-n', required=True,
42-
help='Name of application to update')
44+
help='Name of application to update.')
4345
@click.confirmation_option('--force', '-f',
4446
help='Suppress prompt before removal.',
4547
prompt='Are you sure you want to delete this application')
@@ -48,7 +50,7 @@ def delete(name):
4850
return app.delete()
4951

5052

51-
@app.command()
53+
@app.command(help='Update an existing application.')
5254
@click.option('--name', '-n', required=True,
5355
help='Name of application to update.')
5456
@click.option('--rename', '-r',
@@ -57,7 +59,6 @@ def delete(name):
5759
[ 'Very High', 'High', 'Medium', 'Low', 'Very Low' ],
5860
case_sensitive=True), # update app to snake case so we can go -i
5961
help='New criticality for the application.')
60-
6162
def update(name, rename=None, criticality=None):
6263
# this isn't the right way to do this, google more
6364
if not (rename or criticality):
@@ -71,7 +72,7 @@ def update(name, rename=None, criticality=None):
7172
app.save()
7273

7374

74-
@app.command()
75+
@app.command(help='Launch a new SAST scan.')
7576
@click.option('--app', '-a', required=True,
7677
help='Name of the application.')
7778
@click.option('--files', '-f', required=True,

veracode/utils/cli.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
from .sandbox import commands as sandbox
44
from .user import commands as user
55
from .report import commands as report
6-
from veracode.log import veracode_logger
7-
logger = veracode_logger('veracode')
6+
7+
# import logging
8+
# logger = logging.getLogger('veracode')
89

910
@click.group()
1011
def main():

veracode/utils/report/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ def display(data, headers, format):
1616
user_data[header] = d
1717
json_data.append(user_data)
1818
click.echo(json.dumps(json_data, indent=4))
19+
elif format == 'list':
20+
for idx, header in enumerate(headers):
21+
click.echo('{0:20} {1}'.format(header, data[0][idx]))
1922
else:
2023
click.echo(tabulate(data, headers=headers, tablefmt=format))
2124

veracode/utils/report/commands.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,41 @@
22
from veracode.application import Application
33
from veracode.utils.report import display
44

5-
@click.group()
5+
@click.group(help='View application policy report(s).')
66
def report():
77
pass
88

9-
@report.command()
9+
@report.command(help='Print policy summary.')
1010
@click.option('--app', '-a', required=True,
1111
help='Name of the application.')
1212
@click.option('--sandbox', '-s',
1313
help='Name of the application sandbox.')
1414
@click.option('--build', '-b',
1515
help='Name of the application build.')
16-
def summary(app, sandbox=None, build=None):
16+
@click.option('--format', '-f', default='list',
17+
help='Output format.')
18+
def summary(app, sandbox=None, build=None, format=None):
1719
app = Application(name=app, sandbox=sandbox, build=build)
18-
print(app.build.report)
20+
report = app.build.report
21+
headers = ['Policy Name',
22+
'Policy Status',
23+
'Score',
24+
'Total Flaws',
25+
'Very High',
26+
'High',
27+
'Medium',
28+
'Low']
29+
data = [[
30+
report.policy_name,
31+
report.policy_compliance_status,
32+
report.static_analysis.score,
33+
report.flaw_status.total,
34+
report.flaw_status.sev_5_change,
35+
report.flaw_status.sev_4_change,
36+
report.flaw_status.sev_3_change,
37+
report.flaw_status.sev_2_change,
38+
]]
39+
display(data=data, headers=headers, format=format)
1940

2041
@report.command()
2142
def create():

0 commit comments

Comments
 (0)