| | 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.Models; |
| | 8 | |
|
| | 9 | | namespace Azure.Storage.Blobs |
| | 10 | | { |
| | 11 | | /// <summary> |
| | 12 | | /// Provides the client configuration options for connecting to Azure Blob |
| | 13 | | /// Storage. |
| | 14 | | /// </summary> |
| | 15 | | public class BlobClientOptions : 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 Blob Storage 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 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 | | /// Versioning for Azure Storage Services</see>. |
| | 57 | | /// </summary> |
| 15218 | 58 | | public ServiceVersion Version { get; } |
| | 59 | |
|
| | 60 | | /// <summary> |
| | 61 | | /// Gets the <see cref="CustomerProvidedKey"/> to be used when making requests. |
| | 62 | | /// </summary> |
| 4600 | 63 | | public CustomerProvidedKey? CustomerProvidedKey { get; set; } |
| | 64 | |
|
| | 65 | | /// <summary> |
| | 66 | | /// Gets the <see cref="EncryptionScope"/> to be used when making requests. |
| | 67 | | /// </summary> |
| 0 | 68 | | public string EncryptionScope { get; set; } |
| | 69 | |
|
| | 70 | | /// <summary> |
| | 71 | | /// Gets or sets the secondary storage <see cref="Uri"/> that can be read from for the storage account if the |
| | 72 | | /// account is enabled for RA-GRS. |
| | 73 | | /// |
| | 74 | | /// If this property is set, the secondary Uri will be used for GET or HEAD requests during retries. |
| | 75 | | /// If the status of the response from the secondary Uri is a 404, then subsequent retries for |
| | 76 | | /// the request will not use the secondary Uri again, as this indicates that the resource |
| | 77 | | /// may not have propagated there yet. Otherwise, subsequent retries will alternate back and forth |
| | 78 | | /// between primary and secondary Uri. |
| | 79 | | /// </summary> |
| 4628 | 80 | | public Uri GeoRedundantSecondaryUri { get; set; } |
| | 81 | |
|
| | 82 | | #region Advanced Options |
| | 83 | | internal ClientSideEncryptionOptions _clientSideEncryptionOptions; |
| | 84 | | #endregion |
| | 85 | |
|
| | 86 | | /// <summary> |
| | 87 | | /// Initializes a new instance of the <see cref="BlobClientOptions"/> |
| | 88 | | /// class. |
| | 89 | | /// </summary> |
| | 90 | | /// <param name="version"> |
| | 91 | | /// The <see cref="ServiceVersion"/> of the service API used when |
| | 92 | | /// making requests. |
| | 93 | | /// </param> |
| 15334 | 94 | | public BlobClientOptions(ServiceVersion version = LatestVersion) |
| | 95 | | { |
| 15334 | 96 | | if (ServiceVersion.V2019_02_02 <= version |
| 15334 | 97 | | && version <= LatestVersion) |
| | 98 | | { |
| 15334 | 99 | | Version = version; |
| | 100 | | } |
| | 101 | | else |
| | 102 | | { |
| 0 | 103 | | throw Errors.VersionNotSupported(nameof(version)); |
| | 104 | | } |
| | 105 | |
|
| 15334 | 106 | | this.Initialize(); |
| 15334 | 107 | | AddHeadersAndQueryParameters(); |
| 15334 | 108 | | } |
| | 109 | |
|
| | 110 | | /// <summary> |
| | 111 | | /// Add headers and query parameters in <see cref="DiagnosticsOptions.LoggedHeaderNames"/> and <see cref="Diagno |
| | 112 | | /// </summary> |
| | 113 | | private void AddHeadersAndQueryParameters() |
| | 114 | | { |
| 15334 | 115 | | Diagnostics.LoggedHeaderNames.Add("Access-Control-Allow-Origin"); |
| 15334 | 116 | | Diagnostics.LoggedHeaderNames.Add("x-ms-date"); |
| 15334 | 117 | | Diagnostics.LoggedHeaderNames.Add("x-ms-error-code"); |
| 15334 | 118 | | Diagnostics.LoggedHeaderNames.Add("x-ms-request-id"); |
| 15334 | 119 | | Diagnostics.LoggedHeaderNames.Add("x-ms-version"); |
| 15334 | 120 | | Diagnostics.LoggedHeaderNames.Add("Accept-Ranges"); |
| 15334 | 121 | | Diagnostics.LoggedHeaderNames.Add("Content-Disposition"); |
| 15334 | 122 | | Diagnostics.LoggedHeaderNames.Add("Content-Encoding"); |
| 15334 | 123 | | Diagnostics.LoggedHeaderNames.Add("Content-Language"); |
| 15334 | 124 | | Diagnostics.LoggedHeaderNames.Add("Content-MD5"); |
| 15334 | 125 | | Diagnostics.LoggedHeaderNames.Add("Content-Range"); |
| 15334 | 126 | | Diagnostics.LoggedHeaderNames.Add("Vary"); |
| 15334 | 127 | | Diagnostics.LoggedHeaderNames.Add("x-ms-content-crc64"); |
| 15334 | 128 | | Diagnostics.LoggedHeaderNames.Add("x-ms-copy-action"); |
| 15334 | 129 | | Diagnostics.LoggedHeaderNames.Add("x-ms-copy-completion-time"); |
| 15334 | 130 | | Diagnostics.LoggedHeaderNames.Add("x-ms-copy-id"); |
| 15334 | 131 | | Diagnostics.LoggedHeaderNames.Add("x-ms-copy-progress"); |
| 15334 | 132 | | Diagnostics.LoggedHeaderNames.Add("x-ms-copy-status"); |
| 15334 | 133 | | Diagnostics.LoggedHeaderNames.Add("x-ms-has-immutability-policy"); |
| 15334 | 134 | | Diagnostics.LoggedHeaderNames.Add("x-ms-has-legal-hold"); |
| 15334 | 135 | | Diagnostics.LoggedHeaderNames.Add("x-ms-lease-state"); |
| 15334 | 136 | | Diagnostics.LoggedHeaderNames.Add("x-ms-lease-status"); |
| 15334 | 137 | | Diagnostics.LoggedHeaderNames.Add("x-ms-range"); |
| 15334 | 138 | | Diagnostics.LoggedHeaderNames.Add("x-ms-request-server-encrypted"); |
| 15334 | 139 | | Diagnostics.LoggedHeaderNames.Add("x-ms-server-encrypted"); |
| 15334 | 140 | | Diagnostics.LoggedHeaderNames.Add("x-ms-snapshot"); |
| 15334 | 141 | | Diagnostics.LoggedHeaderNames.Add("x-ms-source-range"); |
| 15334 | 142 | | Diagnostics.LoggedHeaderNames.Add("x-ms-access-tier"); |
| 15334 | 143 | | Diagnostics.LoggedHeaderNames.Add("x-ms-access-tier-change-time"); |
| 15334 | 144 | | Diagnostics.LoggedHeaderNames.Add("x-ms-access-tier-inferred"); |
| 15334 | 145 | | Diagnostics.LoggedHeaderNames.Add("x-ms-account-kind"); |
| 15334 | 146 | | Diagnostics.LoggedHeaderNames.Add("x-ms-archive-status"); |
| 15334 | 147 | | Diagnostics.LoggedHeaderNames.Add("x-ms-blob-append-offset"); |
| 15334 | 148 | | Diagnostics.LoggedHeaderNames.Add("x-ms-blob-cache-control"); |
| 15334 | 149 | | Diagnostics.LoggedHeaderNames.Add("x-ms-blob-committed-block-count"); |
| 15334 | 150 | | Diagnostics.LoggedHeaderNames.Add("x-ms-blob-condition-appendpos"); |
| 15334 | 151 | | Diagnostics.LoggedHeaderNames.Add("x-ms-blob-condition-maxsize"); |
| 15334 | 152 | | Diagnostics.LoggedHeaderNames.Add("x-ms-blob-content-disposition"); |
| 15334 | 153 | | Diagnostics.LoggedHeaderNames.Add("x-ms-blob-content-encoding"); |
| 15334 | 154 | | Diagnostics.LoggedHeaderNames.Add("x-ms-blob-content-language"); |
| 15334 | 155 | | Diagnostics.LoggedHeaderNames.Add("x-ms-blob-content-length"); |
| 15334 | 156 | | Diagnostics.LoggedHeaderNames.Add("x-ms-blob-content-md5"); |
| 15334 | 157 | | Diagnostics.LoggedHeaderNames.Add("x-ms-blob-content-type"); |
| 15334 | 158 | | Diagnostics.LoggedHeaderNames.Add("x-ms-blob-public-access"); |
| 15334 | 159 | | Diagnostics.LoggedHeaderNames.Add("x-ms-blob-sequence-number"); |
| 15334 | 160 | | Diagnostics.LoggedHeaderNames.Add("x-ms-blob-type"); |
| 15334 | 161 | | Diagnostics.LoggedHeaderNames.Add("x-ms-copy-destination-snapshot"); |
| 15334 | 162 | | Diagnostics.LoggedHeaderNames.Add("x-ms-creation-time"); |
| 15334 | 163 | | Diagnostics.LoggedHeaderNames.Add("x-ms-default-encryption-scope"); |
| 15334 | 164 | | Diagnostics.LoggedHeaderNames.Add("x-ms-delete-snapshots"); |
| 15334 | 165 | | Diagnostics.LoggedHeaderNames.Add("x-ms-delete-type-permanent"); |
| 15334 | 166 | | Diagnostics.LoggedHeaderNames.Add("x-ms-deny-encryption-scope-override"); |
| 15334 | 167 | | Diagnostics.LoggedHeaderNames.Add("x-ms-encryption-algorithm"); |
| 15334 | 168 | | Diagnostics.LoggedHeaderNames.Add("x-ms-if-sequence-number-eq"); |
| 15334 | 169 | | Diagnostics.LoggedHeaderNames.Add("x-ms-if-sequence-number-le"); |
| 15334 | 170 | | Diagnostics.LoggedHeaderNames.Add("x-ms-if-sequence-number-lt"); |
| 15334 | 171 | | Diagnostics.LoggedHeaderNames.Add("x-ms-incremental-copy"); |
| 15334 | 172 | | Diagnostics.LoggedHeaderNames.Add("x-ms-lease-action"); |
| 15334 | 173 | | Diagnostics.LoggedHeaderNames.Add("x-ms-lease-break-period"); |
| 15334 | 174 | | Diagnostics.LoggedHeaderNames.Add("x-ms-lease-duration"); |
| 15334 | 175 | | Diagnostics.LoggedHeaderNames.Add("x-ms-lease-id"); |
| 15334 | 176 | | Diagnostics.LoggedHeaderNames.Add("x-ms-lease-time"); |
| 15334 | 177 | | Diagnostics.LoggedHeaderNames.Add("x-ms-page-write"); |
| 15334 | 178 | | Diagnostics.LoggedHeaderNames.Add("x-ms-proposed-lease-id"); |
| 15334 | 179 | | Diagnostics.LoggedHeaderNames.Add("x-ms-range-get-content-md5"); |
| 15334 | 180 | | Diagnostics.LoggedHeaderNames.Add("x-ms-rehydrate-priority"); |
| 15334 | 181 | | Diagnostics.LoggedHeaderNames.Add("x-ms-sequence-number-action"); |
| 15334 | 182 | | Diagnostics.LoggedHeaderNames.Add("x-ms-sku-name"); |
| 15334 | 183 | | Diagnostics.LoggedHeaderNames.Add("x-ms-source-content-md5"); |
| 15334 | 184 | | Diagnostics.LoggedHeaderNames.Add("x-ms-source-if-match"); |
| 15334 | 185 | | Diagnostics.LoggedHeaderNames.Add("x-ms-source-if-modified-since"); |
| 15334 | 186 | | Diagnostics.LoggedHeaderNames.Add("x-ms-source-if-none-match"); |
| 15334 | 187 | | Diagnostics.LoggedHeaderNames.Add("x-ms-source-if-unmodified-since"); |
| 15334 | 188 | | Diagnostics.LoggedHeaderNames.Add("x-ms-tag-count"); |
| 15334 | 189 | | Diagnostics.LoggedHeaderNames.Add("x-ms-encryption-key-sha256"); |
| | 190 | |
|
| 15334 | 191 | | Diagnostics.LoggedQueryParameters.Add("comp"); |
| 15334 | 192 | | Diagnostics.LoggedQueryParameters.Add("maxresults"); |
| 15334 | 193 | | Diagnostics.LoggedQueryParameters.Add("rscc"); |
| 15334 | 194 | | Diagnostics.LoggedQueryParameters.Add("rscd"); |
| 15334 | 195 | | Diagnostics.LoggedQueryParameters.Add("rsce"); |
| 15334 | 196 | | Diagnostics.LoggedQueryParameters.Add("rscl"); |
| 15334 | 197 | | Diagnostics.LoggedQueryParameters.Add("rsct"); |
| 15334 | 198 | | Diagnostics.LoggedQueryParameters.Add("se"); |
| 15334 | 199 | | Diagnostics.LoggedQueryParameters.Add("si"); |
| 15334 | 200 | | Diagnostics.LoggedQueryParameters.Add("sip"); |
| 15334 | 201 | | Diagnostics.LoggedQueryParameters.Add("sp"); |
| 15334 | 202 | | Diagnostics.LoggedQueryParameters.Add("spr"); |
| 15334 | 203 | | Diagnostics.LoggedQueryParameters.Add("sr"); |
| 15334 | 204 | | Diagnostics.LoggedQueryParameters.Add("srt"); |
| 15334 | 205 | | Diagnostics.LoggedQueryParameters.Add("ss"); |
| 15334 | 206 | | Diagnostics.LoggedQueryParameters.Add("st"); |
| 15334 | 207 | | Diagnostics.LoggedQueryParameters.Add("sv"); |
| 15334 | 208 | | Diagnostics.LoggedQueryParameters.Add("include"); |
| 15334 | 209 | | Diagnostics.LoggedQueryParameters.Add("marker"); |
| 15334 | 210 | | Diagnostics.LoggedQueryParameters.Add("prefix"); |
| 15334 | 211 | | Diagnostics.LoggedQueryParameters.Add("copyid"); |
| 15334 | 212 | | Diagnostics.LoggedQueryParameters.Add("restype"); |
| 15334 | 213 | | Diagnostics.LoggedQueryParameters.Add("blockid"); |
| 15334 | 214 | | Diagnostics.LoggedQueryParameters.Add("blocklisttype"); |
| 15334 | 215 | | Diagnostics.LoggedQueryParameters.Add("delimiter"); |
| 15334 | 216 | | Diagnostics.LoggedQueryParameters.Add("prevsnapshot"); |
| 15334 | 217 | | Diagnostics.LoggedQueryParameters.Add("ske"); |
| 15334 | 218 | | Diagnostics.LoggedQueryParameters.Add("skoid"); |
| 15334 | 219 | | Diagnostics.LoggedQueryParameters.Add("sks"); |
| 15334 | 220 | | Diagnostics.LoggedQueryParameters.Add("skt"); |
| 15334 | 221 | | Diagnostics.LoggedQueryParameters.Add("sktid"); |
| 15334 | 222 | | Diagnostics.LoggedQueryParameters.Add("skv"); |
| 15334 | 223 | | Diagnostics.LoggedQueryParameters.Add("snapshot"); |
| 15334 | 224 | | } |
| | 225 | |
|
| | 226 | | /// <summary> |
| | 227 | | /// Create an HttpPipeline from BlobClientOptions. |
| | 228 | | /// </summary> |
| | 229 | | /// <param name="authentication">Optional authentication policy.</param> |
| | 230 | | /// <returns>An HttpPipeline to use for Storage requests.</returns> |
| | 231 | | internal HttpPipeline Build(HttpPipelinePolicy authentication = null) |
| | 232 | | { |
| 4592 | 233 | | return this.Build(authentication, GeoRedundantSecondaryUri); |
| | 234 | | } |
| | 235 | |
|
| | 236 | | /// <summary> |
| | 237 | | /// Create an HttpPipeline from BlobClientOptions. |
| | 238 | | /// </summary> |
| | 239 | | /// <param name="credentials">Optional authentication credentials.</param> |
| | 240 | | /// <returns>An HttpPipeline to use for Storage requests.</returns> |
| | 241 | | internal HttpPipeline Build(object credentials) |
| | 242 | | { |
| 148 | 243 | | return this.Build(credentials, GeoRedundantSecondaryUri); |
| | 244 | | } |
| | 245 | | } |
| | 246 | | } |