Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated support for synapse role assignment and Added support for role scope #14172

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
062146a
fixing compliationerror
zesluo Feb 10, 2021
97f37c4
getroleassignment
zesluo Feb 19, 2021
d2fa903
refine parametersetname
zesluo Mar 12, 2021
b1cd8b5
Merge branch 'master' into zeshi/accesscontrolnewsdk
zesluo Mar 12, 2021
7197b83
add scope to newroleassignment
zesluo Mar 15, 2021
5487fc7
add list scope command
zesluo Mar 15, 2021
0d10f47
refine new-azuresynapseroleassignment
zesluo Mar 16, 2021
f412876
add Itemtype and Item
zesluo Mar 16, 2021
e787196
refine newAzureSynapseRoleAssignment
zesluo Mar 19, 2021
df14f92
remove unnecessary feeds
zesluo Mar 19, 2021
2a509b7
refine deleteroleassignmentid
zesluo Mar 23, 2021
84236ef
refine resourceid name
zesluo Mar 23, 2021
6a3ca26
improve remove and getroleassignments
zesluo Mar 31, 2021
585d3f7
itemtype and item improvement
zesluo Apr 1, 2021
7284040
Fix a few issues
Apr 2, 2021
2583a84
Correct exception types
Apr 2, 2021
91e1e29
add principle type
zesluo Apr 5, 2021
c8555d3
add principaltype
zesluo Apr 6, 2021
ee1ba9a
Merge branch 'master' of https://github.com/Azure/azure-powershell in…
zesluo Apr 6, 2021
ab1f2e7
caseinsent
zesluo Apr 6, 2021
12ea62c
update changelog
zesluo Apr 6, 2021
850226c
add doc for get-azsyanpserolescope
zesluo Apr 6, 2021
c8184ca
remove powershlles
zesluo Apr 6, 2021
24232cb
update help doc
zesluo Apr 6, 2021
351318e
add objectid back
zesluo Apr 6, 2021
eba1c34
update Az.Synapse.md
zesluo Apr 6, 2021
4f35647
update auto generated mdfiles
zesluo Apr 6, 2021
43c8e1d
update changelog
zesluo Apr 7, 2021
d6f8a4c
update changelog2
zesluo Apr 7, 2021
bc5873e
update changelog3
zesluo Apr 7, 2021
99336aa
update changelog4
zesluo Apr 7, 2021
11576cd
update changelog5
zesluo Apr 8, 2021
ce1fb1f
update changelog6
zesluo Apr 8, 2021
05c3fc1
update changelog7
zesluo Apr 8, 2021
4e6c2fa
Update src/Synapse/Synapse/ChangeLog.md
zesluo Apr 8, 2021
474ae0d
Merge branch 'release-2021-04-13' into zeshi/accesscontrolnewsdk
BethanyZhou Apr 8, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ public class NewAzureSynapseRoleAssignment : SynapseRoleCmdletBase
private const string NewByWorkspaceNameAndIdParameterSet = "NewByWorkspaceNameAndIdParameterSet";
private const string NewByWorkspaceObjectAndNameParameterSet = "NewByWorkspaceObjectAndNameParameterSet";
private const string NewByWorkspaceObjectAndIdParameterSet = "NewByWorkspaceObjectAndIdParameterSet";
private const string NewByWorkspaceNameAndRoleDefinitionIdAndObjectIdParameterSet = "NewByWorkspaceNameAndRoleDefinitionIdAndObjectIdParameterSet";
private const string NewByWorkspaceObjectAndRoleDefinitionIdAndObjectIdParameterSet = "NewByWorkspaceObjectAndRoleDefinitionIdAndObjectIdParameterSet";
private const string NewByWorkspaceNameAndRoleAssignmentIdAndObjectIdParameterSet = "NewByWorkspaceNameAndRoleAssignmentIdAndObjectIdParameterSet";
private const string NewByWorkspaceObjectAndRoleAssignmentIdAndObjectIdParameterSet = "NewByWorkspaceObjectAndRoleAssignmentIdAndObjectIdParameterSet";
private const string NewByWorkspaceNameAndServicePrincipalNameParameterSet = "NewByWorkspaceNameAndServicePrincipalNameParameterSet";
private const string NewByWorkspaceObjectAndServicePrincipalNameParameterSet = "NewByWorkspaceObjectAndServicePrincipalNameParameterSet";
zesluo marked this conversation as resolved.
Show resolved Hide resolved

[Parameter(ValueFromPipelineByPropertyName = false, ParameterSetName = NewByWorkspaceNameAndNameParameterSet,
Mandatory = true, HelpMessage = HelpMessages.WorkspaceName)]
[Parameter(ValueFromPipelineByPropertyName = false, ParameterSetName = NewByWorkspaceNameAndIdParameterSet,
Mandatory = true, HelpMessage = HelpMessages.WorkspaceName)]
[Parameter(ValueFromPipelineByPropertyName = false, ParameterSetName = NewByWorkspaceNameAndRoleDefinitionIdAndObjectIdParameterSet,
[Parameter(ValueFromPipelineByPropertyName = false, ParameterSetName = NewByWorkspaceNameAndRoleAssignmentIdAndObjectIdParameterSet,
Mandatory = true, HelpMessage = HelpMessages.WorkspaceName)]
[Parameter(ValueFromPipelineByPropertyName = false, ParameterSetName = NewByWorkspaceNameAndServicePrincipalNameParameterSet,
Mandatory = true, HelpMessage = HelpMessages.WorkspaceName)]
Expand All @@ -41,7 +41,7 @@ public class NewAzureSynapseRoleAssignment : SynapseRoleCmdletBase
Mandatory = true, HelpMessage = HelpMessages.WorkspaceObject)]
[Parameter(ValueFromPipeline = true, ParameterSetName = NewByWorkspaceObjectAndIdParameterSet,
Mandatory = true, HelpMessage = HelpMessages.WorkspaceObject)]
[Parameter(ValueFromPipeline = true, ParameterSetName = NewByWorkspaceObjectAndRoleDefinitionIdAndObjectIdParameterSet,
[Parameter(ValueFromPipeline = true, ParameterSetName = NewByWorkspaceObjectAndRoleAssignmentIdAndObjectIdParameterSet,
Mandatory = true, HelpMessage = HelpMessages.WorkspaceObject)]
[Parameter(ValueFromPipeline = true, ParameterSetName = NewByWorkspaceObjectAndServicePrincipalNameParameterSet,
Mandatory = true, HelpMessage = HelpMessages.WorkspaceObject)]
Expand All @@ -63,13 +63,20 @@ public class NewAzureSynapseRoleAssignment : SynapseRoleCmdletBase
[ValidateNotNullOrEmpty]
public string RoleDefinitionName { get; set; }

[Parameter(ValueFromPipelineByPropertyName = false, ParameterSetName = NewByWorkspaceNameAndRoleDefinitionIdAndObjectIdParameterSet,
[Parameter(ValueFromPipelineByPropertyName = false, ParameterSetName = NewByWorkspaceNameAndRoleAssignmentIdAndObjectIdParameterSet,
Mandatory = true, HelpMessage = HelpMessages.RoleDefinitionId)]
[Parameter(ValueFromPipelineByPropertyName = false, ParameterSetName = NewByWorkspaceObjectAndRoleDefinitionIdAndObjectIdParameterSet,
[Parameter(ValueFromPipelineByPropertyName = false, ParameterSetName = NewByWorkspaceObjectAndRoleAssignmentIdAndObjectIdParameterSet,
Mandatory = true, HelpMessage = HelpMessages.RoleDefinitionId)]
[ValidateNotNullOrEmpty]
public string RoleDefinitionId { get; set; }

[Parameter(ValueFromPipelineByPropertyName = false, ParameterSetName = NewByWorkspaceNameAndRoleAssignmentIdAndObjectIdParameterSet,
Mandatory = true, HelpMessage = HelpMessages.RoleAssignmentId)]
[Parameter(ValueFromPipelineByPropertyName = false, ParameterSetName = NewByWorkspaceObjectAndRoleAssignmentIdAndObjectIdParameterSet,
Mandatory = true, HelpMessage = HelpMessages.RoleAssignmentId)]
[ValidateNotNullOrEmpty]
public string RoleAssignmentId { get; set; }
zesluo marked this conversation as resolved.
Show resolved Hide resolved

[Parameter(ValueFromPipelineByPropertyName = false, ParameterSetName = NewByWorkspaceNameAndNameParameterSet,
Mandatory = true, HelpMessage = HelpMessages.SignInName)]
[Parameter(ValueFromPipelineByPropertyName = false, ParameterSetName = NewByWorkspaceObjectAndNameParameterSet,
Expand All @@ -89,14 +96,21 @@ public class NewAzureSynapseRoleAssignment : SynapseRoleCmdletBase
Mandatory = true, HelpMessage = HelpMessages.PrincipalId)]
[Parameter(ValueFromPipelineByPropertyName = false, ParameterSetName = NewByWorkspaceObjectAndIdParameterSet,
Mandatory = true, HelpMessage = HelpMessages.PrincipalId)]
[Parameter(ValueFromPipelineByPropertyName = false, ParameterSetName = NewByWorkspaceNameAndRoleDefinitionIdAndObjectIdParameterSet,
[Parameter(ValueFromPipelineByPropertyName = false, ParameterSetName = NewByWorkspaceNameAndRoleAssignmentIdAndObjectIdParameterSet,
Mandatory = true, HelpMessage = HelpMessages.PrincipalId)]
[Parameter(ValueFromPipelineByPropertyName = false, ParameterSetName = NewByWorkspaceObjectAndRoleDefinitionIdAndObjectIdParameterSet,
[Parameter(ValueFromPipelineByPropertyName = false, ParameterSetName = NewByWorkspaceObjectAndRoleAssignmentIdAndObjectIdParameterSet,
Mandatory = true, HelpMessage = HelpMessages.PrincipalId)]
[Alias("Id", "PrincipalId")]
[ValidateNotNullOrEmpty]
public string ObjectId { get; set; }

[Parameter(ValueFromPipelineByPropertyName = false, ParameterSetName = NewByWorkspaceNameAndIdParameterSet,
Mandatory = true, HelpMessage = HelpMessages.Scope)]
[Parameter(ValueFromPipelineByPropertyName = false, ParameterSetName = NewByWorkspaceObjectAndIdParameterSet,
Mandatory = true, HelpMessage = HelpMessages.Scope)]
[ValidateNotNullOrEmpty]
public string Scope { get; set; }

[Parameter(Mandatory = false, HelpMessage = HelpMessages.AsJob)]
public SwitchParameter AsJob { get; set; }

Expand All @@ -122,9 +136,9 @@ public override void ExecuteCmdlet()
this.ObjectId = SynapseAnalyticsClient.GetObjectIdFromServicePrincipalName(this.ServicePrincipalName);
}

if (this.ShouldProcess(this.WorkspaceName, String.Format(Resources.CreatingSynapseRoleAssignment, this.WorkspaceName, this.RoleDefinitionId, this.ObjectId)))
if (this.ShouldProcess(this.WorkspaceName, String.Format(Resources.CreatingSynapseRoleAssignment, this.WorkspaceName, this.RoleAssignmentId, this.ObjectId)))
{
PSRoleAssignmentDetails roleAssignmentDetails = new PSRoleAssignmentDetails(SynapseAnalyticsClient.CreateRoleAssignment(this.RoleDefinitionId, this.ObjectId));
PSRoleAssignmentDetails roleAssignmentDetails = new PSRoleAssignmentDetails(SynapseAnalyticsClient.CreateRoleAssignment(this.RoleAssignmentId, this.RoleDefinitionId, this.ObjectId, this.Scope));
WriteObject(roleAssignmentDetails);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/Synapse/Synapse/Common/HelpMessages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ SELECT on dbo.myTable by public

public const string PrincipalId = "The Azure AD ObjectId of the User, Group or Service Principal.";

public const string Scope = "The Scope of the user.";
zesluo marked this conversation as resolved.
Show resolved Hide resolved

public const string SignInName = "The email address or the user principal name of the user.";

public const string ServicePrincipalName = "The ServicePrincipalName of the service principal.";
Expand Down
4 changes: 2 additions & 2 deletions src/Synapse/Synapse/Models/PSRoleAssignmentDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public class PSRoleAssignmentDetails
public PSRoleAssignmentDetails(RoleAssignmentDetails roleAssignmentDetails)
{
this.RoleAssignmentId = roleAssignmentDetails.Id;
this.RoleDefinitionId = roleAssignmentDetails.RoleId;
this.ObjectId = roleAssignmentDetails.PrincipalId;
this.RoleDefinitionId = roleAssignmentDetails.RoleDefinitionId.ToString();
this.ObjectId = roleAssignmentDetails.PrincipalId.ToString();
}
zesluo marked this conversation as resolved.
Show resolved Hide resolved

public string RoleAssignmentId { get; set; }
Expand Down
6 changes: 3 additions & 3 deletions src/Synapse/Synapse/Models/PSSynapseRole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ namespace Microsoft.Azure.Commands.Synapse.Models
{
public class PSSynapseRole
{
public PSSynapseRole(SynapseRole synapseRole)
public PSSynapseRole(SynapseRoleDefinition synapseRole)
{
this.Id = synapseRole.Id;
this.Id = synapseRole.Id.ToString();
zesluo marked this conversation as resolved.
Show resolved Hide resolved
this.Name = synapseRole.Name;
this.IsBuiltIn = synapseRole.IsBuiltIn;
}
zesluo marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -18,6 +18,6 @@ public PSSynapseRole(SynapseRole synapseRole)

public string Name { get; set; }

public bool IsBuiltIn { get; set; }
public bool? IsBuiltIn { get; set; }
}
}
32 changes: 17 additions & 15 deletions src/Synapse/Synapse/Models/SynapseAnalyticsRoleClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ namespace Microsoft.Azure.Commands.Synapse.Models
{
public class SynapseAnalyticsRoleClient
{
private readonly AccessControlClient _accessControlClient;
private readonly RoleAssignmentsClient _roleAssignmentsClient;
private readonly RoleDefinitionsClient _roleDefinitionsClient;
private readonly ActiveDirectoryClient _activeDirectoryClient;

public SynapseAnalyticsRoleClient(string workspaceName, IAzureContext context)
Expand All @@ -29,45 +30,46 @@ public SynapseAnalyticsRoleClient(string workspaceName, IAzureContext context)

string suffix = context.Environment.GetEndpoint(AzureEnvironment.ExtendedEndpoint.AzureSynapseAnalyticsEndpointSuffix);
Uri uri = new Uri("https://" + workspaceName + "." + suffix);
_accessControlClient = new AccessControlClient(uri, new AzureSessionCredential(context));
_roleAssignmentsClient = new RoleAssignmentsClient(uri, new AzureSessionCredential(context));
_roleDefinitionsClient = new RoleDefinitionsClient(uri, new AzureSessionCredential(context));
_activeDirectoryClient = new ActiveDirectoryClient(context);
}

public IReadOnlyList<RoleAssignmentDetails> ListRoleAssignments(string roleDefinitionId = null, string objectId = null, string continuationToken = null)
{
return _accessControlClient.GetRoleAssignments(roleDefinitionId, objectId, continuationToken).Value;
return (IReadOnlyList<RoleAssignmentDetails>)_roleAssignmentsClient.ListRoleAssignments(roleDefinitionId, objectId, continuationToken).Value;
}

public RoleAssignmentDetails GetRoleAssignmentById(string roleAssignmentId)
{
return _accessControlClient.GetRoleAssignmentById(roleAssignmentId);
return _roleAssignmentsClient.GetRoleAssignmentById(roleAssignmentId);
}

public RoleAssignmentDetails CreateRoleAssignment(string roleDefinitionId, string objectId)
public RoleAssignmentDetails CreateRoleAssignment(string roleAssignmentId, string RoleDefinitionId, string objectId, string scope)
{
RoleAssignmentOptions roleAssignmentOptions = new RoleAssignmentOptions(roleDefinitionId, objectId);
return _accessControlClient.CreateRoleAssignment(roleAssignmentOptions).Value;
//RoleAssignmentOptions roleAssignmentOptions = new RoleAssignmentOptions(roleAssignmentId, objectId);
zesluo marked this conversation as resolved.
Show resolved Hide resolved
return _roleAssignmentsClient.CreateRoleAssignment(roleAssignmentId, new Guid(RoleDefinitionId), new Guid(objectId), scope);
}

public void DeleteRoleAssignmentById(string roleAssignmentId)
{
_accessControlClient.DeleteRoleAssignmentById(roleAssignmentId);
_roleAssignmentsClient.DeleteRoleAssignmentById(roleAssignmentId);
}

public void DeleteRoleAssignmentByName(string roleDefinitionId, string objectId)
{
string roleAssignmentId = roleDefinitionId + "-" + objectId;
_accessControlClient.DeleteRoleAssignmentById(roleAssignmentId);
_roleAssignmentsClient.DeleteRoleAssignmentById(roleAssignmentId);
}
zesluo marked this conversation as resolved.
Show resolved Hide resolved

public Pageable<SynapseRole> GetRoleDefinitions()
public IReadOnlyList<SynapseRoleDefinition> GetRoleDefinitions()
{
return _accessControlClient.GetRoleDefinitions();
return (IReadOnlyList<SynapseRoleDefinition>)_roleDefinitionsClient.ListRoleDefinitions();
zesluo marked this conversation as resolved.
Show resolved Hide resolved
}

public SynapseRole GetRoleDefinitionById(string roleId)
public SynapseRoleDefinition GetRoleDefinitionById(string roleId)
{
return _accessControlClient.GetRoleDefinitionById(roleId).Value;
return _roleDefinitionsClient.GetRoleDefinitionById(roleId).Value;
}

public string GetObjectIdFromSignInName(string signInName)
Expand Down Expand Up @@ -106,12 +108,12 @@ public string GetRoleDefinitionIdFromRoleDefinitionName(string roleDefinitionNam
{
return null;
}
var roleDefinition = _accessControlClient.GetRoleDefinitions().SingleOrDefault(element => element.Name == roleDefinitionName);
var roleDefinition = _roleDefinitionsClient.ListRoleDefinitions().Value.SingleOrDefault(element => element.Name == roleDefinitionName);
zesluo marked this conversation as resolved.
Show resolved Hide resolved
if (roleDefinition == null)
{
throw new InvalidOperationException(String.Format(Resources.RoleDefinitionNameDoesNotExist, roleDefinitionName));
}
return roleDefinition.Id;
return roleDefinition.Id.ToString();
}
}
}
Binary file not shown.
Binary file not shown.