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

Initial AccessControlClient for Azure.Security.KeyVault.Administration #12480

Merged
merged 21 commits into from
Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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 @@ -7,7 +7,6 @@ public KeyVaultAccessControlClient(System.Uri vaultUri, Azure.Core.TokenCredenti
public KeyVaultAccessControlClient(System.Uri vaultUri, Azure.Core.TokenCredential credential, Azure.Security.KeyVault.Administration.KeyVaultAccessControlClientOptions options) { }
public virtual System.Uri VaultUri { get { throw null; } }
public virtual Azure.Response<Azure.Security.KeyVault.Administration.Models.RoleAssignment> CreateRoleAssignment(Azure.Security.KeyVault.Administration.RoleAssignmentScope roleScope, Azure.Security.KeyVault.Administration.Models.RoleAssignmentProperties properties, System.Guid name = default(System.Guid), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
christothes marked this conversation as resolved.
Show resolved Hide resolved
public virtual Azure.Response<Azure.Security.KeyVault.Administration.Models.RoleAssignment> CreateRoleAssignment(Azure.Security.KeyVault.Administration.RoleAssignmentScope roleScope, Azure.Security.KeyVault.Administration.Models.RoleAssignmentProperties properties, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Security.KeyVault.Administration.Models.RoleAssignment>> CreateRoleAssignmentAsync(Azure.Security.KeyVault.Administration.RoleAssignmentScope roleScope, Azure.Security.KeyVault.Administration.Models.RoleAssignmentProperties properties, System.Guid name = default(System.Guid), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.Security.KeyVault.Administration.Models.RoleAssignment> DeleteRoleAssignment(Azure.Security.KeyVault.Administration.RoleAssignmentScope roleScope, string roleAssignmentName, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
christothes marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also put the id first, which is more common.

public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Security.KeyVault.Administration.Models.RoleAssignment>> DeleteRoleAssignmentAsync(Azure.Security.KeyVault.Administration.RoleAssignmentScope roleScope, string roleAssignmentName, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
Expand All @@ -34,8 +33,8 @@ public enum ServiceVersion
private readonly int _dummyPrimitive;
public RoleAssignmentScope(string value) { throw null; }
public RoleAssignmentScope(System.Uri ResourceId) { throw null; }
public static Azure.Security.KeyVault.Administration.RoleAssignmentScope Global { get { throw null; } }
public static Azure.Security.KeyVault.Administration.RoleAssignmentScope Keys { get { throw null; } }
public static Azure.Security.KeyVault.Administration.RoleAssignmentScope Root { get { throw null; } }
public bool Equals(Azure.Security.KeyVault.Administration.RoleAssignmentScope other) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public override bool Equals(object obj) { throw null; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,24 @@
<NoWarn>$(NoWarn);3021;CA1812</NoWarn>
</PropertyGroup>

<Import Project="..\..\Azure.Security.KeyVault.Shared\src\Azure.Security.KeyVault.Shared.projitems" Label="Shared" />
<!-- <Import Project="..\..\Azure.Security.KeyVault.Shared\src\Azure.Security.KeyVault.Shared.projitems" Label="Shared" /> -->
christothes marked this conversation as resolved.
Show resolved Hide resolved

<ItemGroup>
<PackageReference Include="System.Text.Json" />
</ItemGroup>

<ItemGroup>
<!-- Include just the few items we need from Azure.Security.KeyVault.Shared -->
<Compile Include="$(MSBuildThisFileDirectory)\..\..\Azure.Security.KeyVault.Shared\src\ChallengeBasedAuthenticationPolicy.cs" />
<Compile Include="$(MSBuildThisFileDirectory)\..\..\Azure.Security.KeyVault.Shared\src\ClientOptionsExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)\..\..\Azure.Security.KeyVault.Shared\src\IJsonSerializable.cs" />
</ItemGroup>

<ItemGroup>
<Compile Include="$(AzureCoreSharedSources)NoBodyResponse{T}.cs" Link="Shared\Core\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureCoreSharedSources)ForwardsClientCallsAttribute.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
</ItemGroup>

<ItemGroup>
<Compile Include="$(AzureCoreSharedSources)Argument.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureCoreSharedSources)ArrayBufferWriter.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
Expand All @@ -28,6 +37,7 @@
<Compile Include="$(AzureCoreSharedSources)ContentTypeUtilities.cs" Link="Shared\Core\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureCoreSharedSources)DiagnosticScope.cs" Link="Shared\Core\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureCoreSharedSources)DiagnosticScopeFactory.cs" Link="Shared\Core\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureCoreSharedSources)HashCodeBuilder.cs" Link="Shared\Core\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureCoreSharedSources)HttpMessageSanitizer.cs" Link="Shared\Core\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureCoreSharedSources)OperationHelpers.cs" Link="Shared\Core\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureCoreSharedSources)TaskExtensions.cs" Link="Shared\Core\%(RecursiveDir)\%(Filename)%(Extension)" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ public KeyVaultAccessControlClient(Uri vaultUri, TokenCredential credential, Key
Argument.AssertNotNull(credential, nameof(credential));

VaultUri = vaultUri;
Argument.AssertNotNull(vaultUri, nameof(vaultUri));
Argument.AssertNotNull(credential, nameof(credential));

options ??= new KeyVaultAccessControlClientOptions();
string apiVersion = options.GetVersionString();
Expand All @@ -77,6 +75,7 @@ public KeyVaultAccessControlClient(Uri vaultUri, TokenCredential credential, Key
/// </summary>
/// <param name="roleScope"> The scope of the role assignments. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
/// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception>
christothes marked this conversation as resolved.
Show resolved Hide resolved
public virtual Pageable<RoleDefinition> GetRoleDefinitions(RoleAssignmentScope roleScope, CancellationToken cancellationToken = default)
{
return PageableHelpers.CreateEnumerable(_ =>
Expand Down Expand Up @@ -115,6 +114,7 @@ public virtual Pageable<RoleDefinition> GetRoleDefinitions(RoleAssignmentScope r
/// </summary>
/// <param name="roleScope"> The scope of the role definition. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
/// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception>
public virtual AsyncPageable<RoleDefinition> GetRoleDefinitionsAsync(RoleAssignmentScope roleScope, CancellationToken cancellationToken = default)
{
return PageableHelpers.CreateAsyncEnumerable(async _ =>
Expand Down Expand Up @@ -151,10 +151,11 @@ public virtual AsyncPageable<RoleDefinition> GetRoleDefinitionsAsync(RoleAssignm
}

/// <summary>
///
/// Gets the <see cref="RoleAssignment"/>s for a scope.
/// </summary>
/// <param name="roleScope"> The scope of the role assignments. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
/// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception>
public virtual Pageable<RoleAssignment> GetRoleAssignments(RoleAssignmentScope roleScope, CancellationToken cancellationToken = default)
{
return PageableHelpers.CreateEnumerable(_ =>
Expand Down Expand Up @@ -193,6 +194,7 @@ public virtual Pageable<RoleAssignment> GetRoleAssignments(RoleAssignmentScope r
/// </summary>
/// <param name="roleScope"> The scope of the role assignments. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
/// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception>
public virtual AsyncPageable<RoleAssignment> GetRoleAssignmentsAsync(RoleAssignmentScope roleScope, CancellationToken cancellationToken = default)
{
return PageableHelpers.CreateAsyncEnumerable(async _ =>
Expand Down Expand Up @@ -228,41 +230,22 @@ public virtual AsyncPageable<RoleAssignment> GetRoleAssignmentsAsync(RoleAssignm
});
}

/// <summary>
/// Creates a <see cref="RoleAssignment"/>.
/// </summary>
/// <param name="roleScope"> The scope of the role assignment to create. </param>
/// <param name="properties"> Properties for the role assignment. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public virtual Response<RoleAssignment> CreateRoleAssignment(RoleAssignmentScope roleScope, RoleAssignmentProperties properties, CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _diagnostics.CreateScope($"{nameof(KeyVaultAccessControlClient)}.{nameof(CreateRoleAssignment)}");
scope.Start();
try
{
return _assignmentsRestClient.Create(VaultUri.AbsoluteUri, roleScope.ToString(), Guid.NewGuid().ToString(), properties, cancellationToken);
}
catch (Exception ex)
{
scope.Failed(ex);
throw;
}
}

/// <summary>
/// Creates a <see cref="RoleAssignment"/>.
/// </summary>
/// <param name="roleScope"> The scope of the role assignment to create. </param>
/// <param name="properties"> Properties for the role assignment. </param>
/// <param name="name">The Name used to create the role assignment.</param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
/// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception>
public virtual Response<RoleAssignment> CreateRoleAssignment(RoleAssignmentScope roleScope, RoleAssignmentProperties properties, Guid name = default, CancellationToken cancellationToken = default)
heaths marked this conversation as resolved.
Show resolved Hide resolved
{
using DiagnosticScope scope = _diagnostics.CreateScope($"{nameof(KeyVaultAccessControlClient)}.{nameof(CreateRoleAssignment)}");
scope.Start();
try
{
return _assignmentsRestClient.Create(VaultUri.AbsoluteUri, roleScope.ToString(), name == default ? Guid.NewGuid().ToString() : name.ToString(), properties, cancellationToken);
var _name = name == default ? Guid.NewGuid().ToString() : name.ToString();
return _assignmentsRestClient.Create(VaultUri.AbsoluteUri, roleScope.ToString(), _name, properties, cancellationToken);
}
catch (Exception ex)
{
Expand All @@ -278,13 +261,15 @@ public virtual Response<RoleAssignment> CreateRoleAssignment(RoleAssignmentScope
/// <param name="properties"> Properties for the role assignment. </param>
/// <param name="name">The name used to create the role assignment.</param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
/// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception>
public virtual async Task<Response<RoleAssignment>> CreateRoleAssignmentAsync(RoleAssignmentScope roleScope, RoleAssignmentProperties properties, Guid name = default, CancellationToken cancellationToken = default)
christothes marked this conversation as resolved.
Show resolved Hide resolved
{
using DiagnosticScope scope = _diagnostics.CreateScope($"{nameof(KeyVaultAccessControlClient)}.{nameof(CreateRoleAssignment)}");
scope.Start();
try
{
return await _assignmentsRestClient.CreateAsync(VaultUri.AbsoluteUri, roleScope.ToString(), name == default ? Guid.NewGuid().ToString() : name.ToString(), properties, cancellationToken)
var _name = name == default ? Guid.NewGuid().ToString() : name.ToString();
return await _assignmentsRestClient.CreateAsync(VaultUri.AbsoluteUri, roleScope.ToString(), _name, properties, cancellationToken)
.ConfigureAwait(false);
}
catch (Exception ex)
Expand All @@ -300,6 +285,7 @@ public virtual async Task<Response<RoleAssignment>> CreateRoleAssignmentAsync(Ro
/// <param name="roleScope"> The scope of the role assignment. </param>
/// <param name="roleAssignmentName"> The name of the role assignment to get. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
/// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception>
public virtual Response<RoleAssignment> GetRoleAssignment(RoleAssignmentScope roleScope, string roleAssignmentName, CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _diagnostics.CreateScope($"{nameof(KeyVaultAccessControlClient)}.{nameof(GetRoleAssignment)}");
Expand All @@ -321,6 +307,7 @@ public virtual Response<RoleAssignment> GetRoleAssignment(RoleAssignmentScope ro
/// <param name="roleScope"> The scope of the role assignment. </param>
/// <param name="roleAssignmentName"> The name of the role assignment to get. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
/// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception>
public virtual async Task<Response<RoleAssignment>> GetRoleAssignmentAsync(RoleAssignmentScope roleScope, string roleAssignmentName, CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _diagnostics.CreateScope($"{nameof(KeyVaultAccessControlClient)}.{nameof(GetRoleAssignment)}");
Expand All @@ -343,6 +330,7 @@ public virtual async Task<Response<RoleAssignment>> GetRoleAssignmentAsync(RoleA
/// <param name="roleScope"> The scope of the role assignment. </param>
/// <param name="roleAssignmentName"> The name of the role assignment to get. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
/// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception>
public virtual Response<RoleAssignment> DeleteRoleAssignment(RoleAssignmentScope roleScope, string roleAssignmentName, CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _diagnostics.CreateScope($"{nameof(KeyVaultAccessControlClient)}.{nameof(DeleteRoleAssignment)}");
Expand All @@ -364,6 +352,7 @@ public virtual Response<RoleAssignment> DeleteRoleAssignment(RoleAssignmentScope
/// <param name="roleScope"> The scope of the role assignment. </param>
/// <param name="roleAssignmentName"> The name of the role assignment to get. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
/// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception>
public virtual async Task<Response<RoleAssignment>> DeleteRoleAssignmentAsync(RoleAssignmentScope roleScope, string roleAssignmentName, CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _diagnostics.CreateScope($"{nameof(KeyVaultAccessControlClient)}.{nameof(DeleteRoleAssignment)}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Azure.Security.KeyVault.Administration
{
/// <summary>
/// Options that allow you to configure the requests sent to Key Vault.
/// Options to configure the requests sent to Key Vault.
/// </summary>
public class KeyVaultAccessControlClientOptions : ClientOptions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Azure.Security.KeyVault.Administration
/// </summary>
public readonly struct RoleAssignmentScope : IEquatable<RoleAssignmentScope>
{
internal const string RootValue = "/";
internal const string GlobalValue = "/";
internal const string KeysValue = "/keys";

private readonly string _value;
Expand All @@ -35,12 +35,12 @@ public RoleAssignmentScope(Uri ResourceId)
}

/// <summary>
/// Root.
/// Role assignments apply to everything on the resource.
/// </summary>
public static RoleAssignmentScope Root { get; } = new RoleAssignmentScope(RootValue);
public static RoleAssignmentScope Global { get; } = new RoleAssignmentScope(GlobalValue);

/// <summary>
/// Keys.
/// Role assignments apply to all Keys.
/// </summary>
public static RoleAssignmentScope Keys { get; } = new RoleAssignmentScope(KeysValue);

Expand Down
Loading