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

Add an option to omit conversation with bot and scan entire account #57

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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
17 changes: 10 additions & 7 deletions hammer/reporting-remediation/bot/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,21 +184,21 @@ def scan_account(message, account_num, regions, security_features, tags):
}
resp = requests.post(api_url, json=request_body, headers=headers)
if resp.status_code != 200:
message.reply(f'Failed to start scan for account {account_num}, {resp.text}')
message.reply(f'Failed to start scan for account {account_num}, {resp.text}', in_thread=True)
return
message.reply(f'Scan for account {account_num} has been started. When the scan is finished,'
f'you will be notified with results.')
f'you will be notified with results.', in_thread=True)
request_id = resp.json()['request_id']
time_start = time.time()
while time.time() - time_start < 300:
resp = requests.get(api_url + '/' + request_id, headers=headers)
if resp.json()['scan_status'] == 'COMPLETE':
message.reply(format_scan_account_result(resp.json()['scan_results']))
message.reply(format_scan_account_result(resp.json()['scan_results']), in_thread=True)
return
if resp.json()['scan_status'] == 'FAILED':
return message.reply(f'Scan of account {account_num} is failed. Please try again later.')
return message.reply(f'Scan of account {account_num} is failed. Please try again later.', in_thread=True)
time.sleep(5)
return message.reply('Sorry, but current scan takes too long to finish.')
return message.reply('Sorry, but current scan takes too long to finish.', in_thread=True)


QUESTION_1 = '''
Expand Down Expand Up @@ -297,8 +297,11 @@ def get_current_question(thread):
return len(DIALOGS[thread]['answers'])


@respond_to('^scan account (?P<account_num>.*)$', re.IGNORECASE)
def start_scan_conversation(message, account_num):
@respond_to('^scan account (?P<account_num>\d{12}) (?P<all_account>--all)$', re.IGNORECASE)
@respond_to('^scan account (?P<account_num>\d{12})$', re.IGNORECASE)
def start_scan_conversation(message, account_num, all_account=None):
if all_account:
return scan_account(message, account_num, [], [], {})
try:
thread_ts = message.body['thread_ts']
except KeyError:
Expand Down