Azure / azure-sdk-for-python

This repository is for active development of the Azure SDK for Python. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/python/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-python.
MIT License
4.61k stars 2.83k forks source link

Error when getting a Policy Name using its Definition Id #36519

Open slarionoff opened 3 months ago

slarionoff commented 3 months ago

Describe the bug I'm trying to get a policy name using its definition name:

from azure.mgmt.policyinsights import PolicyInsightsClient
from azure.mgmt.policyinsights.operations import PolicyStatesOperations
from azure.identity import DefaultAzureCredential

# Get Client
pic = PolicyInsightsClient(
    credential=DefaultAzureCredential(),
    subscription_id=subscription_id
)

# Get Operations
pso = PolicyStatesOperations(
    client=pic,
    config=pic._config,
    serializer=pic._serialize,
    deserializer=pic._deserialize
)

# Get Policy details
policy_name = pso.summarize_for_policy_definition(
    subscription_id=subscription_id,
    policy_definition_name=policy_definition_name
)

As a result I have this error for a Release version (1.0.0, Jan 4, 2021):

  File "<my project path>\venv\lib\site-packages\azure\mgmt\policyinsights\operations\_policy_states_operations.py", line 1419, in summarize_for_policy_definition
    url = self._client.format_url(url, **path_format_arguments)
AttributeError: 'PolicyInsightsClient' object has no attribute 'format_url'

and this error for a Latest version (1.1.0.b4, Dec 30, 2022):

  File "<my project path>\venv\lib\site-packages\azure\core\tracing\decorator.py", line 94, in wrapper_use_tracer
    return func(*args, **kwargs)
TypeError: PolicyStatesOperations.summarize_for_policy_definition() missing 1 required positional argument: 'policy_states_summary_resource'

This argument is not described at all.

To Reproduce Steps to reproduce the behavior:

  1. I guess put the code above to a new Python script, add all required imports, define required variable and run it

Expected behavior A Policy name is returned

Additional context

  1. I've tried to find a clear description how this lib should be used, but so far I didn't succeed. The same is for examples, so far not so many examples I could find unfortunately;
xiangyan99 commented 3 months ago

Thanks for the feedback, we’ll investigate asap.