Skip to content

Commit 6408a9d

Browse files
committed
Add env variable configuration
1 parent 0148de3 commit 6408a9d

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

articles/defender-for-iot/device-builders/quickstart-upload-firmware-using-python.md

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,32 @@ This quickstart assumes a basic understanding of Defender for IoT Firmware Analy
2020

2121
### Prepare your environment
2222

23-
* Ensure that your client has the necessary permissions to upload firmware images to Defender for IoT Firmware Analysis. You must be an Owner, Contributor, Security Admin, or Firmware Analysis Admin at the Subscription or Resource Group level to upload firmware images. For more information, visit [Defender for IoT Firmware Analysis Roles, Scopes, and Capabilities](/azure/defender-for-iot/device-builders/defender-iot-firmware-analysis-rbac#defender-for-iot-firmware-analysis-roles-scopes-and-capabilities).
24-
* Make note of your subscription ID, the name of your Resource Group where you'd like to upload your images, your workspace name, and the name of the firmware image that you'd like to upload.
23+
* Python version 3.8+ is required to use this package. Run the command `python --version` to check your Python version. If's not the latest, please update to the latest Python version
24+
* Make note of your Azure subscription ID, the name of your Resource Group where you'd like to upload your images, your workspace name, and the name of the firmware image that you'd like to upload
25+
* Ensure that your Azure account has the necessary permissions to upload firmware images to Defender for IoT Firmware Analysis for your Azure subscription. You must be an Owner, Contributor, Security Admin, or Firmware Analysis Admin at the Subscription or Resource Group level to upload firmware images. For more information, visit [Defender for IoT Firmware Analysis Roles, Scopes, and Capabilities](/azure/defender-for-iot/device-builders/defender-iot-firmware-analysis-rbac#defender-for-iot-firmware-analysis-roles-scopes-and-capabilities)
2526
* Ensure that your firmware image is stored in the same directory as the following code
27+
* Install the packages needed to run this script:
28+
```python
29+
pip install azure-mgmt-iotfirmwaredefense
30+
pip install azure-identity
31+
```
32+
* [Configure](/azure/azure-web-pubsub/howto-authorize-from-application) the following environment variables:
33+
* `AZURE_CLIENT_ID` for Azure client ID
34+
* `AZURE_TENANT_ID` for Azure tenant ID
35+
* `AZURE_CLIENT_SECRET` for Azure client secret
36+
37+
In addition, the Azure subscription ID can be configured with the environment variable `AZURE_SUBSCRIPTION_ID`.
38+
39+
Once you've configured your environment variables, the client can be authenticated by the following code:
40+
41+
```python
42+
from azure.identity import DefaultAzureCredential
43+
from azure.mgmt.iotfirmwaredefense import IoTFirmwareDefenseMgmtClient
44+
import os
45+
46+
sub_id = os.getenv("AZURE_SUBSCRIPTION_ID")
47+
client = IoTFirmwareDefenseMgmtClient(credential=DefaultAzureCredential(), subscription_id=sub_id)
48+
```
2649

2750
## Run the following Python script
2851

@@ -39,18 +62,15 @@ from time import sleep
3962
from halo import Halo
4063
from tabulate import tabulate
4164

42-
4365
subscription_id = "subscription-id"
4466
resource_group_name = "resource-group-name"
4567
workspace_name = "default"
4668
firmware_file = "firmware-image-name"
4769

48-
4970
def main():
5071
firmware_id = str(uuid.uuid4())
51-
5272
fw_client = init_connections(firmware_id)
53-
upload_firmware(fw_client, firmware_id)
73+
# upload_firmware(fw_client, firmware_id)
5474
get_results(fw_client, firmware_id)
5575

5676
def init_connections(firmware_id):

0 commit comments

Comments
 (0)