microsoftgraph / msgraph-beta-sdk-python

MIT License
26 stars 6 forks source link

Partner Security Alerts ModuleNotFoundError #519

Closed AdrianM10 closed 1 week ago

AdrianM10 commented 1 week ago

Describe the bug

I am encountering a ModuleNotFoundError when trying to import from msgraph_beta when attempting to update Partner Security Alerts.

Expected behavior

A response object should be returned as indicated in the Microsoft docs :

https://learn.microsoft.com/en-us/graph/api/partner-security-partnersecurityalert-update?view=graph-rest-beta&tabs=python

HTTP/1.1 200 OK
Content-Type: application/json

 {
  "id": "d8b202fc-a216-3404-69ef-bdffa445eff6",
  "displayName": "Action Required: Virtual machine connecting to crypto currency mining pool Detected",
  "description": "Analysis of Azure resource network activity detected the resource was connecting to a crypto currency mining pool. This would often be an indication that your Azure resource is compromised.",
  "alertType": "networkConnectionsToCryptoMiningPools",
  "status": "active",
  "severity": "high",
  "confidenceLevel": "medium",
  "customerTenantId": "1889e718-414b-4bad-8bbe-c1135bd39a41",
  "subscriptionId": "5f6e6521-6e5f-4b0b-80aa-bd44fad7a398",
  "valueAddedResellerTenantId": "c296b2ce-8cd1-4346-9e82-d8eccca70d65",
  "catalogOfferId": "MS-AZR-0017G",
  "detectedDateTime": "2024-01-23T16:03:33.05Z",
  "firstObservedDateTime": "2024-01-23T16:03:33.05Z",
  "lastObservedDateTime": "2024-01-23T16:03:33.05Z",
  "resolvedReason": "fraud",
  "resolvedOnDateTime": "2024-02-23T16:03:33.05Z",
  "resolvedBy": "danas@contoso.com",
  "isTest": false,
  "affectedResources": [
    {
      "resourceId": "/subscriptions/subscription-id/resourceGroups/resourcegroup-name/providers/Microsoft.Compute/virtualMachines/vm-name",
      "resourceType": "AzureResource"
    }
  ],
  "activityLogs": [
    {
      "statusFrom": "active",
      "statusTo": "investigating",
      "updatedBy": "samanthab@contoso.com",
      "updatedDateTime": "2023-08-10T08:47:10.8454142Z"
    },
    {
      "statusFrom": "investigating",
      "statusTo": "resolved",
      "updatedBy": "samanthab@contoso.com",
      "updatedDateTime": "2023-08-10T08:47:25.2089246Z"
    }
  ],
  "additionalDetails": {
    "VM_IP": "[  \"vm-ip\"]",
    "MiningPool_IP": "[  \"mining-pool-ip\"]",
    "ConnectionCount": "5",
    "CryptoCurrencyMiningPoolDomainName": "pool-name.com"
  }
}

How to reproduce

  1. Installed the msgraph-beta-sdk using pip
  2. Attempted to run the below code :
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.models.partner.security.partner_security_alert import PartnerSecurityAlert
from msgraph_beta.generated.models.security_alert_status import SecurityAlertStatus
from msgraph_beta.generated.models.security_alert_resolved_reason import SecurityAlertResolvedReason

from azure.identity import DefaultAzureCredential
from azure.identity.aio import ClientSecretCredential
from azure.keyvault.secrets import SecretClient
import asyncio

def main():

    asyncio.run(update_security_alert())

async def update_security_alert():
    """Update security alert"""

    credential = DefaultAzureCredential()

    secret_client = SecretClient(
        vault_url="https://kv-demo-zan-prod-004.vault.azure.net/", credential=credential
    )

    client_id = secret_client.get_secret(
        "clientId"
    ).value
    client_secret = secret_client.get_secret(
        "clientSecret"
    ).value
    tenant_id = secret_client.get_secret(
        "tenantId"
    ).value

    credentials = ClientSecretCredential(tenant_id, client_id, client_secret)

    scopes = ["https://graph.microsoft.com/.default"]

    graph_client = GraphServiceClient(credentials, scopes)

    request_body = PartnerSecurityAlert(
        status=SecurityAlertStatus.Resolved,
        resolved_reason=SecurityAlertResolvedReason.Ignore,
    )

    alert_id = ""

    result = await graph_client.security.partner.security_alerts.by_partner_security_alert_id(alert_id).patch(request_body)

    print(result)

if __name__ == "__main__":
    main()

SDK Version

1.5.3

Latest version known to work for scenario above?

No response

Known Workarounds

No response

Debug output

Click to expand log ``` Traceback (most recent call last): File "C:\Users\Developer\Partner-Center-Events\CodeSnippets\update_security_alert.py", line 3, in from msgraph_beta.generated.models.security_alert_status import SecurityAlertStatus ModuleNotFoundError: No module named 'msgraph_beta.generated.models.security_alert_status' ```

Configuration

Other information

No response

shemogumbe commented 1 week ago

Hello @AdrianM10 thanks for using the SDK and for raising this.

There seems to be an issue with the snippet.

In your code:

from msgraph_beta.generated.models.security_alert_status import SecurityAlertStatus
from msgraph_beta.generated.models.security_alert_resolved_reason import SecurityAlertResolvedReason

Do not exist. The path to Partner alert status is and alert reasolved reason are

from msgraph_beta.generated.models.partner.security.security_alert_status import SecurityAlertStatus
from msgraph_beta.generated.models.partner.security.security_alert_resolved_reason import SecurityAlertResolvedReason

As per the path msgraph_beta/generated/models/partner/security/

Investigating the reason for the invalid import path.

shemogumbe commented 1 week ago

Tracked here https://github.com/microsoftgraph/microsoft-graph-devx-api/issues/2183

AdrianM10 commented 1 week ago

Thanks @shemogumbe

shemogumbe commented 1 week ago

Closing as issues is tracked here https://github.com/microsoftgraph/microsoft-graph-devx-api/issues/2183