diff --git a/README.md b/README.md index 0900039..cd38208 100644 --- a/README.md +++ b/README.md @@ -174,15 +174,16 @@ For Azure Mail Reports, use type `azure_mail_reports` with the below parameters. For structuring custom general Azure API calls use type `azure_general` API with the parameters below. ## Configuration Options -| Parameter Name | Description | Required/Optional | Default | -|-----------------------|-------------------------------------------------------------------------------------------------------------|-------------------|-------------| -| name | Name of the API (custom name) | Optional | `azure api` | -| azure_ad_tenant_id | The Azure AD Tenant id | Required | - | -| azure_ad_client_id | The Azure AD Client id | Required | - | -| azure_ad_secret_value | The Azure AD Secret value | Required | - | -| data_request | Nest here any detail relevant to the data request. (Options in [General API](./src/apis/general/README.md)) | Required | - | -| days_back_fetch | The amount of days to fetch back in the first request | Optional | 1 (day) | -| scrape_interval | Time interval to wait between runs (unit: `minutes`) | Optional | 1 (minute) | +| Parameter Name | Description | Required/Optional | Default | +|-----------------------|-------------------------------------------------------------------------------------------------------------|-------------------|----------------------------------------------------------| +| name | Name of the API (custom name) | Optional | `azure api` | +| azure_ad_tenant_id | The Azure AD Tenant id | Required | - | +| azure_ad_client_id | The Azure AD Client id | Required | - | +| azure_ad_secret_value | The Azure AD Secret value | Required | - | +| data_request | Nest here any detail relevant to the data request. (Options in [General API](./src/apis/general/README.md)) | Required | - | +| scope | The specific permissions an application is requesting during a token request. | Optional | Azure graph scope `https://graph.microsoft.com/.default` | +| days_back_fetch | The amount of days to fetch back in the first request | Optional | 1 (day) | +| scrape_interval | Time interval to wait between runs (unit: `minutes`) | Optional | 1 (minute) |
@@ -284,6 +285,8 @@ docker stop -t 30 logzio-api-fetcher ``` ## Changelog: +- **0.2.2**: + - Resolve Azure mail reports bug - **0.2.1**: - Add 1Password Support - Add `next_body` support to allow more customization in general settings diff --git a/src/apis/azure/AzureApi.py b/src/apis/azure/AzureApi.py index 1ceab7c..0277f08 100644 --- a/src/apis/azure/AzureApi.py +++ b/src/apis/azure/AzureApi.py @@ -23,10 +23,12 @@ class AzureApi(OAuthApi): date_filter_key: str = Field(default="createdDateTime") def __init__(self, **data): + scope = data.pop('scope', "https://graph.microsoft.com/.default") + token_request = ApiFetcher( url=f"https://login.microsoftonline.com/{data.get('azure_ad_tenant_id')}/oauth2/v2.0/token", body=f"""client_id={data.get('azure_ad_client_id')} - &scope=https://graph.microsoft.com/.default + &scope={scope} &client_secret={data.get('azure_ad_secret_value')} &grant_type=client_credentials """, diff --git a/src/apis/azure/AzureMailReports.py b/src/apis/azure/AzureMailReports.py index 6fa85c0..007f546 100644 --- a/src/apis/azure/AzureMailReports.py +++ b/src/apis/azure/AzureMailReports.py @@ -28,6 +28,7 @@ def __init__(self, **data): stop_indication=StopPaginationSettings(field="d.results", condition="empty")), response_data_path="d.results") + data["scope"] = "https://outlook.office365.com/.default" super().__init__(data_request=data_request, **data) # Structure the next URL format, to automatically update start date. @@ -44,15 +45,15 @@ def _initialize_url_date(self, fetch_start_date, fetch_end_date): https://url/from/input?$filter=StartDate eq datetime '2024-05-28T13:08:54Z' and EndDate eq datetime '2024-05-29T13:08:54Z' """ self.data_request.url = (self.data_request.next_url - .replace(f"{{res.value.[0].{self.end_date_filter_key}}}", fetch_start_date) + .replace(f"{{res.d.results.[0].{self.end_date_filter_key}}}", fetch_start_date) .replace("NOW_DATE", fetch_end_date)) def _initialize_next_url(self): """ initializing the data request next url to be in format: - https://url/from/input?$filter=StartDate eq datetime '{res.d.results.[0].EndDate}' and EndDate eq datetime 'NOW_DATE' + https://url/from/input?$filter=StartDate eq datetime'{res.d.results.[0].EndDate}' and EndDate eq datetime'NOW_DATE' """ - new_next_url = self.data_request.url + f"?$filter={self.date_filter_key} eq datetime '{{res.d.results.[0].{self.end_date_filter_key}}}' and {self.end_date_filter_key} eq datetime 'NOW_DATE'" + new_next_url = self.data_request.url + f"?$filter={self.date_filter_key} eq datetime'{{res.d.results.[0].{self.end_date_filter_key}}}' and {self.end_date_filter_key} eq datetime'NOW_DATE'&$format=json" self.data_request.update_next_url(new_next_url) @staticmethod diff --git a/src/apis/azure/README.MD b/src/apis/azure/README.MD index da2f85e..287b98e 100644 --- a/src/apis/azure/README.MD +++ b/src/apis/azure/README.MD @@ -10,15 +10,16 @@ Configuration [example here](#example). ## Azure General Below fields are relevant for **all Azure API types** -| Parameter Name | Description | Required/Optional | Default | -|-----------------------|-----------------------------------------------------------------------------------------------------|-------------------|-------------| -| name | Name of the API (custom name) | Optional | `azure api` | -| azure_ad_tenant_id | The Azure AD Tenant id | Required | - | -| azure_ad_client_id | The Azure AD Client id | Required | - | -| azure_ad_secret_value | The Azure AD Secret value | Required | - | -| data_request | Nest here any detail relevant to the data request. (Options in [General API](../general/README.md)) | Required | - | -| days_back_fetch | The amount of days to fetch back in the first request | Optional | 1 (day) | -| scrape_interval | Time interval to wait between runs (unit: `minutes`) | Optional | 1 (minute) | +| Parameter Name | Description | Required/Optional | Default | +|-----------------------|-----------------------------------------------------------------------------------------------------|-------------------|----------------------------------------------------------| +| name | Name of the API (custom name) | Optional | `azure api` | +| azure_ad_tenant_id | The Azure AD Tenant id | Required | - | +| azure_ad_client_id | The Azure AD Client id | Required | - | +| azure_ad_secret_value | The Azure AD Secret value | Required | - | +| data_request | Nest here any detail relevant to the data request. (Options in [General API](../general/README.md)) | Required | - | +| scope | The specific permissions an application is requesting during a token request. | Optional | Azure graph scope `https://graph.microsoft.com/.default` | +| days_back_fetch | The amount of days to fetch back in the first request | Optional | 1 (day) | +| scrape_interval | Time interval to wait between runs (unit: `minutes`) | Optional | 1 (minute) | ## Azure Graph By default `azure_graph` API type has built in pagination settings and sets the `response_data_path` to `value` field. diff --git a/tests/UnitTests/test_azure_api.py b/tests/UnitTests/test_azure_api.py index d5944e4..d7b4412 100644 --- a/tests/UnitTests/test_azure_api.py +++ b/tests/UnitTests/test_azure_api.py @@ -49,11 +49,17 @@ def test_valid_setup(self): &grant_type=client_credentials """ + expected_token_body2 = """client_id=some-client + &scope=https://outlook.office365.com/.default + &client_secret=some-secret + &grant_type=client_credentials + """ + # Validate the token request self.assertEqual(ag.token_request.url, "https://login.microsoftonline.com/some-tenant/oauth2/v2.0/token") self.assertEqual(am.token_request.url, "https://login.microsoftonline.com/some-tenant/oauth2/v2.0/token") self.assertEqual(ag.token_request.body, expected_token_body) - self.assertEqual(am.token_request.body, expected_token_body) + self.assertEqual(am.token_request.body, expected_token_body2) # Validate the data request URL was updated self.assertIn("https://azure-graph?$filter=createdDateTime gt", ag.data_request.url) @@ -64,7 +70,7 @@ def test_valid_setup(self): self.assertEqual("https://azure-graph?$filter=createdDateTime gt {res.value.[0].createdDateTime}", ag.data_request.next_url) self.assertEqual( - "https://azure-mail?$filter=StartDate eq datetime '{res.d.results.[0].EndDate}' and EndDate eq datetime 'NOW_DATE'", + "https://azure-mail?$filter=StartDate eq datetime'{res.d.results.[0].EndDate}' and EndDate eq datetime'NOW_DATE'&$format=json", am.data_request.next_url) def test_start_date_generator(self): @@ -159,4 +165,4 @@ def test_azure_mail_send_request(self): self.assertEqual(result, data_res_body.get("d").get("results")) self.assertEqual(a.data_request.url, - "https://reports.office365.com/ecp/reportingwebservice/reporting.svc/MessageTrace?$filter=StartDate eq datetime '2024-05-30T13:08:54Z' and EndDate eq datetime 'NOW_DATE'") + "https://reports.office365.com/ecp/reportingwebservice/reporting.svc/MessageTrace?$filter=StartDate eq datetime'2024-05-30T13:08:54Z' and EndDate eq datetime'NOW_DATE'&$format=json")