-
Notifications
You must be signed in to change notification settings - Fork 2
Adding example for Microsoft Intune #107
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
base: main
Are you sure you want to change the base?
Conversation
|
…o add_microsoft_intune_example
|
||
The `requirements.txt` file specifies any additional Python libraries required by the connector. For this example, the following libraries are required: | ||
|
||
*Example content of `requirements.txt`:* | ||
|
||
``` | ||
requests | ||
``` | ||
|
||
Note: The `fivetran_connector_sdk:latest` and `requests:latest` packages are pre-installed in the Fivetran environment. To avoid dependency conflicts, do not declare them in your `requirements.txt`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is confusing, we should mention no requirements are needed for this example
"tenant_id": "<your_tenant_id>", | ||
"client_id": "<your_client_id>", | ||
"client_secret": "<your_client_secret>" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please change them to UPPER_CASE
import json | ||
|
||
# Define base URL for Microsoft graph API | ||
base_url = "https://graph.microsoft.com/v1.0/" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use UPPER_CASE for constants
base_url = "https://graph.microsoft.com/v1.0/" | |
BASE_URL = "https://graph.microsoft.com/v1.0/" |
if response.status_code == 200: | ||
access_token = response.json().get("access_token") | ||
else: | ||
log.severe(f"Error: {response.status_code} - {response.text}") | ||
|
||
return access_token |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be something like
if response.status_code == 200:
access_token = response.json().get("access_token")
return access_token
else:
log.severe(f"Error: {response.status_code} - {response.text}")
raise RuntimeError("Unable to fetch access_token")
auth_url = f"https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token" | ||
headers = {"Content-Type": "application/x-www-form-urlencoded"} | ||
payload = f'grant_type=client_credentials&client_id={client_id}&client_secret={client_secret}&scope=https%3A%2F%2Fgraph.microsoft.com%2F.default' | ||
response = requests.post(auth_url, headers=headers, data=payload) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no retry?
while more_devices: | ||
|
||
# Call API and retrieve JSON response | ||
print(f"Calling API: {devices_url}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use proper logging method, if needed
|
||
# Call API and retrieve JSON response | ||
print(f"Calling API: {devices_url}") | ||
response = requests.get(devices_url, headers=headers) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No retry? Generally APIs can fail intermittenly sometimes, retries ensure the code works properly in such intermittent cases
No description provided.