| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | | using Azure.AI.FormRecognizer.Training; |
| | 6 | | using Azure.Core; |
| | 7 | |
|
| | 8 | | namespace Azure.AI.FormRecognizer |
| | 9 | | { |
| | 10 | | /// <summary> |
| | 11 | | /// The set of options that can be specified when creating a <see cref="FormRecognizerClient" /> |
| | 12 | | /// or a <see cref="FormTrainingClient"/> to configure its behavior. |
| | 13 | | /// </summary> |
| | 14 | | public class FormRecognizerClientOptions : ClientOptions |
| | 15 | | { |
| | 16 | | internal const ServiceVersion LatestVersion = ServiceVersion.V2_0; |
| | 17 | |
|
| | 18 | | /// <summary> |
| | 19 | | /// Initializes a new instance of the <see cref="FormRecognizerClientOptions"/> class. |
| | 20 | | /// </summary> |
| | 21 | | /// <param name="version">The version of the service to send requests to.</param> |
| 588 | 22 | | public FormRecognizerClientOptions(ServiceVersion version = LatestVersion) |
| | 23 | | { |
| 588 | 24 | | Version = version; |
| 588 | 25 | | AddLoggedHeadersAndQueryParameters(); |
| 588 | 26 | | } |
| | 27 | |
|
| | 28 | | /// <summary> |
| | 29 | | /// The service version. |
| | 30 | | /// </summary> |
| | 31 | | public enum ServiceVersion |
| | 32 | | { |
| | 33 | | /// <summary> |
| | 34 | | /// The V2.0 of the service. |
| | 35 | | /// </summary> |
| | 36 | | #pragma warning disable CA1707 // Identifiers should not contain underscores |
| | 37 | | V2_0 = 1 |
| | 38 | | #pragma warning restore CA1707 // Identifiers should not contain underscores |
| | 39 | | } |
| | 40 | |
|
| | 41 | | /// <summary> |
| | 42 | | /// The service version. |
| | 43 | | /// </summary> |
| 0 | 44 | | public ServiceVersion Version { get; } |
| | 45 | |
|
| | 46 | | internal static string GetVersionString(ServiceVersion version) |
| | 47 | | { |
| 0 | 48 | | return version switch |
| 0 | 49 | | { |
| 0 | 50 | | ServiceVersion.V2_0 => "v2.0", |
| 0 | 51 | | _ => throw new NotSupportedException($"The service version {version} is not supported."), |
| 0 | 52 | | }; |
| | 53 | | } |
| | 54 | |
|
| | 55 | | /// <summary> |
| | 56 | | /// Add headers and query parameters that are considered safe for logging or including in |
| | 57 | | /// error messages by default. |
| | 58 | | /// </summary> |
| | 59 | | private void AddLoggedHeadersAndQueryParameters() |
| | 60 | | { |
| 588 | 61 | | Diagnostics.LoggedHeaderNames.Add(Constants.OperationLocationHeader); |
| 588 | 62 | | Diagnostics.LoggedHeaderNames.Add("apim-request-id"); |
| 588 | 63 | | Diagnostics.LoggedHeaderNames.Add("Location"); |
| 588 | 64 | | Diagnostics.LoggedHeaderNames.Add("Strict-Transport-Security"); |
| 588 | 65 | | Diagnostics.LoggedHeaderNames.Add("X-Content-Type-Options"); |
| 588 | 66 | | Diagnostics.LoggedHeaderNames.Add("x-envoy-upstream-service-time"); |
| | 67 | |
|
| 588 | 68 | | Diagnostics.LoggedQueryParameters.Add("includeKeys"); |
| 588 | 69 | | Diagnostics.LoggedQueryParameters.Add("includeTextDetails"); |
| 588 | 70 | | Diagnostics.LoggedQueryParameters.Add("op"); |
| 588 | 71 | | } |
| | 72 | | } |
| | 73 | | } |