From 122224cc460c6e753e3da08803b329f9b63eca86 Mon Sep 17 00:00:00 2001 From: Bargenish Date: Wed, 7 Apr 2021 15:45:25 +0300 Subject: [PATCH] Added support for auto cache update (#12062) * Replaced demisto.set/getIntegrationContext with the wrapper functions from CSP set/get_integration_context. * Reverted docker update for MicrosoftTeams.yml and MicrosoftManagementActivity.yml because of compatibility issues in pyjwt * Updated RN * Check #1 --- .../AzureLogAnalytics/AzureLogAnalytics.py | 2 +- Packs/AzureLogAnalytics/ReleaseNotes/1_0_8.md | 4 ++ Packs/AzureLogAnalytics/pack_metadata.json | 2 +- .../AzureSentinel/AzureSentinel.py | 2 +- Packs/AzureSentinel/ReleaseNotes/1_0_9.md | 4 ++ Packs/AzureSentinel/pack_metadata.json | 2 +- .../MicrosoftGraphListener.py | 2 +- .../MicrosoftGraphListener.yml | 2 +- .../ReleaseNotes/1_0_14.md | 5 +++ .../MicrosoftGraphListener/pack_metadata.json | 2 +- .../MicrosoftManagementActivity.py | 2 +- .../ReleaseNotes/1_1_10.md | 4 ++ .../pack_metadata.json | 2 +- .../MicrosoftTeams/MicrosoftTeams.py | 41 +++++++++---------- Packs/MicrosoftTeams/ReleaseNotes/1_1_5.md | 4 ++ Packs/MicrosoftTeams/pack_metadata.json | 2 +- 16 files changed, 51 insertions(+), 31 deletions(-) create mode 100644 Packs/AzureLogAnalytics/ReleaseNotes/1_0_8.md create mode 100644 Packs/AzureSentinel/ReleaseNotes/1_0_9.md create mode 100644 Packs/MicrosoftGraphListener/ReleaseNotes/1_0_14.md create mode 100644 Packs/MicrosoftManagementActivity/ReleaseNotes/1_1_10.md create mode 100644 Packs/MicrosoftTeams/ReleaseNotes/1_1_5.md diff --git a/Packs/AzureLogAnalytics/Integrations/AzureLogAnalytics/AzureLogAnalytics.py b/Packs/AzureLogAnalytics/Integrations/AzureLogAnalytics/AzureLogAnalytics.py index bb3446603953..8e0be58e78b9 100644 --- a/Packs/AzureLogAnalytics/Integrations/AzureLogAnalytics/AzureLogAnalytics.py +++ b/Packs/AzureLogAnalytics/Integrations/AzureLogAnalytics/AzureLogAnalytics.py @@ -30,7 +30,7 @@ def __init__(self, self_deployed, refresh_token, auth_and_token_url, enc_key, re subscription_id, resource_group_name, workspace_name, verify, proxy): tenant_id = refresh_token if self_deployed else '' - refresh_token = (demisto.getIntegrationContext().get('current_refresh_token') or refresh_token) + refresh_token = get_integration_context().get('current_refresh_token') or refresh_token base_url = f'https://management.azure.com/subscriptions/{subscription_id}/resourceGroups/' \ f'{resource_group_name}/providers/Microsoft.OperationalInsights/workspaces/{workspace_name}' self.ms_client = MicrosoftClient( diff --git a/Packs/AzureLogAnalytics/ReleaseNotes/1_0_8.md b/Packs/AzureLogAnalytics/ReleaseNotes/1_0_8.md new file mode 100644 index 000000000000..8c378a89bd59 --- /dev/null +++ b/Packs/AzureLogAnalytics/ReleaseNotes/1_0_8.md @@ -0,0 +1,4 @@ + +#### Integrations +##### Azure Log Analytics (Beta) +- Added support for cache to be updated automatically on token expiration. \ No newline at end of file diff --git a/Packs/AzureLogAnalytics/pack_metadata.json b/Packs/AzureLogAnalytics/pack_metadata.json index 1d823f6237b4..1073af8f8dbc 100644 --- a/Packs/AzureLogAnalytics/pack_metadata.json +++ b/Packs/AzureLogAnalytics/pack_metadata.json @@ -2,7 +2,7 @@ "name": "Azure Log Analytics", "description": "Log Analytics is a service that helps you collect and analyze data generated by resources in your cloud and on-premises environments.", "support": "xsoar", - "currentVersion": "1.0.7", + "currentVersion": "1.0.8", "author": "Cortex XSOAR", "url": "https://www.paloaltonetworks.com/cortex", "email": "", diff --git a/Packs/AzureSentinel/Integrations/AzureSentinel/AzureSentinel.py b/Packs/AzureSentinel/Integrations/AzureSentinel/AzureSentinel.py index b9df8c4d023d..16ab52db8026 100644 --- a/Packs/AzureSentinel/Integrations/AzureSentinel/AzureSentinel.py +++ b/Packs/AzureSentinel/Integrations/AzureSentinel/AzureSentinel.py @@ -39,7 +39,7 @@ def __init__(self, self_deployed, refresh_token, auth_and_token_url, enc_key, re subscription_id, resource_group_name, workspace_name, verify, proxy): tenant_id = refresh_token if self_deployed else '' - refresh_token = (demisto.getIntegrationContext().get('current_refresh_token') or refresh_token) + refresh_token = get_integration_context().get('current_refresh_token') or refresh_token base_url = f'https://management.azure.com/subscriptions/{subscription_id}/' \ f'resourceGroups/{resource_group_name}/providers/Microsoft.OperationalInsights/workspaces/' \ f'{workspace_name}/providers/Microsoft.SecurityInsights' diff --git a/Packs/AzureSentinel/ReleaseNotes/1_0_9.md b/Packs/AzureSentinel/ReleaseNotes/1_0_9.md new file mode 100644 index 000000000000..128fe7374b03 --- /dev/null +++ b/Packs/AzureSentinel/ReleaseNotes/1_0_9.md @@ -0,0 +1,4 @@ + +#### Integrations +##### Azure Sentinel (Beta) +- Added support for cache to be updated automatically on token expiration. diff --git a/Packs/AzureSentinel/pack_metadata.json b/Packs/AzureSentinel/pack_metadata.json index 96e98a8ecceb..25e687890bd2 100644 --- a/Packs/AzureSentinel/pack_metadata.json +++ b/Packs/AzureSentinel/pack_metadata.json @@ -2,7 +2,7 @@ "name": "AzureSentinel", "description": "Azure Sentinel is a cloud-native security information and event manager (SIEM) platform that uses built-in AI to help analyze large volumes of data across an enterprise.", "support": "xsoar", - "currentVersion": "1.0.8", + "currentVersion": "1.0.9", "author": "Cortex XSOAR", "url": "https://www.paloaltonetworks.com/cortex", "email": "", diff --git a/Packs/MicrosoftGraphListener/Integrations/MicrosoftGraphListener/MicrosoftGraphListener.py b/Packs/MicrosoftGraphListener/Integrations/MicrosoftGraphListener/MicrosoftGraphListener.py index 18c665ab9a74..4f85a2da8b99 100644 --- a/Packs/MicrosoftGraphListener/Integrations/MicrosoftGraphListener/MicrosoftGraphListener.py +++ b/Packs/MicrosoftGraphListener/Integrations/MicrosoftGraphListener/MicrosoftGraphListener.py @@ -819,7 +819,7 @@ def main(): # params related to oproxy # In case the script is running for the first time, refresh token is retrieved from integration parameters, # in other case it's retrieved from integration context. - refresh_token = (demisto.getIntegrationContext().get('current_refresh_token') or refresh_token) + refresh_token = get_integration_context().get('current_refresh_token') or refresh_token client = MsGraphClient(self_deployed, tenant_id, auth_and_token_url, enc_key, app_name, base_url, use_ssl, proxy, ok_codes, refresh_token, mailbox_to_fetch, folder_to_fetch, first_fetch_interval, diff --git a/Packs/MicrosoftGraphListener/Integrations/MicrosoftGraphListener/MicrosoftGraphListener.yml b/Packs/MicrosoftGraphListener/Integrations/MicrosoftGraphListener/MicrosoftGraphListener.yml index 5182d5f68e06..30d357e86ae4 100644 --- a/Packs/MicrosoftGraphListener/Integrations/MicrosoftGraphListener/MicrosoftGraphListener.yml +++ b/Packs/MicrosoftGraphListener/Integrations/MicrosoftGraphListener/MicrosoftGraphListener.yml @@ -378,7 +378,7 @@ script: description: Tests connectivity of the email. execution: false name: msgraph-mail-test - dockerimage: demisto/crypto:1.0.0.12979 + dockerimage: demisto/crypto:1.0.0.18288 isfetch: true longRunning: false longRunningPort: false diff --git a/Packs/MicrosoftGraphListener/ReleaseNotes/1_0_14.md b/Packs/MicrosoftGraphListener/ReleaseNotes/1_0_14.md new file mode 100644 index 000000000000..cf2741352192 --- /dev/null +++ b/Packs/MicrosoftGraphListener/ReleaseNotes/1_0_14.md @@ -0,0 +1,5 @@ + +#### Integrations +##### Microsoft Graph Mail Single User +- Added support for cache to be updated automatically on token expiration. +- Updated the Docker image to: *demisto/crypto:1.0.0.18288* diff --git a/Packs/MicrosoftGraphListener/pack_metadata.json b/Packs/MicrosoftGraphListener/pack_metadata.json index bd9ea3af4484..70e22e7c4029 100644 --- a/Packs/MicrosoftGraphListener/pack_metadata.json +++ b/Packs/MicrosoftGraphListener/pack_metadata.json @@ -2,7 +2,7 @@ "name": "Microsoft Graph Mail Single User", "description": "Microsoft Graph grants Demisto authorized access to a user's Microsoft Outlook mail data in a personal account or organization account.", "support": "xsoar", - "currentVersion": "1.0.13", + "currentVersion": "1.0.14", "author": "Cortex XSOAR", "url": "https://www.paloaltonetworks.com/cortex", "email": "", diff --git a/Packs/MicrosoftManagementActivity/Integrations/MicrosoftManagementActivity/MicrosoftManagementActivity.py b/Packs/MicrosoftManagementActivity/Integrations/MicrosoftManagementActivity/MicrosoftManagementActivity.py index 9e0014c23e90..80164ae7c72f 100644 --- a/Packs/MicrosoftManagementActivity/Integrations/MicrosoftManagementActivity/MicrosoftManagementActivity.py +++ b/Packs/MicrosoftManagementActivity/Integrations/MicrosoftManagementActivity/MicrosoftManagementActivity.py @@ -524,7 +524,7 @@ def main(): auth_id = params['auth_id'] enc_key = params['enc_key'] - refresh_token = (demisto.getIntegrationContext().get('current_refresh_token') or refresh_token) + refresh_token = get_integration_context().get('current_refresh_token') or refresh_token client = Client( base_url=base_url, diff --git a/Packs/MicrosoftManagementActivity/ReleaseNotes/1_1_10.md b/Packs/MicrosoftManagementActivity/ReleaseNotes/1_1_10.md new file mode 100644 index 000000000000..7afdfaa017ad --- /dev/null +++ b/Packs/MicrosoftManagementActivity/ReleaseNotes/1_1_10.md @@ -0,0 +1,4 @@ + +#### Integrations +##### Microsoft Management Activity API (O365 Azure Events) +- Added support for cache to be updated automatically on token expiration. \ No newline at end of file diff --git a/Packs/MicrosoftManagementActivity/pack_metadata.json b/Packs/MicrosoftManagementActivity/pack_metadata.json index 2a01e3a82c1a..030899eb13ac 100644 --- a/Packs/MicrosoftManagementActivity/pack_metadata.json +++ b/Packs/MicrosoftManagementActivity/pack_metadata.json @@ -2,7 +2,7 @@ "name": "Microsoft Management Activity API (O365/Azure Events)", "description": "An integration for Microsoft's management activity API, which enables you to fetch content records and manage your subscriptions.", "support": "xsoar", - "currentVersion": "1.1.9", + "currentVersion": "1.1.10", "author": "Cortex XSOAR", "url": "https://www.paloaltonetworks.com/cortex", "email": "", diff --git a/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.py b/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.py index 9a58d4489f62..862b47a88f14 100644 --- a/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.py +++ b/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.py @@ -387,7 +387,7 @@ def get_bot_access_token() -> str: Retrieves Bot Framework API access token, either from cache or from Microsoft :return: The Bot Framework API access token """ - integration_context: dict = demisto.getIntegrationContext() + integration_context: dict = get_integration_context() access_token: str = integration_context.get('bot_access_token', '') valid_until: int = integration_context.get('bot_valid_until', int) if access_token and valid_until: @@ -418,7 +418,7 @@ def get_bot_access_token() -> str: expires_in -= time_buffer integration_context['bot_access_token'] = access_token integration_context['bot_valid_until'] = time_now + expires_in - demisto.setIntegrationContext(integration_context) + set_integration_context(integration_context) return access_token except ValueError: raise ValueError('Failed to get bot access token') @@ -429,7 +429,7 @@ def get_graph_access_token() -> str: Retrieves Microsoft Graph API access token, either from cache or from Microsoft :return: The Microsoft Graph API access token """ - integration_context: dict = demisto.getIntegrationContext() + integration_context: dict = get_integration_context() access_token: str = integration_context.get('graph_access_token', '') valid_until: int = integration_context.get('graph_valid_until', int) if access_token and valid_until: @@ -468,7 +468,7 @@ def get_graph_access_token() -> str: expires_in -= time_buffer integration_context['graph_access_token'] = access_token integration_context['graph_valid_until'] = time_now + expires_in - demisto.setIntegrationContext(integration_context) + set_integration_context(integration_context) return access_token except ValueError: raise ValueError('Failed to get Graph access token') @@ -562,7 +562,7 @@ def integration_health(): adi_health_human_readable: str = tableToMarkdown('Microsoft API Health', api_health_output) mirrored_channels_output = list() - integration_context: dict = demisto.getIntegrationContext() + integration_context: dict = get_integration_context() teams: list = json.loads(integration_context.get('teams', '[]')) for team in teams: mirrored_channels: list = team.get('mirrored_channels', []) @@ -611,7 +611,7 @@ def validate_auth_header(headers: dict) -> bool: demisto.info('Authorization header validation - failed to verify issuer') return False - integration_context: dict = demisto.getIntegrationContext() + integration_context: dict = get_integration_context() open_id_metadata: dict = json.loads(integration_context.get('open_id_metadata', '{}')) keys: list = open_id_metadata.get('keys', []) @@ -680,8 +680,7 @@ def validate_auth_header(headers: dict) -> bool: return False integration_context['open_id_metadata'] = json.dumps(open_id_metadata) - demisto.setIntegrationContext(integration_context) - + set_integration_context(integration_context) return True @@ -694,7 +693,7 @@ def get_team_aad_id(team_name: str) -> str: :param team_name: Team name to get AAD ID of :return: team AAD ID """ - integration_context: dict = demisto.getIntegrationContext() + integration_context: dict = get_integration_context() if integration_context.get('teams'): teams: list = json.loads(integration_context['teams']) for team in teams: @@ -888,7 +887,7 @@ def get_channel_id(channel_name: str, team_aad_id: str, investigation_id: str = :return: Requested channel ID """ investigation_id = investigation_id or str() - integration_context: dict = demisto.getIntegrationContext() + integration_context: dict = get_integration_context() teams: list = json.loads(integration_context.get('teams', '[]')) for team in teams: mirrored_channels: list = team.get('mirrored_channels', []) @@ -958,7 +957,7 @@ def close_channel(): """ Deletes a mirrored Microsoft Teams channel """ - integration_context: dict = demisto.getIntegrationContext() + integration_context: dict = get_integration_context() channel_name: str = demisto.args().get('channel', '') investigation: dict = demisto.investigation() investigation_id: str = investigation.get('id', '') @@ -981,7 +980,7 @@ def close_channel(): if not channel_id: raise ValueError('Could not find Microsoft Teams channel to close.') integration_context['teams'] = json.dumps(teams) - demisto.setIntegrationContext(integration_context) + set_integration_context(integration_context) else: team_name: str = demisto.args().get('team') or demisto.params().get('team') team_aad_id = get_team_aad_id(team_name) @@ -1096,7 +1095,7 @@ def send_message(): if message and adaptive_card: raise ValueError('Provide either message or adaptive to send, not both.') - integration_context: dict = demisto.getIntegrationContext() + integration_context: dict = get_integration_context() channel_id: str = str() personal_conversation_id: str = str() if channel_name: @@ -1160,7 +1159,7 @@ def mirror_investigation(): if investigation.get('type') == PLAYGROUND_INVESTIGATION_TYPE: raise ValueError('Can not perform this action in playground.') - integration_context: dict = demisto.getIntegrationContext() + integration_context: dict = get_integration_context() mirror_type: str = demisto.args().get('mirror_type', 'all') auto_close: str = demisto.args().get('autoclose', 'true') @@ -1217,7 +1216,7 @@ def mirror_investigation(): demisto.results(f'Investigation mirrored successfully in channel {channel_name}.') team['mirrored_channels'] = mirrored_channels integration_context['teams'] = json.dumps(teams) - demisto.setIntegrationContext(integration_context) + set_integration_context(integration_context) def channel_mirror_loop(): @@ -1226,7 +1225,7 @@ def channel_mirror_loop(): """ while True: found_channel_to_mirror: bool = False - integration_context = demisto.getIntegrationContext() + integration_context = get_integration_context() try: teams: list = json.loads(integration_context.get('teams', '[]')) for team in teams: @@ -1249,7 +1248,7 @@ def channel_mirror_loop(): demisto.info(f'Could not mirror {investigation_id}') team['mirrored_channels'] = mirrored_channels integration_context['teams'] = json.dumps(teams) - demisto.setIntegrationContext(integration_context) + set_integration_context(integration_context) found_channel_to_mirror = True break if found_channel_to_mirror: @@ -1322,7 +1321,7 @@ def member_added_handler(integration_context: dict, request_body: dict, channel_ 'team_members': team_members }) integration_context['teams'] = json.dumps(teams) - demisto.setIntegrationContext(integration_context) + set_integration_context(integration_context) def direct_message_handler(integration_context: dict, request_body: dict, conversation: dict, message: str): @@ -1479,12 +1478,12 @@ def messages() -> Response: demisto.info(f'Authorization header failed: {str(headers)}') else: request_body: dict = request.json - integration_context: dict = demisto.getIntegrationContext() + integration_context: dict = get_integration_context() service_url: str = request_body.get('serviceUrl', '') if service_url: service_url = service_url[:-1] if service_url.endswith('/') else service_url integration_context['service_url'] = service_url - demisto.setIntegrationContext(integration_context) + set_integration_context(integration_context) channel_data: dict = request_body.get('channelData', {}) event_type: str = channel_data.get('eventType', '') @@ -1534,7 +1533,7 @@ def ring_user(): None. """ bot_id = demisto.params().get('bot_id') - integration_context: dict = demisto.getIntegrationContext() + integration_context: dict = get_integration_context() tenant_id: str = integration_context.get('tenant_id', '') if not tenant_id: raise ValueError( diff --git a/Packs/MicrosoftTeams/ReleaseNotes/1_1_5.md b/Packs/MicrosoftTeams/ReleaseNotes/1_1_5.md new file mode 100644 index 000000000000..51a957891766 --- /dev/null +++ b/Packs/MicrosoftTeams/ReleaseNotes/1_1_5.md @@ -0,0 +1,4 @@ + +#### Integrations +##### Microsoft Teams +- Added support for cache to be updated automatically on token expiration. \ No newline at end of file diff --git a/Packs/MicrosoftTeams/pack_metadata.json b/Packs/MicrosoftTeams/pack_metadata.json index e91785a970e5..a26e34f52523 100644 --- a/Packs/MicrosoftTeams/pack_metadata.json +++ b/Packs/MicrosoftTeams/pack_metadata.json @@ -2,7 +2,7 @@ "name": "Microsoft Teams", "description": "Send messages and notifications to your team members.", "support": "xsoar", - "currentVersion": "1.1.4", + "currentVersion": "1.1.5", "author": "Cortex XSOAR", "url": "https://www.paloaltonetworks.com/cortex", "email": "",