Python 用 Azure 承認ライブラリ

管理 API

pip install azure-mgmt-authorization

管理クライアントを作成する

管理クライアントのインスタンスは、以下のコードで作成します。

サブスクリプションの一覧から取得できる をsubscription_id指定する必要があります。

Python SDK を使用した Azure Active Directory の認証処理と Credentials インスタンスの作成について詳しくは、「Resource Management Authentication (リソース管理の認証)」を参照してください。

from azure.mgmt.authorization import AuthorizationManagementClient
from azure.common.credentials import UserPassCredentials

# Replace this with your subscription id
subscription_id = '33333333-3333-3333-3333-333333333333'

# See above for details on creating different types of AAD credentials
credentials = UserPassCredentials(
    'user@domain.com',	# Your user
    'my_password' 		# Your password
)

authorization_client = AuthorizationManagementClient(
    credentials,
    subscription_id
)

リソース グループのアクセス許可チェック

以下のコードは、特定のリソース グループのアクセス許可をチェックするものです。 リソース グループの作成と管理については、リソース管理に関するページを参照してください。

from azure.mgmt.redis.models import Sku, RedisCreateOrUpdateParameters

group_name = 'myresourcegroup'
permissions = self.authorization_client.permissions.list_for_resource_group(
    group_name
)
# permissions is a iterable of Permissions instances