Skip to content

Commit

Permalink
Apply ClientOptions analyzers to client libraries. (#6915)
Browse files Browse the repository at this point in the history
  • Loading branch information
annelo-msft authored and pakrym committed Jul 16, 2019
1 parent 369ea8e commit 9dea72e
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 3 deletions.
2 changes: 1 addition & 1 deletion eng/Packages.Data.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<ItemGroup>
<PackageReference Update="ApprovalTests" Version="3.0.22" />
<PackageReference Update="ApprovalUtilities" Version="3.0.22" />
<PackageReference Update="Azure.ClientSdk.Analyzers" Version="0.1.1-dev.20190503.1" />
<PackageReference Update="Azure.ClientSdk.Analyzers" Version="0.1.1-dev.20190711.4" />
<PackageReference Update="Azure.Core" Version="1.0.0-preview.6" />
<PackageReference Update="BenchmarkDotNet" Version="0.11.5" />
<PackageReference Update="FsCheck.Xunit" Version="2.14.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,36 @@ namespace Azure.ApplicationModel.Configuration
/// </summary>
public class ConfigurationClientOptions: ClientOptions
{
/// <summary>
/// The latest service version supported by this client library.
/// </summary>
internal const ServiceVersion LatestVersion = ServiceVersion.Default;

/// <summary>
/// The versions of App Config Service supported by this client library.
/// </summary>
public enum ServiceVersion
{
Default = 0
}

/// <summary>
/// Gets the <see cref="ServiceVersion"/> of the service API used when
/// making requests.
/// </summary>
public ServiceVersion Version { get; }

/// <summary>
/// Initializes a new instance of the <see cref="ConfigurationClientOptions"/>
/// class.
/// </summary>
/// <param name="version">
/// The <see cref="ServiceVersion"/> of the service API used when
/// making requests.
/// </param>
public ConfigurationClientOptions(ServiceVersion version = ServiceVersion.Default)
{
this.Version = version;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,45 @@ namespace Azure.Security.KeyVault.Certificates
{
public class CertificateClientOptions : ClientOptions
{
/// <summary>
/// The latest service version supported by this client library.
/// For more information, see
/// <see href="https://docs.microsoft.com/en-us/rest/api/keyvault/key-vault-versions"/>
/// </summary>
internal const ServiceVersion LatestVersion = ServiceVersion.V7_0;

/// <summary>
/// The versions of Azure Key Vault supported by this client
/// library.
/// </summary>
public enum ServiceVersion
{
#pragma warning disable CA1707 // Identifiers should not contain underscores
/// <summary>
/// The Key Vault API version 7.0.
/// </summary>
V7_0 = 0
#pragma warning restore CA1707 // Identifiers should not contain underscores
}

/// <summary>
/// Gets the <see cref="ServiceVersion"/> of the service API used when
/// making requests. For more information, see
/// <see href="https://docs.microsoft.com/en-us/rest/api/keyvault/key-vault-versions"/>
/// </summary>
public ServiceVersion Version { get; }

/// <summary>
/// Initializes a new instance of the <see cref="CertificateClientOptions"/>
/// class.
/// </summary>
/// <param name="version">
/// The <see cref="ServiceVersion"/> of the service API used when
/// making requests.
/// </param>
public CertificateClientOptions(ServiceVersion version = ServiceVersion.V7_0)
{
this.Version = version;
}
}
}
1 change: 1 addition & 0 deletions sdk/keyvault/Azure.Security.KeyVault.Keys/src/KeyClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public KeyClient(Uri vaultUri, TokenCredential credential, KeyClientOptions opti
{
_vaultUri = vaultUri ?? throw new ArgumentNullException(nameof(credential));
options = options ?? new KeyClientOptions();
this.ApiVersion = options.GetVersionString();

_pipeline = HttpPipelineBuilder.Build(options,
bufferResponse: true,
Expand Down
58 changes: 58 additions & 0 deletions sdk/keyvault/Azure.Security.KeyVault.Keys/src/KeyClientOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// license information.

using Azure.Core.Pipeline;
using System;

namespace Azure.Security.KeyVault.Keys
{
Expand All @@ -11,5 +12,62 @@ namespace Azure.Security.KeyVault.Keys
/// </summary>
public class KeyClientOptions : ClientOptions
{
/// <summary>
/// The latest service version supported by this client library.
/// For more information, see
/// <see href="https://docs.microsoft.com/en-us/rest/api/keyvault/key-vault-versions"/>
/// </summary>
internal const ServiceVersion LatestVersion = ServiceVersion.V7_0;

/// <summary>
/// The versions of Azure Key Vault supported by this client
/// library.
/// </summary>
public enum ServiceVersion
{
#pragma warning disable CA1707 // Identifiers should not contain underscores
/// <summary>
/// The Key Vault API version 7.0.
/// </summary>
V7_0 = 0
#pragma warning restore CA1707 // Identifiers should not contain underscores
}

/// <summary>
/// Gets the <see cref="ServiceVersion"/> of the service API used when
/// making requests. For more information, see
/// <see href="https://docs.microsoft.com/en-us/rest/api/keyvault/key-vault-versions"/>
/// </summary>
public ServiceVersion Version { get; }

/// <summary>
/// Initializes a new instance of the <see cref="KeyClientOptions"/>
/// class.
/// </summary>
/// <param name="version">
/// The <see cref="ServiceVersion"/> of the service API used when
/// making requests.
/// </param>
public KeyClientOptions(ServiceVersion version = ServiceVersion.V7_0)
{
this.Version = version;
}

internal string GetVersionString()
{
var version = string.Empty;

switch (this.Version)
{
case ServiceVersion.V7_0:
version = "7.0";
break;

default:
throw new ArgumentException(this.Version.ToString());
}

return version;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ namespace Azure.Security.KeyVault.Keys
{
public partial class KeyClient
{
private const string ApiVersion = "7.0";
private const string KeysPath = "/keys/";
private const string DeletedKeysPath = "/deletedkeys/";
private readonly string ApiVersion;

private async Task<Response<TResult>> SendRequestAsync<TContent, TResult>(RequestMethod method, TContent content, Func<TResult> resultFactory, CancellationToken cancellationToken, params string[] path)
where TContent : Model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Azure.Security.KeyVault.Secrets
public class SecretClient
{
private readonly Uri _vaultUri;
private const string ApiVersion = "7.0";
private readonly string ApiVersion;
private readonly HttpPipeline _pipeline;

private const string SecretsPath = "/secrets/";
Expand Down Expand Up @@ -56,6 +56,7 @@ public SecretClient(Uri vaultUri, TokenCredential credential, SecretClientOption
{
_vaultUri = vaultUri ?? throw new ArgumentNullException(nameof(credential));
options = options ?? new SecretClientOptions();
this.ApiVersion = options.GetVersionString();

_pipeline = HttpPipelineBuilder.Build(options,
bufferResponse: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// license information.

using Azure.Core.Pipeline;
using System;

namespace Azure.Security.KeyVault.Secrets
{
Expand All @@ -11,5 +12,62 @@ namespace Azure.Security.KeyVault.Secrets
/// </summary>
public class SecretClientOptions : ClientOptions
{
/// <summary>
/// The latest service version supported by this client library.
/// For more information, see
/// <see href="https://docs.microsoft.com/en-us/rest/api/keyvault/key-vault-versions"/>
/// </summary>
internal const ServiceVersion LatestVersion = ServiceVersion.V7_0;

/// <summary>
/// The versions of Azure Key Vault supported by this client
/// library.
/// </summary>
public enum ServiceVersion
{
#pragma warning disable CA1707 // Identifiers should not contain underscores
/// <summary>
/// The Key Vault API version 7.0.
/// </summary>
V7_0 = 0
#pragma warning restore CA1707 // Identifiers should not contain underscores
}

/// <summary>
/// Gets the <see cref="ServiceVersion"/> of the service API used when
/// making requests. For more information, see
/// <see href="https://docs.microsoft.com/en-us/rest/api/keyvault/key-vault-versions"/>
/// </summary>
public ServiceVersion Version { get; }

/// <summary>
/// Initializes a new instance of the <see cref="SecretClientOptions"/>
/// class.
/// </summary>
/// <param name="version">
/// The <see cref="ServiceVersion"/> of the service API used when
/// making requests.
/// </param>
public SecretClientOptions(ServiceVersion version = ServiceVersion.V7_0)
{
this.Version = version;
}

internal string GetVersionString()
{
var version = string.Empty;

switch (this.Version)
{
case ServiceVersion.V7_0:
version = "7.0";
break;

default:
throw new ArgumentException(this.Version.ToString());
}

return version;
}
}
}

0 comments on commit 9dea72e

Please sign in to comment.