public override void ExecuteCmdlet() { if (this.IsParameterBound(c => c.WorkspaceObject)) { this.WorkspaceName = this.WorkspaceObject.Name; } if (this.IsParameterBound(c => c.RoleDefinitionName)) { this.RoleDefinitionId = SynapseAnalyticsClient.GetRoleDefinitionIdFromRoleDefinitionName(this.RoleDefinitionName); } if (this.IsParameterBound(c => c.SignInName)) { this.ObjectId = SynapseAnalyticsClient.GetObjectIdFromSignInName(this.SignInName); } if (this.IsParameterBound(c => c.ServicePrincipalName)) { this.ObjectId = SynapseAnalyticsClient.GetObjectIdFromServicePrincipalName(this.ServicePrincipalName); } if (this.ShouldProcess(this.WorkspaceName, String.Format(Resources.CreatingSynapseRoleAssignment, this.WorkspaceName, this.RoleDefinitionId, this.ObjectId))) { PSRoleAssignmentDetails roleAssignmentDetails = new PSRoleAssignmentDetails(SynapseAnalyticsClient.CreateRoleAssignment(this.RoleDefinitionId, this.ObjectId)); WriteObject(roleAssignmentDetails); } }
public override void ExecuteCmdlet() { if (this.IsParameterBound(c => c.WorkspaceObject)) { this.WorkspaceName = this.WorkspaceObject.Name; } if (this.IsParameterBound(c => c.RoleDefinitionName)) { this.RoleDefinitionId = SynapseAnalyticsClient.GetRoleDefinitionIdFromRoleDefinitionName(this.RoleDefinitionName); } if (this.IsParameterBound(c => c.SignInName)) { this.ObjectId = SynapseAnalyticsClient.GetObjectIdFromSignInName(this.SignInName); } if (this.IsParameterBound(c => c.ServicePrincipalName)) { this.ObjectId = SynapseAnalyticsClient.GetObjectIdFromServicePrincipalName(this.ServicePrincipalName); } string itemType = null; if (this.IsParameterBound(c => c.ItemType)) { itemType = this.ItemType.GetItemTypeString(); } string principalType = null; if (this.IsParameterBound(c => c.PrincipalType)) { principalType = this.PrincipalType.GetPrincipalTypeString(); } if (this.ShouldProcess(this.WorkspaceName, String.Format(Resources.CreatingSynapseRoleAssignment, this.WorkspaceName, this.RoleDefinitionId, this.ObjectId))) { // Item type and item should appear Report error if either item type or item is specified. if ((!this.IsParameterBound(c => c.ItemType) && this.IsParameterBound(c => c.Item)) || (this.IsParameterBound(c => c.ItemType) && !this.IsParameterBound(c => c.Item))) { throw new AzPSInvalidOperationException(String.Format(Resources.WorkspaceItemTypeAndItemNotAppearTogether)); } string roleAssignmentId = Guid.NewGuid().ToString(); string scope = SynapseAnalyticsClient.GetRoleAssignmentScope(this.WorkspaceName, itemType, this.Item); PSRoleAssignmentDetails roleAssignmentDetails = new PSRoleAssignmentDetails(SynapseAnalyticsClient.CreateRoleAssignment(roleAssignmentId, this.RoleDefinitionId, this.ObjectId, scope, principalType)); WriteObject(roleAssignmentDetails); } }