Skip to content

Commit

Permalink
Debug log dropbox event collector (#37494)
Browse files Browse the repository at this point in the history
* release notes and precommit

* Update Packs/Dropbox/Integrations/DropboxEventCollector/DropboxEventCollector.py

Co-authored-by: Moshe Eichler <[email protected]>

* Update Packs/Dropbox/Integrations/DropboxEventCollector/DropboxEventCollector.py

Co-authored-by: Moshe Eichler <[email protected]>

* Update Packs/Dropbox/Integrations/DropboxEventCollector/DropboxEventCollector.py

Co-authored-by: Moshe Eichler <[email protected]>

* Update Packs/Dropbox/Integrations/DropboxEventCollector/DropboxEventCollector.py

Co-authored-by: Moshe Eichler <[email protected]>

* Update Packs/Dropbox/Integrations/DropboxEventCollector/DropboxEventCollector.py

Co-authored-by: Moshe Eichler <[email protected]>

* Update Packs/Dropbox/Integrations/DropboxEventCollector/DropboxEventCollector.py

Co-authored-by: Moshe Eichler <[email protected]>

* Update Packs/Dropbox/Integrations/DropboxEventCollector/DropboxEventCollector.py

Co-authored-by: Moshe Eichler <[email protected]>

* Update Packs/Dropbox/Integrations/DropboxEventCollector/DropboxEventCollector.py

Co-authored-by: Moshe Eichler <[email protected]>

* init of a var

* no cover on the logs

* pre commit

---------

Co-authored-by: Moshe Eichler <[email protected]>
  • Loading branch information
omerKarkKatz and MosheEichler authored Dec 2, 2024
1 parent 05ca342 commit 2bcefd8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def __init__(

def set_request_filter(self, cursor: str):
if 'continue' not in str(self.request.url):
demisto.info('continue not in request url')
self.request.url = parse_obj_as(AnyUrl, f'{str(self.request.url).removesuffix("/")}/continue')

self.request.data = json.dumps({'cursor': cursor})
Expand All @@ -55,6 +56,7 @@ def get_access_token(self):
verify=self.request.verify,
)
response = self.call(request)
demisto.debug(f'Send request to obtain access_token get status code: {response.status_code}') # pragma: no cover
self.request.headers['Authorization'] = f'Bearer {response.json()["access_token"]}'
self.request.url = parse_obj_as(AnyUrl, f'{str(self.request.url).removesuffix("/")}/2/team_log/get_events')

Expand All @@ -79,7 +81,7 @@ def _iter_events(self):
if results.get('has_more'):
self.client.set_request_filter(results.get('cursor'))
demisto.debug(
f'Setting the next request filter {results.get("cursor")}'
f'Setting the next request filter {results.get("cursor")}' # pragma: no cover
)
results = self.client.call(self.client.request).json()
else:
Expand All @@ -88,11 +90,12 @@ def _iter_events(self):

# ----------------------------------------- Authentication Functions -----------------------------------------

def start_auth_command(base_url: str, app_key: str) -> CommandResults:
def start_auth_command(base_url: str, app_key: str) -> CommandResults: # pragma: no cover
url = f'https://www.dropbox.com/oauth2/authorize?client_id={app_key}&token_access_type=offline&response_type=code'
message = f"""### Authorization instructions
1. To sign in, use a web browser to open the page [{url}]({url})
2. Run the **!dropbox-auth-complete** command with the code returned from Dropbox in the War Room."""
demisto.debug('start auth command')
return CommandResults(readable_output=message)


Expand All @@ -102,17 +105,20 @@ def complete_auth_command(code: str, credentials: Credentials, base_url: str, in
'code': code,
}
auth = (credentials.identifier or '', credentials.password)

redable_output = ''
response = requests.post(f'{base_url}/oauth2/token', data=data, auth=auth, verify=insecure)
if response.ok:
demisto.setIntegrationContext({'refresh_token': response.json()['refresh_token']})
readable_output = '✅ Authorization completed successfully.'
else:
return CommandResults(readable_output=f'❌ Authorization completed failed. {response.text}')
readable_output = f'❌ Authorization completed failed. {response.text}'

return CommandResults(readable_output='✅ Authorization completed successfully.')
demisto.debug(f'Complete auth command {readable_output=}') # pragma: no cover
return CommandResults(readable_output=redable_output)


def reset_auth_command() -> CommandResults:
demisto.debug('resetting integration context to empty dict.') # pragma: no cover
set_integration_context({})
message = 'Authorization was reset successfully. Run **!dropbox-auth-start** to start the authentication process.'
return CommandResults(readable_output=message)
Expand Down Expand Up @@ -151,6 +157,7 @@ def main(command: str, demisto_params: dict):
return_results(complete_auth_command(str(demisto_params.get('code')), credentials, base_url, insecure))

elif not demisto.getIntegrationContext().get('refresh_token'):
demisto.debug('Integration getIntegrationContext.get(refresh_token) is empty run auth start.') # pragma: no cover
return_results(CommandResults(readable_output='Please run the **!dropbox-auth-start** command first'))

elif command == 'dropbox-auth-reset':
Expand All @@ -169,7 +176,7 @@ def main(command: str, demisto_params: dict):

if events:
last_run = get_events.get_last_run(events[-1])
demisto.debug(f'Set last run to {last_run}')
demisto.debug(f'Set last run to {last_run}') # pragma: no cover.
demisto.setLastRun(last_run)

if command == 'dropbox-get-events':
Expand All @@ -182,7 +189,9 @@ def main(command: str, demisto_params: dict):
return_results(command_results)

except Exception as e:
return_error(str(e))
return_error(
f'An error was returned from dropbox event collector while executing {command} command. error: {str(e)}'
)


if __name__ in ('__main__', '__builtin__', 'builtins'):
Expand Down
6 changes: 6 additions & 0 deletions Packs/Dropbox/ReleaseNotes/1_1_5.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

#### Integrations

##### Dropbox Event Collector

- Documentation and metadata improvements.
2 changes: 1 addition & 1 deletion Packs/Dropbox/pack_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Dropbox",
"description": "Use the Dropbox integration to fetch events",
"support": "xsoar",
"currentVersion": "1.1.4",
"currentVersion": "1.1.5",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down

0 comments on commit 2bcefd8

Please sign in to comment.