From 90bd8ee415b1665926c579ec0dd7c64de98ecfa4 Mon Sep 17 00:00:00 2001 From: Anne Thompson Date: Fri, 12 Jul 2019 12:16:13 -0700 Subject: [PATCH 1/2] Applying ClientOptions analyzers to client libraries. --- eng/Packages.Data.props | 2 +- .../src/ConfigurationClientOptions.cs | 33 +++++++++++ .../src/CertificateClientOptions.cs | 40 ++++++++++++++ .../src/KeyClient.cs | 1 + .../src/KeyClientOptions.cs | 55 +++++++++++++++++++ .../src/KeyClient_private.cs | 2 +- .../src/SecretClient.cs | 3 +- .../src/SecretClientOptions.cs | 55 +++++++++++++++++++ 8 files changed, 188 insertions(+), 3 deletions(-) diff --git a/eng/Packages.Data.props b/eng/Packages.Data.props index bbe48c3f04a9e..7944fcb75194f 100755 --- a/eng/Packages.Data.props +++ b/eng/Packages.Data.props @@ -9,7 +9,7 @@ - + diff --git a/sdk/appconfiguration/Azure.ApplicationModel.Configuration/src/ConfigurationClientOptions.cs b/sdk/appconfiguration/Azure.ApplicationModel.Configuration/src/ConfigurationClientOptions.cs index 2a1f0be0ff38c..4df754be4f2b6 100644 --- a/sdk/appconfiguration/Azure.ApplicationModel.Configuration/src/ConfigurationClientOptions.cs +++ b/sdk/appconfiguration/Azure.ApplicationModel.Configuration/src/ConfigurationClientOptions.cs @@ -7,5 +7,38 @@ namespace Azure.ApplicationModel.Configuration { public class ConfigurationClientOptions: ClientOptions { + /// + /// The latest service version supported by this client library. + /// + internal const ServiceVersion LatestVersion = ServiceVersion.Default; + + /// + /// The versions of App Config Service supported by this client library. + /// + public enum ServiceVersion + { +#pragma warning disable CA1707 // Identifiers should not contain underscores + Default = 0 +#pragma warning restore CA1707 // Identifiers should not contain underscores + } + + /// + /// Gets the of the service API used when + /// making requests. + /// + public ServiceVersion Version { get; } + + /// + /// Initializes a new instance of the + /// class. + /// + /// + /// The of the service API used when + /// making requests. + /// + public ConfigurationClientOptions(ServiceVersion version = ServiceVersion.Default) + { + this.Version = version; + } } } diff --git a/sdk/keyvault/Azure.Security.KeyVault.Certificates/src/CertificateClientOptions.cs b/sdk/keyvault/Azure.Security.KeyVault.Certificates/src/CertificateClientOptions.cs index 023be145e78d2..bf48ac8b1185e 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Certificates/src/CertificateClientOptions.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Certificates/src/CertificateClientOptions.cs @@ -8,5 +8,45 @@ namespace Azure.Security.KeyVault.Certificates { public class CertificateClientOptions : ClientOptions { + /// + /// The latest service version supported by this client library. + /// For more information, see + /// + /// + internal const ServiceVersion LatestVersion = ServiceVersion.V0_7_0; + + /// + /// The versions of Azure Key Vault supported by this client + /// library. + /// + public enum ServiceVersion + { +#pragma warning disable CA1707 // Identifiers should not contain underscores + /// + /// The Key Vault API version 7.0. + /// + V0_7_0 = 0 +#pragma warning restore CA1707 // Identifiers should not contain underscores + } + + /// + /// Gets the of the service API used when + /// making requests. For more information, see + /// + /// + public ServiceVersion Version { get; } + + /// + /// Initializes a new instance of the + /// class. + /// + /// + /// The of the service API used when + /// making requests. + /// + public CertificateClientOptions(ServiceVersion version = ServiceVersion.V0_7_0) + { + this.Version = version; + } } } diff --git a/sdk/keyvault/Azure.Security.KeyVault.Keys/src/KeyClient.cs b/sdk/keyvault/Azure.Security.KeyVault.Keys/src/KeyClient.cs index 6051fc79a0c5b..29b0e7aa30662 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Keys/src/KeyClient.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Keys/src/KeyClient.cs @@ -51,6 +51,7 @@ public KeyClient(Uri vaultUri, TokenCredential credential, KeyClientOptions opti { _vaultUri = vaultUri ?? throw new ArgumentNullException(nameof(credential)); options = options ?? new KeyClientOptions(); + options.SetVersionString(out this.ApiVersion); _pipeline = HttpPipelineBuilder.Build(options, bufferResponse: true, diff --git a/sdk/keyvault/Azure.Security.KeyVault.Keys/src/KeyClientOptions.cs b/sdk/keyvault/Azure.Security.KeyVault.Keys/src/KeyClientOptions.cs index 2fa1af1e083a2..6c76f1140df30 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Keys/src/KeyClientOptions.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Keys/src/KeyClientOptions.cs @@ -11,5 +11,60 @@ namespace Azure.Security.KeyVault.Keys /// public class KeyClientOptions : ClientOptions { + /// + /// The latest service version supported by this client library. + /// For more information, see + /// + /// + internal const ServiceVersion LatestVersion = ServiceVersion.V0_7_0; + + /// + /// The versions of Azure Key Vault supported by this client + /// library. + /// + public enum ServiceVersion + { +#pragma warning disable CA1707 // Identifiers should not contain underscores + /// + /// The Key Vault API version 7.0. + /// + V0_7_0 = 0 +#pragma warning restore CA1707 // Identifiers should not contain underscores + } + + /// + /// Gets the of the service API used when + /// making requests. For more information, see + /// + /// + public ServiceVersion Version { get; } + + /// + /// Initializes a new instance of the + /// class. + /// + /// + /// The of the service API used when + /// making requests. + /// + public KeyClientOptions(ServiceVersion version = ServiceVersion.V0_7_0) + { + this.Version = version; + } + + internal void SetVersionString(out string version) + { + version = string.Empty; + + switch (this.Version) + { + case ServiceVersion.V0_7_0: + version = "7.0"; + break; + + default: + break; + } + } } } diff --git a/sdk/keyvault/Azure.Security.KeyVault.Keys/src/KeyClient_private.cs b/sdk/keyvault/Azure.Security.KeyVault.Keys/src/KeyClient_private.cs index b9f4caa8ae0c4..5ee9684fc4958 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Keys/src/KeyClient_private.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Keys/src/KeyClient_private.cs @@ -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 = "7.0"; private async Task> SendRequestAsync(RequestMethod method, TContent content, Func resultFactory, CancellationToken cancellationToken, params string[] path) where TContent : Model diff --git a/sdk/keyvault/Azure.Security.KeyVault.Secrets/src/SecretClient.cs b/sdk/keyvault/Azure.Security.KeyVault.Secrets/src/SecretClient.cs index 32f4c8f321473..f24d7f0bbfe6d 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Secrets/src/SecretClient.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Secrets/src/SecretClient.cs @@ -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 = "7.0"; private readonly HttpPipeline _pipeline; private const string SecretsPath = "/secrets/"; @@ -56,6 +56,7 @@ public SecretClient(Uri vaultUri, TokenCredential credential, SecretClientOption { _vaultUri = vaultUri ?? throw new ArgumentNullException(nameof(credential)); options = options ?? new SecretClientOptions(); + options.SetVersionString(out this.ApiVersion); _pipeline = HttpPipelineBuilder.Build(options, bufferResponse: true, diff --git a/sdk/keyvault/Azure.Security.KeyVault.Secrets/src/SecretClientOptions.cs b/sdk/keyvault/Azure.Security.KeyVault.Secrets/src/SecretClientOptions.cs index 7248ede837b93..dfcbe3175226b 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Secrets/src/SecretClientOptions.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Secrets/src/SecretClientOptions.cs @@ -11,5 +11,60 @@ namespace Azure.Security.KeyVault.Secrets /// public class SecretClientOptions : ClientOptions { + /// + /// The latest service version supported by this client library. + /// For more information, see + /// + /// + internal const ServiceVersion LatestVersion = ServiceVersion.V0_7_0; + + /// + /// The versions of Azure Key Vault supported by this client + /// library. + /// + public enum ServiceVersion + { +#pragma warning disable CA1707 // Identifiers should not contain underscores + /// + /// The Key Vault API version 7.0. + /// + V0_7_0 = 0 +#pragma warning restore CA1707 // Identifiers should not contain underscores + } + + /// + /// Gets the of the service API used when + /// making requests. For more information, see + /// + /// + public ServiceVersion Version { get; } + + /// + /// Initializes a new instance of the + /// class. + /// + /// + /// The of the service API used when + /// making requests. + /// + public SecretClientOptions(ServiceVersion version = ServiceVersion.V0_7_0) + { + this.Version = version; + } + + internal void SetVersionString(out string version) + { + version = string.Empty; + + switch (this.Version) + { + case ServiceVersion.V0_7_0: + version = "7.0"; + break; + + default: + break; + } + } } } From 7b56addc55a11af48ca7d335814c074d5c574776 Mon Sep 17 00:00:00 2001 From: Anne Thompson Date: Fri, 12 Jul 2019 12:51:46 -0700 Subject: [PATCH 2/2] Addressing PR comments. --- .../src/ConfigurationClientOptions.cs | 2 -- .../src/CertificateClientOptions.cs | 6 +++--- .../src/KeyClient.cs | 2 +- .../src/KeyClientOptions.cs | 17 ++++++++++------- .../src/KeyClient_private.cs | 2 +- .../src/SecretClient.cs | 4 ++-- .../src/SecretClientOptions.cs | 17 ++++++++++------- 7 files changed, 27 insertions(+), 23 deletions(-) diff --git a/sdk/appconfiguration/Azure.ApplicationModel.Configuration/src/ConfigurationClientOptions.cs b/sdk/appconfiguration/Azure.ApplicationModel.Configuration/src/ConfigurationClientOptions.cs index 4df754be4f2b6..e2efd16d822fc 100644 --- a/sdk/appconfiguration/Azure.ApplicationModel.Configuration/src/ConfigurationClientOptions.cs +++ b/sdk/appconfiguration/Azure.ApplicationModel.Configuration/src/ConfigurationClientOptions.cs @@ -17,9 +17,7 @@ public class ConfigurationClientOptions: ClientOptions /// public enum ServiceVersion { -#pragma warning disable CA1707 // Identifiers should not contain underscores Default = 0 -#pragma warning restore CA1707 // Identifiers should not contain underscores } /// diff --git a/sdk/keyvault/Azure.Security.KeyVault.Certificates/src/CertificateClientOptions.cs b/sdk/keyvault/Azure.Security.KeyVault.Certificates/src/CertificateClientOptions.cs index bf48ac8b1185e..28a65aef1fdeb 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Certificates/src/CertificateClientOptions.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Certificates/src/CertificateClientOptions.cs @@ -13,7 +13,7 @@ public class CertificateClientOptions : ClientOptions /// For more information, see /// /// - internal const ServiceVersion LatestVersion = ServiceVersion.V0_7_0; + internal const ServiceVersion LatestVersion = ServiceVersion.V7_0; /// /// The versions of Azure Key Vault supported by this client @@ -25,7 +25,7 @@ public enum ServiceVersion /// /// The Key Vault API version 7.0. /// - V0_7_0 = 0 + V7_0 = 0 #pragma warning restore CA1707 // Identifiers should not contain underscores } @@ -44,7 +44,7 @@ public enum ServiceVersion /// The of the service API used when /// making requests. /// - public CertificateClientOptions(ServiceVersion version = ServiceVersion.V0_7_0) + public CertificateClientOptions(ServiceVersion version = ServiceVersion.V7_0) { this.Version = version; } diff --git a/sdk/keyvault/Azure.Security.KeyVault.Keys/src/KeyClient.cs b/sdk/keyvault/Azure.Security.KeyVault.Keys/src/KeyClient.cs index 29b0e7aa30662..9a28df0959317 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Keys/src/KeyClient.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Keys/src/KeyClient.cs @@ -51,7 +51,7 @@ public KeyClient(Uri vaultUri, TokenCredential credential, KeyClientOptions opti { _vaultUri = vaultUri ?? throw new ArgumentNullException(nameof(credential)); options = options ?? new KeyClientOptions(); - options.SetVersionString(out this.ApiVersion); + this.ApiVersion = options.GetVersionString(); _pipeline = HttpPipelineBuilder.Build(options, bufferResponse: true, diff --git a/sdk/keyvault/Azure.Security.KeyVault.Keys/src/KeyClientOptions.cs b/sdk/keyvault/Azure.Security.KeyVault.Keys/src/KeyClientOptions.cs index 6c76f1140df30..60b1952f3c549 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Keys/src/KeyClientOptions.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Keys/src/KeyClientOptions.cs @@ -3,6 +3,7 @@ // license information. using Azure.Core.Pipeline; +using System; namespace Azure.Security.KeyVault.Keys { @@ -16,7 +17,7 @@ public class KeyClientOptions : ClientOptions /// For more information, see /// /// - internal const ServiceVersion LatestVersion = ServiceVersion.V0_7_0; + internal const ServiceVersion LatestVersion = ServiceVersion.V7_0; /// /// The versions of Azure Key Vault supported by this client @@ -28,7 +29,7 @@ public enum ServiceVersion /// /// The Key Vault API version 7.0. /// - V0_7_0 = 0 + V7_0 = 0 #pragma warning restore CA1707 // Identifiers should not contain underscores } @@ -47,24 +48,26 @@ public enum ServiceVersion /// The of the service API used when /// making requests. /// - public KeyClientOptions(ServiceVersion version = ServiceVersion.V0_7_0) + public KeyClientOptions(ServiceVersion version = ServiceVersion.V7_0) { this.Version = version; } - internal void SetVersionString(out string version) + internal string GetVersionString() { - version = string.Empty; + var version = string.Empty; switch (this.Version) { - case ServiceVersion.V0_7_0: + case ServiceVersion.V7_0: version = "7.0"; break; default: - break; + throw new ArgumentException(this.Version.ToString()); } + + return version; } } } diff --git a/sdk/keyvault/Azure.Security.KeyVault.Keys/src/KeyClient_private.cs b/sdk/keyvault/Azure.Security.KeyVault.Keys/src/KeyClient_private.cs index 5ee9684fc4958..3c5241ee6d35e 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Keys/src/KeyClient_private.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Keys/src/KeyClient_private.cs @@ -11,7 +11,7 @@ public partial class KeyClient { private const string KeysPath = "/keys/"; private const string DeletedKeysPath = "/deletedkeys/"; - private readonly string ApiVersion = "7.0"; + private readonly string ApiVersion; private async Task> SendRequestAsync(RequestMethod method, TContent content, Func resultFactory, CancellationToken cancellationToken, params string[] path) where TContent : Model diff --git a/sdk/keyvault/Azure.Security.KeyVault.Secrets/src/SecretClient.cs b/sdk/keyvault/Azure.Security.KeyVault.Secrets/src/SecretClient.cs index f24d7f0bbfe6d..a02c6c73b1fda 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Secrets/src/SecretClient.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Secrets/src/SecretClient.cs @@ -21,7 +21,7 @@ namespace Azure.Security.KeyVault.Secrets public class SecretClient { private readonly Uri _vaultUri; - private readonly string ApiVersion = "7.0"; + private readonly string ApiVersion; private readonly HttpPipeline _pipeline; private const string SecretsPath = "/secrets/"; @@ -56,7 +56,7 @@ public SecretClient(Uri vaultUri, TokenCredential credential, SecretClientOption { _vaultUri = vaultUri ?? throw new ArgumentNullException(nameof(credential)); options = options ?? new SecretClientOptions(); - options.SetVersionString(out this.ApiVersion); + this.ApiVersion = options.GetVersionString(); _pipeline = HttpPipelineBuilder.Build(options, bufferResponse: true, diff --git a/sdk/keyvault/Azure.Security.KeyVault.Secrets/src/SecretClientOptions.cs b/sdk/keyvault/Azure.Security.KeyVault.Secrets/src/SecretClientOptions.cs index dfcbe3175226b..20c3c567a4d05 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Secrets/src/SecretClientOptions.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Secrets/src/SecretClientOptions.cs @@ -3,6 +3,7 @@ // license information. using Azure.Core.Pipeline; +using System; namespace Azure.Security.KeyVault.Secrets { @@ -16,7 +17,7 @@ public class SecretClientOptions : ClientOptions /// For more information, see /// /// - internal const ServiceVersion LatestVersion = ServiceVersion.V0_7_0; + internal const ServiceVersion LatestVersion = ServiceVersion.V7_0; /// /// The versions of Azure Key Vault supported by this client @@ -28,7 +29,7 @@ public enum ServiceVersion /// /// The Key Vault API version 7.0. /// - V0_7_0 = 0 + V7_0 = 0 #pragma warning restore CA1707 // Identifiers should not contain underscores } @@ -47,24 +48,26 @@ public enum ServiceVersion /// The of the service API used when /// making requests. /// - public SecretClientOptions(ServiceVersion version = ServiceVersion.V0_7_0) + public SecretClientOptions(ServiceVersion version = ServiceVersion.V7_0) { this.Version = version; } - internal void SetVersionString(out string version) + internal string GetVersionString() { - version = string.Empty; + var version = string.Empty; switch (this.Version) { - case ServiceVersion.V0_7_0: + case ServiceVersion.V7_0: version = "7.0"; break; default: - break; + throw new ArgumentException(this.Version.ToString()); } + + return version; } } }