建立或更新角色定義。
PUT https://management.azure.com/{scope}/providers/Microsoft.Authorization/roleDefinitions/{roleDefinitionId}?api-version=2022-04-01
URI 參數
名稱 |
位於 |
必要 |
類型 |
Description |
roleDefinitionId
|
path |
True
|
string
|
角色定義的識別碼。
|
scope
|
path |
True
|
string
|
角色定義的範圍。
|
api-version
|
query |
True
|
string
minLength: 1
|
要用於這項作業的 API 版本。
|
要求本文
名稱 |
類型 |
Description |
properties.assignableScopes
|
string[]
|
角色定義可指派的範圍。
|
properties.description
|
string
|
角色定義描述。
|
properties.permissions
|
Permission[]
|
角色定義許可權。
|
properties.roleName
|
string
|
角色名稱。
|
properties.type
|
string
|
角色類型。
|
回應
安全性
azure_auth
Azure Active Directory OAuth2 Flow
類型:
oauth2
Flow:
implicit
授權 URL:
https://login.microsoftonline.com/common/oauth2/authorize
範圍
名稱 |
Description |
user_impersonation
|
模擬您的用戶帳戶
|
範例
Create role definition
範例要求
PUT https://management.azure.com/scope/providers/Microsoft.Authorization/roleDefinitions/roleDefinitionId?api-version=2022-04-01
{}
import com.azure.resourcemanager.authorization.fluent.models.RoleDefinitionInner;
/**
* Samples for RoleDefinitions CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* specification/authorization/resource-manager/Microsoft.Authorization/stable/2022-04-01/examples/PutRoleDefinition
* .json
*/
/**
* Sample code: Create role definition.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createRoleDefinition(com.azure.resourcemanager.AzureResourceManager azure) {
azure.accessManagement().roleAssignments().manager().roleServiceClient().getRoleDefinitions()
.createOrUpdateWithResponse("scope", "roleDefinitionId", new RoleDefinitionInner(),
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armauthorization_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/authorization/armauthorization/v2"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/53b1affe357b3bfbb53721d0a2002382a046d3b0/specification/authorization/resource-manager/Microsoft.Authorization/stable/2022-04-01/examples/PutRoleDefinition.json
func ExampleRoleDefinitionsClient_CreateOrUpdate() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armauthorization.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
_, err = clientFactory.NewRoleDefinitionsClient().CreateOrUpdate(ctx, "scope", "roleDefinitionId", armauthorization.RoleDefinition{}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { AuthorizationManagementClient } = require("@azure/arm-authorization");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to Creates or updates a role definition.
*
* @summary Creates or updates a role definition.
* x-ms-original-file: specification/authorization/resource-manager/Microsoft.Authorization/stable/2022-04-01/examples/PutRoleDefinition.json
*/
async function createRoleDefinition() {
const subscriptionId =
process.env["AUTHORIZATION_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000";
const scope = "scope";
const roleDefinitionId = "roleDefinitionId";
const roleDefinition = {};
const credential = new DefaultAzureCredential();
const client = new AuthorizationManagementClient(credential, subscriptionId);
const result = await client.roleDefinitions.createOrUpdate(
scope,
roleDefinitionId,
roleDefinition
);
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.Authorization;
// Generated from example definition: specification/authorization/resource-manager/Microsoft.Authorization/stable/2022-04-01/examples/PutRoleDefinition.json
// this example is just showing the usage of "RoleDefinitions_CreateOrUpdate" 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);
// get the collection of this AuthorizationRoleDefinitionResource
string scope = "scope";
AuthorizationRoleDefinitionCollection collection = client.GetAuthorizationRoleDefinitions(new ResourceIdentifier(scope));
// invoke the operation
ResourceIdentifier roleDefinitionId = new ResourceIdentifier("roleDefinitionId");
AuthorizationRoleDefinitionData data = new AuthorizationRoleDefinitionData();
ArmOperation<AuthorizationRoleDefinitionResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, roleDefinitionId, data);
AuthorizationRoleDefinitionResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
AuthorizationRoleDefinitionData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
範例回覆
{
"properties": {
"roleName": "Role name",
"type": "roletype",
"description": "Role description",
"assignableScopes": [
"/subscriptions/subId"
],
"permissions": [
{
"actions": [
"action"
],
"notActions": [],
"dataActions": [
"dataAction"
],
"notDataActions": []
}
]
},
"id": "/subscriptions/subID/providers/Microsoft.Authorization/roleDefinitions/roleDefinitionId",
"type": "Microsoft.Authorization/roleDefinitions",
"name": "roleDefinitionId"
}
定義
ErrorAdditionalInfo
Object
資源管理錯誤其他資訊。
名稱 |
類型 |
Description |
info
|
object
|
其他資訊。
|
type
|
string
|
其他信息類型。
|
ErrorDetail
Object
錯誤詳細數據。
名稱 |
類型 |
Description |
additionalInfo
|
ErrorAdditionalInfo[]
|
錯誤其他資訊。
|
code
|
string
|
錯誤碼。
|
details
|
ErrorDetail[]
|
錯誤詳細數據。
|
message
|
string
|
錯誤訊息。
|
target
|
string
|
錯誤目標。
|
ErrorResponse
Object
錯誤回應
Permission
Object
角色定義許可權。
名稱 |
類型 |
Description |
actions
|
string[]
|
允許的動作。
|
dataActions
|
string[]
|
允許的數據動作。
|
notActions
|
string[]
|
拒絕的動作。
|
notDataActions
|
string[]
|
拒絕的數據動作。
|
RoleDefinition
Object
角色定義。
名稱 |
類型 |
Description |
id
|
string
|
角色定義標識碼。
|
name
|
string
|
角色定義名稱。
|
properties.assignableScopes
|
string[]
|
角色定義可指派的範圍。
|
properties.createdBy
|
string
|
建立指派的使用者標識碼
|
properties.createdOn
|
string
(date-time)
|
建立時間
|
properties.description
|
string
|
角色定義描述。
|
properties.permissions
|
Permission[]
|
角色定義許可權。
|
properties.roleName
|
string
|
角色名稱。
|
properties.type
|
string
|
角色類型。
|
properties.updatedBy
|
string
|
更新指派的使用者標識碼
|
properties.updatedOn
|
string
(date-time)
|
更新的時間
|
type
|
string
|
角色定義類型。
|