GET https://management.azure.com/scope/providers/Microsoft.Authorization/roleDefinitions/roleDefinitionId?api-version=2022-04-01
import com.azure.core.util.Context;
/** Samples for RoleDefinitions Get. */
public final class Main {
/*
* x-ms-original-file: specification/authorization/resource-manager/Microsoft.Authorization/stable/2022-04-01/examples/GetRoleDefinitionByName.json
*/
/**
* Sample code: Get role definition by name.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void getRoleDefinitionByName(com.azure.resourcemanager.AzureResourceManager azure) {
azure
.accessManagement()
.roleAssignments()
.manager()
.roleServiceClient()
.getRoleDefinitions()
.getWithResponse("scope", "roleDefinitionId", Context.NONE);
}
}
from azure.identity import DefaultAzureCredential
from azure.mgmt.authorization import AuthorizationManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-authorization
# USAGE
python get_role_definition_by_name.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = AuthorizationManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.role_definitions.get(
scope="scope",
role_definition_id="roleDefinitionId",
)
print(response)
# x-ms-original-file: specification/authorization/resource-manager/Microsoft.Authorization/stable/2022-04-01/examples/GetRoleDefinitionByName.json
if __name__ == "__main__":
main()
const { AuthorizationManagementClient } = require("@azure/arm-authorization");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to Get role definition by name (GUID).
*
* @summary Get role definition by name (GUID).
* x-ms-original-file: specification/authorization/resource-manager/Microsoft.Authorization/stable/2022-04-01/examples/GetRoleDefinitionByName.json
*/
async function getRoleDefinitionByName() {
const subscriptionId =
process.env["AUTHORIZATION_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000";
const scope = "scope";
const roleDefinitionId = "roleDefinitionId";
const credential = new DefaultAzureCredential();
const client = new AuthorizationManagementClient(credential, subscriptionId);
const result = await client.roleDefinitions.get(scope, roleDefinitionId);
console.log(result);
}
using System;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Authorization;
// Generated from example definition: specification/authorization/resource-manager/Microsoft.Authorization/stable/2022-04-01/examples/GetRoleDefinitionByName.json
// this example is just showing the usage of "RoleDefinitions_Get" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ArmResource created on azure
// for more information of creating ArmResource, please refer to the document of ArmResource
// get the collection of this AuthorizationRoleDefinitionResource
string scope = "scope";
ResourceIdentifier scopeId = new ResourceIdentifier(string.Format("/{0}", scope));
AuthorizationRoleDefinitionCollection collection = client.GetAuthorizationRoleDefinitions(scopeId);
// invoke the operation
ResourceIdentifier roleDefinitionId = new ResourceIdentifier("roleDefinitionId");
bool result = await collection.ExistsAsync(roleDefinitionId);
Console.WriteLine($"Succeeded: {result}");