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

Gmail Search all mailboxes: retry mechanism for first time #36615

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
508d0c1
add retry mechanism
rshunim Oct 6, 2024
01c3d6a
dev version
rshunim Oct 6, 2024
c68c676
pre commit
rshunim Oct 6, 2024
3fbcee5
adding debug logs
rshunim Oct 7, 2024
c0fc7ac
RN
rshunim Oct 7, 2024
0e173c1
pre commit
rshunim Oct 7, 2024
26bd4b7
Update Packs/Gmail/Integrations/Gmail/Gmail.py
rshunim Oct 7, 2024
e8e0cb0
remove - dev
rshunim Oct 7, 2024
fc83b7e
Merge remote-tracking branch 'origin/Search_all_mailboxes_Gmail' into…
rshunim Oct 7, 2024
3bd2a99
pre-commit
rshunim Oct 7, 2024
d9055d6
edit RN
rshunim Oct 7, 2024
1803a04
CR comment
rshunim Oct 7, 2024
12986ee
Merge branch 'master' into Search_all_mailboxes_Gmail
rshunim Oct 7, 2024
53adc4e
Merge branch 'master' of github.com:demisto/content into Search_all_m…
rshunim Oct 8, 2024
94954ae
Merge remote-tracking branch 'origin/Search_all_mailboxes_Gmail' into…
rshunim Oct 8, 2024
60b63d4
another retry mechanism
rshunim Oct 13, 2024
52e2936
adding logs
rshunim Oct 13, 2024
0b8f350
Merged master into current branch.
Oct 13, 2024
2e0bee0
Bump pack from version Gmail to 1.3.26.
Oct 13, 2024
bc326d6
remove sleep since timeout
rshunim Oct 20, 2024
08c0eb1
Merge remote-tracking branch 'origin/Search_all_mailboxes_Gmail' into…
rshunim Oct 20, 2024
e604246
Merged master into current branch.
Oct 27, 2024
ac87e71
Bump pack from version Gmail to 1.3.27.
Oct 27, 2024
078fed2
Merged master into current branch.
Nov 7, 2024
92dba01
Bump pack from version Gmail to 1.3.28.
Nov 7, 2024
163bb9d
Merged master into current branch.
Nov 18, 2024
68370b8
Bump pack from version Gmail to 1.3.29.
Nov 18, 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
21 changes: 14 additions & 7 deletions Packs/Gmail/Integrations/Gmail/Gmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,6 @@ def get_millis_from_date(date, arg_name):


def cutting_for_batches(list_accounts: list) -> List[list]:

accounts: list = []
rest_accounts: list = []

Expand All @@ -845,13 +844,11 @@ def cutting_for_batches(list_accounts: list) -> List[list]:


def scheduled_commands_for_more_users(accounts: list, next_page_token: str) -> List[CommandResults]:

accounts_batches = cutting_for_batches(accounts)

command_results: list[CommandResults] = []
args = copy.deepcopy(demisto.args())
for batch in accounts_batches:

args.update({'list_accounts': batch})
command_results.append(
CommandResults(
Expand Down Expand Up @@ -907,7 +904,6 @@ def get_mailboxes(max_results: int, users_next_page_token: str = None):


def information_search_process(length_accounts: int, search_from: int | None, search_to: int | None) -> CommandResults:

if search_from is None or search_to is None:
readable_output = f'Searching the first {length_accounts} accounts'
search_from = 0
Expand Down Expand Up @@ -1350,7 +1346,6 @@ def search_in_mailboxes(accounts: list[str], only_return_account_names: bool) ->


def search_all_mailboxes():

args = demisto.args()
only_return_account_names = argToBoolean(args.get('show-only-mailboxes', 'true'))
list_accounts = argToList(args.get('list_accounts', ''))
Expand Down Expand Up @@ -1392,7 +1387,8 @@ def search_all_mailboxes():
search_all_mailboxes()


def search_command(mailbox: str = None, only_return_account_names: bool = False) -> dict[str, Any] | None:
def search_command(mailbox: str = None, only_return_account_names: bool = False, first_time: bool = True) -> dict[
rshunim marked this conversation as resolved.
Show resolved Hide resolved
str, Any] | None:
"""
Searches for Gmail records of a specified Google user.
"""
Expand Down Expand Up @@ -1428,8 +1424,19 @@ def search_command(mailbox: str = None, only_return_account_names: bool = False)
include_spam_trash, has_attachments, only_return_account_names,
)
except HttpError as err:
if only_return_account_names and err.status_code == 429:
if err.status_code == 500 and first_time:
# retry mechanism - try just one time more
demisto.debug(f'Gmail Integration: Got an error {err.status_code} for {user_id=}, trying again to search fot it')
search_command(mailbox, only_return_account_names, False)
elif (
err.status_code == 500
or (err.status_code == 429
and only_return_account_names)
):
demisto.debug(f'Gmail Integration: Got another time the {err.status_code} error for {user_id=}, '
f'continuing to the next user')
return {'Mailbox': mailbox, 'Error': {'message': str(err.error_details), 'status_code': err.status_code}}

raise

# In case the user wants only account list without content.
Expand Down
6 changes: 6 additions & 0 deletions Packs/Gmail/ReleaseNotes/1_3_25.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

#### Integrations

##### Gmail

- Added support for retry mechanism in ***gmail-search*** command when getting an error due to limited resources on Google's side.
2 changes: 1 addition & 1 deletion Packs/Gmail/pack_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Gmail",
"description": "Gmail API and user management (This integration replaces the Gmail functionality in the GoogleApps API and G Suite integration).",
"support": "xsoar",
"currentVersion": "1.3.24",
"currentVersion": "1.3.25",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down
Loading