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

Bugfix/sc deplay issue #271 #275

Merged
merged 2 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 7 additions & 5 deletions tenb2jira/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def tenable_table(config: dict) -> Table:
table.add_row('Secret key', f'{skey[:4]}...{skey[-4:]}')
if platform == 'tsc':
table.add_row('Security Center URL', config['tenable']['url'])
table.add_row('Page Size', config['tenable']['tsc_page_size'])
table.add_row('Page Size', str(config['tenable']['tsc_page_size']))
elif platform == 'tvm':
table.add_row('TVM URL', config['tenable']['url'])
table.add_row('Export Chunk Size',
Expand Down Expand Up @@ -103,7 +103,7 @@ def validate(configfile: Path):
@app.command()
def build(configfile: Path,
update: bool = True,
verbose: bool = False
verbose: bool = False,
):
"""
Runs the initial configuration for the Jira project.
Expand All @@ -126,20 +126,22 @@ def build(configfile: Path,
@app.command()
def sync(configfile: Path,
update: bool = True,
verbose: bool = False
verbose: bool = False,
cleanup: bool = True,
ignore_last_run: bool = False,
):
"""
Perform the sync between Tenable & Jira
"""
setup_logging(verbose)
with configfile.open('r', encoding='utf-8') as fobj:
config = tomlkit.load(fobj)
processor = Processor(config)
processor = Processor(config, ignore_last_run=ignore_last_run)
console.print(Columns([tenable_table(config),
jira_table(config)
]))
console.print(field_definition_table(processor.jira))
processor.sync()
processor.sync(cleanup=cleanup)
if update:
with open(configfile, 'w', encoding='utf-8') as f:
tomlkit.dump(config, f)
16 changes: 12 additions & 4 deletions tenb2jira/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,15 @@ class Processor:
plugin_id: str
closed_map: list[str]

def __init__(self, config: dict):
def __init__(self, config: dict, ignore_last_run: bool = False):
dburi = f'sqlite:///{config["mapping_database"].get("path")}'

# For situations where we will need to ignore the last_run variable,
# This will pull it from the config, forcing the integration to use
# the vuln_age attribute that is used in the initial run.
if ignore_last_run and 'last_run' in config['tenable']:
config['tenable'].pop('last_run')

self.last_run = arrow.get(config['tenable'].get('last_run', 0))
self.config = config
self.jira = Jira(config)
Expand Down Expand Up @@ -399,7 +406,7 @@ def finding_job(self, finding: dict):
self.upsert_subtask(s=session, task_id=task_id, finding=finding)
session.commit()

def sync(self):
def sync(self, cleanup: bool = True):
"""
Tenable to Jira Synchronization method.
"""
Expand Down Expand Up @@ -458,5 +465,6 @@ def sync(self):

self.engine.dispose()
# Delete the mapping database.
with Path(self.config["mapping_database"].get("path")) as p:
p.unlink()
if cleanup:
with Path(self.config["mapping_database"].get("path")) as p:
p.unlink()
62 changes: 62 additions & 0 deletions tests/test_processor.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from copy import copy
import pytest
import responses
from responses import matchers
Expand Down Expand Up @@ -64,6 +65,67 @@ def processor(example_config):
return Processor(example_config)


@responses.activate
def test_ignore_last_run(example_config):
responses.get('https://not-jira/rest/api/3/project/VULN',
json={}
)
responses.get('https://not-jira/rest/api/3/screens',
json={'values': [{'id': 1}], 'total': 1}
)
responses.get('https://not-jira/rest/api/3/screens/1/tabs',
json=[
{'name': 'Vulnerability', 'id': 1},
{'name': 'Asset', 'id': 1}
]
)
responses.post('https://not-jira/rest/api/3/screens/1/tabs',
json={'id': 1}
)
responses.post('https://not-jira/rest/api/3/screens/1/tabs/1/fields')
responses.get('https://not-jira/rest/api/3/screens/1/tabs/1/fields',
json=[
{'id': 'customfield_1'},
{'id': 'customfield_2'},
{'id': 'customfield_3'},
{'id': 'customfield_4'},
{'id': 'customfield_5'},
{'id': 'customfield_6'},
{'id': 'customfield_7'},
{'id': 'customfield_8'},
{'id': 'customfield_9'},
{'id': 'customfield_10'},
{'id': 'customfield_11'},
{'id': 'customfield_12'},
{'id': 'customfield_13'},
{'id': 'customfield_14'},
{'id': 'customfield_15'},
{'id': 'customfield_16'},
{'id': 'customfield_17'},
{'id': 'customfield_18'},
{'id': 'customfield_19'},
{'id': 'customfield_20'},
{'id': 'customfield_21'},
{'id': 'customfield_22'},
{'id': 'customfield_23'},
{'id': 'customfield_24'},
{'id': 'customfield_25'},
{'id': 'customfield_26'},
{'id': 'customfield_27'},
{'id': 'customfield_28'},
{'id': 'customfield_29'},
{'id': 'customfield_30'},
])
responses.get('https://not-tenb/rest/system',
json={
'error_code': None,
'response': {}
})
last_run_config = copy(example_config)
last_run_config['tenable']['last_run'] = 1234567890
p = Processor(last_run_config, ignore_last_run=True)
assert p.config == example_config

def test_init(processor, example_config):
assert processor.config == example_config

Expand Down
Loading