0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

背景

Cosmos DB のデータプレーンの Role を生成する際に、作成済みかどうかを確認したかった為の調査記録

結論

  1. 定義してある JSON から読み込み
  2. Azure で Role 名で検索
  3. あとは、見つかったかどうかで条件分岐
# Role 定義ファイルから読み込み
$roleDefinition = Get-Content -Path $roleDefinitionJsonPath -Raw | ConvertFrom-Json
# 定義 Role 名取得
$cosmosRoleName = $roleDefinition.RoleName
# Role に一致するものを、Cosmos DB から取得
$roleInfos = az cosmosdb sql role definition list --account-name {Cosmos Account} --resource-group {Resource Group} --query "[?roleName=='$cosmosRoleName'].{id: id, roleName: roleName}" --output json | ConvertFrom-Json
# 一致する Role の数で確認。null でもいい
if ($roleInfos.Count -eq 0) {
  # Role does not exist
} else {
  # Role exists
}
role の例
{
    "RoleName": "MyReadWriteRole",
    "Type": "CustomRole",
    "AssignableScopes": ["/"],
    "Permissions": [{
        "DataActions": [
            "Microsoft.DocumentDB/databaseAccounts/readMetadata",
            "Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/items/*",
            "Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/*"
        ]
    }]
}

あとがき

以前やったときは、query に RoleName を書く事に気付かず探せなかったが、今回はすぐだった・・
脳みそさんが backend で動いていてくれたんですかね :laughing:

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?