Skip to content

Commit ff7e832

Browse files
mgmt, authorization, support description in role assignment (Azure#31596)
1 parent 4d4a666 commit ff7e832

File tree

8 files changed

+175
-104
lines changed

8 files changed

+175
-104
lines changed

sdk/resourcemanager/azure-resourcemanager-authorization/CHANGELOG.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44

55
### Features Added
66

7-
### Breaking Changes
8-
9-
### Bugs Fixed
10-
11-
### Other Changes
7+
- Supported description in role assignment.
128

139
## 2.19.0 (2022-09-23)
1410

sdk/resourcemanager/azure-resourcemanager-authorization/pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
<javaModulesSurefireArgLine>
4444
--add-opens com.azure.resourcemanager.authorization/com.azure.resourcemanager.authorization=ALL-UNNAMED
4545
--add-opens com.azure.resourcemanager.resources/com.azure.resourcemanager.resources=ALL-UNNAMED
46+
47+
--add-opens com.azure.core/com.azure.core.implementation.util=ALL-UNNAMED
4648
</javaModulesSurefireArgLine>
4749
</properties>
4850

sdk/resourcemanager/azure-resourcemanager-authorization/src/main/java/com/azure/resourcemanager/authorization/implementation/RoleAssignmentImpl.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class RoleAssignmentImpl extends CreatableImpl<RoleAssignment, RoleAssignmentInn
3030
private String roleDefinitionId;
3131
private String roleName;
3232
private String scope;
33+
private String description;
3334
private final ClientLogger logger = new ClientLogger(RoleAssignmentImpl.class);
3435

3536
RoleAssignmentImpl(String name, RoleAssignmentInner innerObject, AuthorizationManager manager) {
@@ -78,7 +79,8 @@ public Mono<RoleAssignment> createResourceAsync() {
7879
new RoleAssignmentCreateParameters()
7980
.withProperties(new RoleAssignmentProperties()
8081
.withPrincipalId(objectId)
81-
.withRoleDefinitionId(roleDefinitionId)))
82+
.withRoleDefinitionId(roleDefinitionId)
83+
.withDescription(description)))
8284
.flatMap(
8385
roleAssignmentPropertiesInner ->
8486
manager()
@@ -115,6 +117,11 @@ public String condition() {
115117
return innerModel().properties().condition();
116118
}
117119

120+
@Override
121+
public String description() {
122+
return innerModel().properties().description();
123+
}
124+
118125
@Override
119126
public RoleAssignmentImpl forObjectId(String objectId) {
120127
this.objectId = objectId;
@@ -184,6 +191,11 @@ public RoleAssignmentImpl withSubscriptionScope(String subscriptionId) {
184191
return withScope("/subscriptions/" + subscriptionId);
185192
}
186193

194+
@Override
195+
public RoleAssignmentImpl withDescription(String description) {
196+
this.description = description;
197+
return this;
198+
}
187199
@Override
188200
public String id() {
189201
return innerModel().id();

sdk/resourcemanager/azure-resourcemanager-authorization/src/main/java/com/azure/resourcemanager/authorization/models/RoleAssignment.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,22 @@ public interface RoleAssignment
2828
/** @return the principal ID */
2929
String principalId();
3030

31-
/** @return the condition */
31+
/**
32+
* Gets the condition.
33+
* <p>
34+
* This is a preview feature.
35+
*
36+
* @return the condition
37+
*/
3238
String condition();
3339

40+
/**
41+
* Gets the description.
42+
*
43+
* @return the description
44+
*/
45+
String description();
46+
3447
/**************************************************************
3548
* Fluent interfaces to provision an role assignment
3649
**************************************************************/
@@ -154,11 +167,22 @@ interface WithScope {
154167
WithCreate withSubscriptionScope(String subscriptionId);
155168
}
156169

170+
/** The stage of role assignment definition allowing specifying the description. */
171+
interface WithDescription {
172+
/**
173+
* Specifies the description.
174+
*
175+
* @param description the description.
176+
* @return the next stage in role assignment definition
177+
*/
178+
WithCreate withDescription(String description);
179+
}
180+
157181
/**
158182
* An role assignment definition with sufficient inputs to create a new role assignment in the cloud, but
159183
* exposing additional optional inputs to specify.
160184
*/
161-
interface WithCreate extends Creatable<RoleAssignment> {
185+
interface WithCreate extends Creatable<RoleAssignment>, WithDescription {
162186
}
163187
}
164188
}

sdk/resourcemanager/azure-resourcemanager-authorization/src/main/java/com/azure/resourcemanager/authorization/models/RoleAssignmentProperties.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ public final class RoleAssignmentProperties {
2525
@JsonProperty(value = "principalId", required = true)
2626
private String principalId;
2727

28+
@JsonProperty(value = "description")
29+
private String description;
30+
2831
/**
2932
* Get the roleDefinitionId property: The role definition ID used in the role assignment.
3033
*
@@ -67,6 +70,26 @@ public RoleAssignmentProperties withPrincipalId(String principalId) {
6770
return this;
6871
}
6972

73+
/**
74+
* Get the description property: Description of role assignment.
75+
*
76+
* @return the description value
77+
*/
78+
public String description() {
79+
return description;
80+
}
81+
82+
/**
83+
* Set the description property: Description of role assignment.
84+
*
85+
* @param description the description value to set.
86+
* @return the RoleAssignmentPropertiesWithScope object itself.
87+
*/
88+
public RoleAssignmentProperties withDescription(String description) {
89+
this.description = description;
90+
return this;
91+
}
92+
7093
/**
7194
* Validates the instance.
7295
*

sdk/resourcemanager/azure-resourcemanager-authorization/src/main/java/com/azure/resourcemanager/authorization/models/RoleAssignmentPropertiesWithScope.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ public final class RoleAssignmentPropertiesWithScope {
3737
@JsonProperty(value = "condition")
3838
private String condition;
3939

40+
@JsonProperty(value = "description")
41+
private String description;
42+
4043
/*
4144
* Version of the condition. Currently accepted value is '2.0'
4245
*/
@@ -136,6 +139,15 @@ public String conditionVersion() {
136139
return this.conditionVersion;
137140
}
138141

142+
/**
143+
* Get the description property: Description of role assignment.
144+
*
145+
* @return the description value
146+
*/
147+
public String description() {
148+
return description;
149+
}
150+
139151
/**
140152
* Set the conditionVersion property: Version of the condition. Currently accepted value is '2.0'.
141153
*

sdk/resourcemanager/azure-resourcemanager-authorization/src/test/java/com/azure/resourcemanager/authorization/RoleAssignmentTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public void canCRUDRoleAssignment() throws Exception {
3333
.forServicePrincipal(sp)
3434
.withBuiltInRole(BuiltInRole.CONTRIBUTOR)
3535
.withSubscriptionScope(resourceManager.subscriptionId())
36+
.withDescription("contributor role")
3637
.create();
3738

3839
Assertions.assertNotNull(roleAssignment);
@@ -46,6 +47,7 @@ public void canCRUDRoleAssignment() throws Exception {
4647
Assertions.assertEquals(roleAssignment.scope(), roleAssignment1.scope());
4748
Assertions.assertEquals(roleAssignment.roleDefinitionId(), roleAssignment1.roleDefinitionId());
4849
Assertions.assertEquals(roleAssignment.principalId(), roleAssignment1.principalId());
50+
Assertions.assertEquals("contributor role", roleAssignment1.description());
4951
} finally {
5052
authorizationManager.servicePrincipals().deleteById(sp.id());
5153
authorizationManager

0 commit comments

Comments
 (0)