| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | | using Azure.Core; |
| | 6 | | using Azure.Core.Pipeline; |
| | 7 | | using Azure.Storage.Blobs; |
| | 8 | | using Azure.Storage.Files.DataLake.Models; |
| | 9 | |
|
| | 10 | | namespace Azure.Storage.Files.DataLake |
| | 11 | | { |
| | 12 | | /// <summary> |
| | 13 | | /// Provides the client configuration options for connecting to Azure Data Lake service. |
| | 14 | | /// </summary> |
| | 15 | | public class DataLakeClientOptions : ClientOptions |
| | 16 | | { |
| | 17 | | /// <summary> |
| | 18 | | /// The Latest service version supported by this client library. |
| | 19 | | /// </summary> |
| | 20 | | internal const ServiceVersion LatestVersion = StorageVersionExtensions.LatestVersion; |
| | 21 | |
|
| | 22 | | /// <summary> |
| | 23 | | /// The versions of Azure Data Lake Sevice supported by this client |
| | 24 | | /// library. For more, see |
| | 25 | | /// <see href="https://docs.microsoft.com/en-us/rest/api/storageservices/versioning-for-the-azure-storage-servic |
| | 26 | | /// Versioning for the Azure Storage services</see>. |
| | 27 | | /// </summary> |
| | 28 | | public enum ServiceVersion |
| | 29 | | { |
| | 30 | | #pragma warning disable CA1707 // Identifiers should not contain underscores |
| | 31 | | /// <summary> |
| | 32 | | /// The 2019-02-02 service version described at |
| | 33 | | /// <see href="https://docs.microsoft.com/en-us/rest/api/storageservices/version-2019-02-02"> |
| | 34 | | /// Version 2019-02-02</see> |
| | 35 | | /// </summary> |
| | 36 | | V2019_02_02 = 1, |
| | 37 | |
|
| | 38 | | /// <summary> |
| | 39 | | /// The 2019-07-07 service version described at |
| | 40 | | /// <see href="https://docs.microsoft.com/en-us/rest/api/storageservices/version-2019-07-07"> |
| | 41 | | /// Version 2019-07-07</see> |
| | 42 | | /// </summary> |
| | 43 | | V2019_07_07 = 2, |
| | 44 | |
|
| | 45 | | /// <summary> |
| | 46 | | /// The 2019-12-12 service version. |
| | 47 | | /// </summary> |
| | 48 | | V2019_12_12 = 3 |
| | 49 | | #pragma warning restore CA1707 // Identifiers should not contain underscores |
| | 50 | | } |
| | 51 | |
|
| | 52 | | /// <summary> |
| | 53 | | /// Gets the <see cref="ServiceVersion"/> of the service API used when |
| | 54 | | /// making requests. For more, see |
| | 55 | | /// <see href="https://docs.microsoft.com/en-us/rest/api/storageservices/versioning-for-the-azure-storage-servic |
| | 56 | | /// </summary> |
| 3298 | 57 | | public ServiceVersion Version { get; } |
| | 58 | |
|
| | 59 | | /// <summary> |
| | 60 | | /// Initializes a new instance of the <see cref="DataLakeClientOptions"/> |
| | 61 | | /// class. |
| | 62 | | /// </summary> |
| | 63 | | /// <param name="version"> |
| | 64 | | /// The <see cref="ServiceVersion"/> of the service API used when |
| | 65 | | /// making requests. |
| | 66 | | /// </param> |
| 3298 | 67 | | public DataLakeClientOptions(ServiceVersion version = LatestVersion) |
| | 68 | | { |
| 3298 | 69 | | if (ServiceVersion.V2019_02_02 <= version |
| 3298 | 70 | | && version <= LatestVersion) |
| | 71 | | { |
| 3298 | 72 | | Version = version; |
| | 73 | | } |
| | 74 | | else |
| | 75 | | { |
| 0 | 76 | | throw Errors.VersionNotSupported(nameof(version)); |
| | 77 | | } |
| | 78 | |
|
| 3298 | 79 | | this.Initialize(); |
| 3298 | 80 | | AddHeadersAndQueryParameters(); |
| 3298 | 81 | | } |
| | 82 | |
|
| | 83 | | /// <summary> |
| | 84 | | /// Gets or sets the secondary storage <see cref="Uri"/> that can be read from for the storage account if the |
| | 85 | | /// account is enabled for RA-GRS. |
| | 86 | | /// |
| | 87 | | /// If this property is set, the secondary Uri will be used for GET or HEAD requests during retries. |
| | 88 | | /// If the status of the response from the secondary Uri is a 404, then subsequent retries for |
| | 89 | | /// the request will not use the secondary Uri again, as this indicates that the resource |
| | 90 | | /// may not have propagated there yet. Otherwise, subsequent retries will alternate back and forth |
| | 91 | | /// between primary and secondary Uri. |
| | 92 | | /// </summary> |
| 0 | 93 | | public Uri GeoRedundantSecondaryUri { get; set; } |
| | 94 | |
|
| | 95 | | /// <summary> |
| | 96 | | /// Add headers and query parameters in <see cref="DiagnosticsOptions.LoggedHeaderNames"/> and <see cref="Diagno |
| | 97 | | /// </summary> |
| | 98 | | private void AddHeadersAndQueryParameters() |
| | 99 | | { |
| | 100 | | // Data Lake headers |
| 3298 | 101 | | Diagnostics.LoggedHeaderNames.Add("x-ms-properties"); |
| 3298 | 102 | | Diagnostics.LoggedHeaderNames.Add("x-ms-client-request-id"); |
| 3298 | 103 | | Diagnostics.LoggedHeaderNames.Add("If-Modified-Since"); |
| 3298 | 104 | | Diagnostics.LoggedHeaderNames.Add("If-Unmodified-Since"); |
| 3298 | 105 | | Diagnostics.LoggedHeaderNames.Add("If-Match"); |
| 3298 | 106 | | Diagnostics.LoggedHeaderNames.Add("If-None-Match"); |
| 3298 | 107 | | Diagnostics.LoggedHeaderNames.Add("x-ms-rename-source"); |
| 3298 | 108 | | Diagnostics.LoggedHeaderNames.Add("x-ms-source-lease-id"); |
| 3298 | 109 | | Diagnostics.LoggedHeaderNames.Add("x-ms-permissions"); |
| 3298 | 110 | | Diagnostics.LoggedHeaderNames.Add("x-ms-umask"); |
| 3298 | 111 | | Diagnostics.LoggedHeaderNames.Add("x-ms-owner"); |
| 3298 | 112 | | Diagnostics.LoggedHeaderNames.Add("x-ms-group"); |
| 3298 | 113 | | Diagnostics.LoggedHeaderNames.Add("x-ms-acl"); |
| | 114 | |
|
| | 115 | | // Data Lake query parameters |
| 3298 | 116 | | Diagnostics.LoggedQueryParameters.Add("recursive"); |
| 3298 | 117 | | Diagnostics.LoggedQueryParameters.Add("resource"); |
| 3298 | 118 | | Diagnostics.LoggedQueryParameters.Add("action"); |
| 3298 | 119 | | Diagnostics.LoggedQueryParameters.Add("position"); |
| 3298 | 120 | | Diagnostics.LoggedQueryParameters.Add("retainUncommittedData"); |
| 3298 | 121 | | Diagnostics.LoggedQueryParameters.Add("close"); |
| 3298 | 122 | | Diagnostics.LoggedQueryParameters.Add("timeout"); |
| 3298 | 123 | | Diagnostics.LoggedQueryParameters.Add("directory"); |
| 3298 | 124 | | Diagnostics.LoggedQueryParameters.Add("continuation"); |
| 3298 | 125 | | Diagnostics.LoggedQueryParameters.Add("upn"); |
| 3298 | 126 | | Diagnostics.LoggedQueryParameters.Add("maxResults"); |
| 3298 | 127 | | Diagnostics.LoggedQueryParameters.Add("mode"); |
| | 128 | |
|
| | 129 | | // Blob headers |
| 3298 | 130 | | Diagnostics.LoggedHeaderNames.Add("Access-Control-Allow-Origin"); |
| 3298 | 131 | | Diagnostics.LoggedHeaderNames.Add("x-ms-date"); |
| 3298 | 132 | | Diagnostics.LoggedHeaderNames.Add("x-ms-error-code"); |
| 3298 | 133 | | Diagnostics.LoggedHeaderNames.Add("x-ms-request-id"); |
| 3298 | 134 | | Diagnostics.LoggedHeaderNames.Add("x-ms-version"); |
| 3298 | 135 | | Diagnostics.LoggedHeaderNames.Add("Accept-Ranges"); |
| 3298 | 136 | | Diagnostics.LoggedHeaderNames.Add("Content-Disposition"); |
| 3298 | 137 | | Diagnostics.LoggedHeaderNames.Add("Content-Encoding"); |
| 3298 | 138 | | Diagnostics.LoggedHeaderNames.Add("Content-Language"); |
| 3298 | 139 | | Diagnostics.LoggedHeaderNames.Add("Content-MD5"); |
| 3298 | 140 | | Diagnostics.LoggedHeaderNames.Add("Content-Range"); |
| 3298 | 141 | | Diagnostics.LoggedHeaderNames.Add("Vary"); |
| 3298 | 142 | | Diagnostics.LoggedHeaderNames.Add("x-ms-content-crc64"); |
| 3298 | 143 | | Diagnostics.LoggedHeaderNames.Add("x-ms-copy-action"); |
| 3298 | 144 | | Diagnostics.LoggedHeaderNames.Add("x-ms-copy-completion-time"); |
| 3298 | 145 | | Diagnostics.LoggedHeaderNames.Add("x-ms-copy-id"); |
| 3298 | 146 | | Diagnostics.LoggedHeaderNames.Add("x-ms-copy-progress"); |
| 3298 | 147 | | Diagnostics.LoggedHeaderNames.Add("x-ms-copy-status"); |
| 3298 | 148 | | Diagnostics.LoggedHeaderNames.Add("x-ms-has-immutability-policy"); |
| 3298 | 149 | | Diagnostics.LoggedHeaderNames.Add("x-ms-has-legal-hold"); |
| 3298 | 150 | | Diagnostics.LoggedHeaderNames.Add("x-ms-lease-state"); |
| 3298 | 151 | | Diagnostics.LoggedHeaderNames.Add("x-ms-lease-status"); |
| 3298 | 152 | | Diagnostics.LoggedHeaderNames.Add("x-ms-range"); |
| 3298 | 153 | | Diagnostics.LoggedHeaderNames.Add("x-ms-request-server-encrypted"); |
| 3298 | 154 | | Diagnostics.LoggedHeaderNames.Add("x-ms-server-encrypted"); |
| 3298 | 155 | | Diagnostics.LoggedHeaderNames.Add("x-ms-snapshot"); |
| 3298 | 156 | | Diagnostics.LoggedHeaderNames.Add("x-ms-source-range"); |
| 3298 | 157 | | Diagnostics.LoggedHeaderNames.Add("x-ms-access-tier"); |
| 3298 | 158 | | Diagnostics.LoggedHeaderNames.Add("x-ms-access-tier-change-time"); |
| 3298 | 159 | | Diagnostics.LoggedHeaderNames.Add("x-ms-access-tier-inferred"); |
| 3298 | 160 | | Diagnostics.LoggedHeaderNames.Add("x-ms-account-kind"); |
| 3298 | 161 | | Diagnostics.LoggedHeaderNames.Add("x-ms-archive-status"); |
| 3298 | 162 | | Diagnostics.LoggedHeaderNames.Add("x-ms-blob-append-offset"); |
| 3298 | 163 | | Diagnostics.LoggedHeaderNames.Add("x-ms-blob-cache-control"); |
| 3298 | 164 | | Diagnostics.LoggedHeaderNames.Add("x-ms-blob-committed-block-count"); |
| 3298 | 165 | | Diagnostics.LoggedHeaderNames.Add("x-ms-blob-condition-appendpos"); |
| 3298 | 166 | | Diagnostics.LoggedHeaderNames.Add("x-ms-blob-condition-maxsize"); |
| 3298 | 167 | | Diagnostics.LoggedHeaderNames.Add("x-ms-blob-content-disposition"); |
| 3298 | 168 | | Diagnostics.LoggedHeaderNames.Add("x-ms-blob-content-encoding"); |
| 3298 | 169 | | Diagnostics.LoggedHeaderNames.Add("x-ms-blob-content-language"); |
| 3298 | 170 | | Diagnostics.LoggedHeaderNames.Add("x-ms-blob-content-length"); |
| 3298 | 171 | | Diagnostics.LoggedHeaderNames.Add("x-ms-blob-content-md5"); |
| 3298 | 172 | | Diagnostics.LoggedHeaderNames.Add("x-ms-blob-content-type"); |
| 3298 | 173 | | Diagnostics.LoggedHeaderNames.Add("x-ms-blob-public-access"); |
| 3298 | 174 | | Diagnostics.LoggedHeaderNames.Add("x-ms-blob-sequence-number"); |
| 3298 | 175 | | Diagnostics.LoggedHeaderNames.Add("x-ms-blob-type"); |
| 3298 | 176 | | Diagnostics.LoggedHeaderNames.Add("x-ms-copy-destination-snapshot"); |
| 3298 | 177 | | Diagnostics.LoggedHeaderNames.Add("x-ms-creation-time"); |
| 3298 | 178 | | Diagnostics.LoggedHeaderNames.Add("x-ms-default-encryption-scope"); |
| 3298 | 179 | | Diagnostics.LoggedHeaderNames.Add("x-ms-delete-snapshots"); |
| 3298 | 180 | | Diagnostics.LoggedHeaderNames.Add("x-ms-delete-type-permanent"); |
| 3298 | 181 | | Diagnostics.LoggedHeaderNames.Add("x-ms-deny-encryption-scope-override"); |
| 3298 | 182 | | Diagnostics.LoggedHeaderNames.Add("x-ms-encryption-algorithm"); |
| 3298 | 183 | | Diagnostics.LoggedHeaderNames.Add("x-ms-if-sequence-number-eq"); |
| 3298 | 184 | | Diagnostics.LoggedHeaderNames.Add("x-ms-if-sequence-number-le"); |
| 3298 | 185 | | Diagnostics.LoggedHeaderNames.Add("x-ms-if-sequence-number-lt"); |
| 3298 | 186 | | Diagnostics.LoggedHeaderNames.Add("x-ms-incremental-copy"); |
| 3298 | 187 | | Diagnostics.LoggedHeaderNames.Add("x-ms-lease-action"); |
| 3298 | 188 | | Diagnostics.LoggedHeaderNames.Add("x-ms-lease-break-period"); |
| 3298 | 189 | | Diagnostics.LoggedHeaderNames.Add("x-ms-lease-duration"); |
| 3298 | 190 | | Diagnostics.LoggedHeaderNames.Add("x-ms-lease-id"); |
| 3298 | 191 | | Diagnostics.LoggedHeaderNames.Add("x-ms-lease-time"); |
| 3298 | 192 | | Diagnostics.LoggedHeaderNames.Add("x-ms-page-write"); |
| 3298 | 193 | | Diagnostics.LoggedHeaderNames.Add("x-ms-proposed-lease-id"); |
| 3298 | 194 | | Diagnostics.LoggedHeaderNames.Add("x-ms-range-get-content-md5"); |
| 3298 | 195 | | Diagnostics.LoggedHeaderNames.Add("x-ms-rehydrate-priority"); |
| 3298 | 196 | | Diagnostics.LoggedHeaderNames.Add("x-ms-sequence-number-action"); |
| 3298 | 197 | | Diagnostics.LoggedHeaderNames.Add("x-ms-sku-name"); |
| 3298 | 198 | | Diagnostics.LoggedHeaderNames.Add("x-ms-source-content-md5"); |
| 3298 | 199 | | Diagnostics.LoggedHeaderNames.Add("x-ms-source-if-match"); |
| 3298 | 200 | | Diagnostics.LoggedHeaderNames.Add("x-ms-source-if-modified-since"); |
| 3298 | 201 | | Diagnostics.LoggedHeaderNames.Add("x-ms-source-if-none-match"); |
| 3298 | 202 | | Diagnostics.LoggedHeaderNames.Add("x-ms-source-if-unmodified-since"); |
| 3298 | 203 | | Diagnostics.LoggedHeaderNames.Add("x-ms-tag-count"); |
| 3298 | 204 | | Diagnostics.LoggedHeaderNames.Add("x-ms-encryption-key-sha256"); |
| | 205 | |
|
| | 206 | | // Blob query parameters |
| 3298 | 207 | | Diagnostics.LoggedQueryParameters.Add("comp"); |
| 3298 | 208 | | Diagnostics.LoggedQueryParameters.Add("maxresults"); |
| 3298 | 209 | | Diagnostics.LoggedQueryParameters.Add("rscc"); |
| 3298 | 210 | | Diagnostics.LoggedQueryParameters.Add("rscd"); |
| 3298 | 211 | | Diagnostics.LoggedQueryParameters.Add("rsce"); |
| 3298 | 212 | | Diagnostics.LoggedQueryParameters.Add("rscl"); |
| 3298 | 213 | | Diagnostics.LoggedQueryParameters.Add("rsct"); |
| 3298 | 214 | | Diagnostics.LoggedQueryParameters.Add("se"); |
| 3298 | 215 | | Diagnostics.LoggedQueryParameters.Add("si"); |
| 3298 | 216 | | Diagnostics.LoggedQueryParameters.Add("sip"); |
| 3298 | 217 | | Diagnostics.LoggedQueryParameters.Add("sp"); |
| 3298 | 218 | | Diagnostics.LoggedQueryParameters.Add("spr"); |
| 3298 | 219 | | Diagnostics.LoggedQueryParameters.Add("sr"); |
| 3298 | 220 | | Diagnostics.LoggedQueryParameters.Add("srt"); |
| 3298 | 221 | | Diagnostics.LoggedQueryParameters.Add("ss"); |
| 3298 | 222 | | Diagnostics.LoggedQueryParameters.Add("st"); |
| 3298 | 223 | | Diagnostics.LoggedQueryParameters.Add("sv"); |
| 3298 | 224 | | Diagnostics.LoggedQueryParameters.Add("include"); |
| 3298 | 225 | | Diagnostics.LoggedQueryParameters.Add("marker"); |
| 3298 | 226 | | Diagnostics.LoggedQueryParameters.Add("prefix"); |
| 3298 | 227 | | Diagnostics.LoggedQueryParameters.Add("copyid"); |
| 3298 | 228 | | Diagnostics.LoggedQueryParameters.Add("restype"); |
| 3298 | 229 | | Diagnostics.LoggedQueryParameters.Add("blockid"); |
| 3298 | 230 | | Diagnostics.LoggedQueryParameters.Add("blocklisttype"); |
| 3298 | 231 | | Diagnostics.LoggedQueryParameters.Add("delimiter"); |
| 3298 | 232 | | Diagnostics.LoggedQueryParameters.Add("prevsnapshot"); |
| 3298 | 233 | | Diagnostics.LoggedQueryParameters.Add("ske"); |
| 3298 | 234 | | Diagnostics.LoggedQueryParameters.Add("skoid"); |
| 3298 | 235 | | Diagnostics.LoggedQueryParameters.Add("sks"); |
| 3298 | 236 | | Diagnostics.LoggedQueryParameters.Add("skt"); |
| 3298 | 237 | | Diagnostics.LoggedQueryParameters.Add("sktid"); |
| 3298 | 238 | | Diagnostics.LoggedQueryParameters.Add("skv"); |
| 3298 | 239 | | Diagnostics.LoggedQueryParameters.Add("snapshot"); |
| 3298 | 240 | | } |
| | 241 | |
|
| | 242 | | /// <summary> |
| | 243 | | /// Create an HttpPipeline from DataLakeClientOptions. |
| | 244 | | /// </summary> |
| | 245 | | /// <param name="authentication">Optional authentication policy.</param> |
| | 246 | | /// <returns>An HttpPipeline to use for Storage requests.</returns> |
| | 247 | | internal HttpPipeline Build(HttpPipelinePolicy authentication = null) |
| | 248 | | { |
| 3094 | 249 | | return this.Build(authentication, GeoRedundantSecondaryUri); |
| | 250 | | } |
| | 251 | |
|
| | 252 | | /// <summary> |
| | 253 | | /// Create an HttpPipeline from DataLakeClientOptions. |
| | 254 | | /// </summary> |
| | 255 | | /// <param name="credentials">Optional authentication credentials.</param> |
| | 256 | | /// <returns>An HttpPipeline to use for Storage requests.</returns> |
| | 257 | | internal HttpPipeline Build(object credentials) |
| | 258 | | { |
| 0 | 259 | | return this.Build(credentials, GeoRedundantSecondaryUri); |
| | 260 | | } |
| | 261 | | } |
| | 262 | | } |