| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | | using System.Collections.Generic; |
| | 6 | | using System.Net; |
| | 7 | | using System.ComponentModel; |
| | 8 | | using System.Threading; |
| | 9 | | using System.Threading.Tasks; |
| | 10 | | using Azure.Core; |
| | 11 | | using Azure.Core.Pipeline; |
| | 12 | | using Azure.Storage.Blobs.Models; |
| | 13 | | using Azure.Storage.Cryptography; |
| | 14 | | using Metadata = System.Collections.Generic.IDictionary<string, string>; |
| | 15 | |
|
| | 16 | | namespace Azure.Storage.Blobs |
| | 17 | | { |
| | 18 | | /// <summary> |
| | 19 | | /// The <see cref="BlobServiceClient"/> allows you to manipulate Azure |
| | 20 | | /// Storage service resources and blob containers. The storage account provides |
| | 21 | | /// the top-level namespace for the Blob service. |
| | 22 | | /// </summary> |
| | 23 | | public class BlobServiceClient |
| | 24 | | { |
| | 25 | | /// <summary> |
| | 26 | | /// Gets the blob service's primary <see cref="Uri"/> endpoint. |
| | 27 | | /// </summary> |
| | 28 | | private readonly Uri _uri; |
| | 29 | |
|
| | 30 | | /// <summary> |
| | 31 | | /// Gets the blob service's primary <see cref="Uri"/> endpoint. |
| | 32 | | /// </summary> |
| 4604 | 33 | | public virtual Uri Uri => _uri; |
| | 34 | |
|
| | 35 | | /// <summary> |
| | 36 | | /// The <see cref="HttpPipeline"/> transport pipeline used to send |
| | 37 | | /// every request. |
| | 38 | | /// </summary> |
| | 39 | | private readonly HttpPipeline _pipeline; |
| | 40 | |
|
| | 41 | | /// <summary> |
| | 42 | | /// The <see cref="HttpPipeline"/> transport pipeline used to send |
| | 43 | | /// every request. |
| | 44 | | /// </summary> |
| 4804 | 45 | | internal virtual HttpPipeline Pipeline => _pipeline; |
| | 46 | |
|
| | 47 | | /// <summary> |
| | 48 | | /// The version of the service to use when sending requests. |
| | 49 | | /// </summary> |
| | 50 | | private readonly BlobClientOptions.ServiceVersion _version; |
| | 51 | |
|
| | 52 | | /// <summary> |
| | 53 | | /// The version of the service to use when sending requests. |
| | 54 | | /// </summary> |
| 4504 | 55 | | internal virtual BlobClientOptions.ServiceVersion Version => _version; |
| | 56 | |
|
| | 57 | | /// <summary> |
| | 58 | | /// The authentication policy for our pipeline. We cache it here in |
| | 59 | | /// case we need to construct a pipeline for authenticating batch |
| | 60 | | /// operations. |
| | 61 | | /// </summary> |
| | 62 | | private readonly HttpPipelinePolicy _authenticationPolicy; |
| | 63 | |
|
| 116 | 64 | | internal virtual HttpPipelinePolicy AuthenticationPolicy => _authenticationPolicy; |
| | 65 | |
|
| | 66 | | /// <summary> |
| | 67 | | /// The <see cref="ClientDiagnostics"/> instance used to create diagnostic scopes |
| | 68 | | /// every request. |
| | 69 | | /// </summary> |
| | 70 | | private readonly ClientDiagnostics _clientDiagnostics; |
| | 71 | |
|
| | 72 | | /// <summary> |
| | 73 | | /// The <see cref="ClientDiagnostics"/> instance used to create diagnostic scopes |
| | 74 | | /// every request. |
| | 75 | | /// </summary> |
| 4504 | 76 | | internal virtual ClientDiagnostics ClientDiagnostics => _clientDiagnostics; |
| | 77 | |
|
| | 78 | | /// <summary> |
| | 79 | | /// The <see cref="CustomerProvidedKey"/> to be used when sending requests. |
| | 80 | | /// </summary> |
| | 81 | | internal readonly CustomerProvidedKey? _customerProvidedKey; |
| | 82 | |
|
| | 83 | | /// <summary> |
| | 84 | | /// The <see cref="CustomerProvidedKey"/> to be used when sending requests. |
| | 85 | | /// </summary> |
| 4092 | 86 | | internal virtual CustomerProvidedKey? CustomerProvidedKey => _customerProvidedKey; |
| | 87 | |
|
| | 88 | | /// <summary> |
| | 89 | | /// The <see cref="ClientSideEncryptionOptions"/> to be used when sending/receiving requests. |
| | 90 | | /// </summary> |
| | 91 | | private readonly ClientSideEncryptionOptions _clientSideEncryption; |
| | 92 | |
|
| | 93 | | /// <summary> |
| | 94 | | /// The <see cref="ClientSideEncryptionOptions"/> to be used when sending/receiving requests. |
| | 95 | | /// </summary> |
| 4092 | 96 | | internal virtual ClientSideEncryptionOptions ClientSideEncryption => _clientSideEncryption; |
| | 97 | |
|
| | 98 | | /// <summary> |
| | 99 | | /// The name of the Encryption Scope to be used when sending request. |
| | 100 | | /// </summary> |
| | 101 | | internal readonly string _encryptionScope; |
| | 102 | |
|
| | 103 | | /// <summary> |
| | 104 | | /// The name of the Encryption Scope to be used when sending request. |
| | 105 | | /// </summary> |
| 4092 | 106 | | internal virtual string EncryptionScope => _encryptionScope; |
| | 107 | |
|
| | 108 | | /// <summary> |
| | 109 | | /// The Storage account name corresponding to the service client. |
| | 110 | | /// </summary> |
| | 111 | | private string _accountName; |
| | 112 | |
|
| | 113 | | /// <summary> |
| | 114 | | /// Gets the Storage account name corresponding to the service client. |
| | 115 | | /// </summary> |
| | 116 | | public string AccountName |
| | 117 | | { |
| | 118 | | get |
| | 119 | | { |
| 48 | 120 | | if (_accountName == null) |
| | 121 | | { |
| 44 | 122 | | _accountName = new BlobUriBuilder(Uri).AccountName; |
| | 123 | | } |
| 48 | 124 | | return _accountName; |
| | 125 | | } |
| | 126 | | } |
| | 127 | |
|
| | 128 | | #region ctors |
| | 129 | | /// <summary> |
| | 130 | | /// Initializes a new instance of the <see cref="BlobServiceClient"/> |
| | 131 | | /// class for mocking. |
| | 132 | | /// </summary> |
| 4108 | 133 | | protected BlobServiceClient() |
| | 134 | | { |
| 4108 | 135 | | } |
| | 136 | |
|
| | 137 | | /// <summary> |
| | 138 | | /// Initializes a new instance of the <see cref="BlobServiceClient"/> |
| | 139 | | /// class. |
| | 140 | | /// </summary> |
| | 141 | | /// <param name="connectionString"> |
| | 142 | | /// A connection string includes the authentication information |
| | 143 | | /// required for your application to access data in an Azure Storage |
| | 144 | | /// account at runtime. |
| | 145 | | /// |
| | 146 | | /// For more information, <see href="https://docs.microsoft.com/azure/storage/common/storage-configure-connectio |
| | 147 | | /// </param> |
| | 148 | | public BlobServiceClient(string connectionString) |
| 4 | 149 | | : this(connectionString, null) |
| | 150 | | { |
| 4 | 151 | | } |
| | 152 | |
|
| | 153 | | /// <summary> |
| | 154 | | /// Initializes a new instance of the <see cref="BlobServiceClient"/> |
| | 155 | | /// class. |
| | 156 | | /// </summary> |
| | 157 | | /// <param name="connectionString"> |
| | 158 | | /// A connection string includes the authentication information |
| | 159 | | /// required for your application to access data in an Azure Storage |
| | 160 | | /// account at runtime. |
| | 161 | | /// |
| | 162 | | /// For more information, |
| | 163 | | /// <see href="https://docs.microsoft.com/azure/storage/common/storage-configure-connection-string"> |
| | 164 | | /// Configure Azure Storage connection strings</see> |
| | 165 | | /// </param> |
| | 166 | | /// <param name="options"> |
| | 167 | | /// Optional client options that define the transport pipeline |
| | 168 | | /// policies for authentication, retries, etc., that are applied to |
| | 169 | | /// every request. |
| | 170 | | /// </param> |
| 8 | 171 | | public BlobServiceClient(string connectionString, BlobClientOptions options) |
| | 172 | | { |
| 8 | 173 | | var conn = StorageConnectionString.Parse(connectionString); |
| 8 | 174 | | _uri = conn.BlobEndpoint; |
| 8 | 175 | | options ??= new BlobClientOptions(); |
| 8 | 176 | | _authenticationPolicy = StorageClientOptions.GetAuthenticationPolicy(conn.Credentials); |
| 8 | 177 | | _pipeline = options.Build(_authenticationPolicy); |
| 8 | 178 | | _version = options.Version; |
| 8 | 179 | | _clientDiagnostics = new ClientDiagnostics(options); |
| 8 | 180 | | _customerProvidedKey = options.CustomerProvidedKey; |
| 8 | 181 | | _clientSideEncryption = options._clientSideEncryptionOptions?.Clone(); |
| 8 | 182 | | _encryptionScope = options.EncryptionScope; |
| 8 | 183 | | BlobErrors.VerifyHttpsCustomerProvidedKey(_uri, _customerProvidedKey); |
| 8 | 184 | | BlobErrors.VerifyCpkAndEncryptionScopeNotBothSet(_customerProvidedKey, _encryptionScope); |
| 8 | 185 | | } |
| | 186 | |
|
| | 187 | | /// <summary> |
| | 188 | | /// Initializes a new instance of the <see cref="BlobServiceClient"/> |
| | 189 | | /// class. |
| | 190 | | /// </summary> |
| | 191 | | /// <param name="serviceUri"> |
| | 192 | | /// A <see cref="Uri"/> referencing the blob service. |
| | 193 | | /// This is likely to be similar to "https://{account_name}.blob.core.windows.net". |
| | 194 | | /// </param> |
| | 195 | | /// <param name="options"> |
| | 196 | | /// Optional client options that define the transport pipeline |
| | 197 | | /// policies for authentication, retries, etc., that are applied to |
| | 198 | | /// every request. |
| | 199 | | /// </param> |
| | 200 | | public BlobServiceClient(Uri serviceUri, BlobClientOptions options = default) |
| 84 | 201 | | : this(serviceUri, (HttpPipelinePolicy)null, options ?? new BlobClientOptions()) |
| | 202 | | { |
| 80 | 203 | | } |
| | 204 | |
|
| | 205 | | /// <summary> |
| | 206 | | /// Initializes a new instance of the <see cref="BlobServiceClient"/> |
| | 207 | | /// class. |
| | 208 | | /// </summary> |
| | 209 | | /// <param name="serviceUri"> |
| | 210 | | /// A <see cref="Uri"/> referencing the blob service. |
| | 211 | | /// This is likely to be similar to "https://{account_name}.blob.core.windows.net". |
| | 212 | | /// </param> |
| | 213 | | /// <param name="credential"> |
| | 214 | | /// The shared key credential used to sign requests. |
| | 215 | | /// </param> |
| | 216 | | /// <param name="options"> |
| | 217 | | /// Optional client options that define the transport pipeline |
| | 218 | | /// policies for authentication, retries, etc., that are applied to |
| | 219 | | /// every request. |
| | 220 | | /// </param> |
| | 221 | | public BlobServiceClient(Uri serviceUri, StorageSharedKeyCredential credential, BlobClientOptions options = defa |
| 3968 | 222 | | : this(serviceUri, credential.AsPolicy(), options ?? new BlobClientOptions()) |
| | 223 | | { |
| 3968 | 224 | | } |
| | 225 | |
|
| | 226 | | /// <summary> |
| | 227 | | /// Initializes a new instance of the <see cref="BlobServiceClient"/> |
| | 228 | | /// class. |
| | 229 | | /// </summary> |
| | 230 | | /// <param name="serviceUri"> |
| | 231 | | /// A <see cref="Uri"/> referencing the blob service. |
| | 232 | | /// This is likely to be similar to "https://{account_name}.blob.core.windows.net". |
| | 233 | | /// </param> |
| | 234 | | /// <param name="credential"> |
| | 235 | | /// The token credential used to sign requests. |
| | 236 | | /// </param> |
| | 237 | | /// <param name="options"> |
| | 238 | | /// Optional client options that define the transport pipeline |
| | 239 | | /// policies for authentication, retries, etc., that are applied to |
| | 240 | | /// every request. |
| | 241 | | /// </param> |
| | 242 | | public BlobServiceClient(Uri serviceUri, TokenCredential credential, BlobClientOptions options = default) |
| 68 | 243 | | : this(serviceUri, credential.AsPolicy(), options ?? new BlobClientOptions()) |
| | 244 | | { |
| 68 | 245 | | Errors.VerifyHttpsTokenAuth(serviceUri); |
| 64 | 246 | | } |
| | 247 | |
|
| | 248 | | /// <summary> |
| | 249 | | /// Initializes a new instance of the <see cref="BlobServiceClient"/> |
| | 250 | | /// class. |
| | 251 | | /// </summary> |
| | 252 | | /// <param name="serviceUri"> |
| | 253 | | /// A <see cref="Uri"/> referencing the blob service. |
| | 254 | | /// This is likely to be similar to "https://{account_name}.blob.core.windows.net". |
| | 255 | | /// </param> |
| | 256 | | /// <param name="authentication"> |
| | 257 | | /// An optional authentication policy used to sign requests. |
| | 258 | | /// </param> |
| | 259 | | /// <param name="options"> |
| | 260 | | /// Optional client options that define the transport pipeline |
| | 261 | | /// policies for authentication, retries, etc., that are applied to |
| | 262 | | /// every request. |
| | 263 | | /// </param> |
| | 264 | | internal BlobServiceClient(Uri serviceUri, HttpPipelinePolicy authentication, BlobClientOptions options) |
| 4120 | 265 | | : this( |
| 4120 | 266 | | serviceUri, |
| 4120 | 267 | | authentication, |
| 4120 | 268 | | options?.Version ?? BlobClientOptions.LatestVersion, |
| 4120 | 269 | | new ClientDiagnostics(options), |
| 4120 | 270 | | options?.CustomerProvidedKey, |
| 4120 | 271 | | options?._clientSideEncryptionOptions?.Clone(), |
| 4120 | 272 | | options?.EncryptionScope, |
| 4120 | 273 | | options.Build(authentication)) |
| | 274 | | { |
| | 275 | |
|
| 4116 | 276 | | } |
| | 277 | |
|
| | 278 | | /// <summary> |
| | 279 | | /// Initializes a new instance of the <see cref="BlobServiceClient"/> |
| | 280 | | /// class. |
| | 281 | | /// </summary> |
| | 282 | | /// <param name="serviceUri"> |
| | 283 | | /// A <see cref="Uri"/> referencing the blob service. |
| | 284 | | /// This is likely to be similar to "https://{account_name}.blob.core.windows.net". |
| | 285 | | /// </param> |
| | 286 | | /// <param name="authentication"> |
| | 287 | | /// An optional authentication policy used to sign requests. |
| | 288 | | /// </param> |
| | 289 | | /// <param name="version"> |
| | 290 | | /// The version of the service to use when sending requests. |
| | 291 | | /// </param> |
| | 292 | | /// <param name="clientDiagnostics"> |
| | 293 | | /// The <see cref="ClientDiagnostics"/> instance used to create |
| | 294 | | /// diagnostic scopes every request. |
| | 295 | | /// </param> |
| | 296 | | /// <param name="customerProvidedKey">Customer provided key.</param> |
| | 297 | | /// <param name="clientSideEncryption">Client-side encryption options.</param> |
| | 298 | | /// <param name="encryptionScope">Encryption scope.</param> |
| | 299 | | /// <param name="pipeline"> |
| | 300 | | /// The transport pipeline used to send every request. |
| | 301 | | /// </param> |
| 7038 | 302 | | internal BlobServiceClient( |
| 7038 | 303 | | Uri serviceUri, |
| 7038 | 304 | | HttpPipelinePolicy authentication, |
| 7038 | 305 | | BlobClientOptions.ServiceVersion version, |
| 7038 | 306 | | ClientDiagnostics clientDiagnostics, |
| 7038 | 307 | | CustomerProvidedKey? customerProvidedKey, |
| 7038 | 308 | | ClientSideEncryptionOptions clientSideEncryption, |
| 7038 | 309 | | string encryptionScope, |
| 7038 | 310 | | HttpPipeline pipeline) |
| | 311 | | { |
| 7038 | 312 | | _uri = serviceUri; |
| 7038 | 313 | | _authenticationPolicy = authentication; |
| 7038 | 314 | | _pipeline = pipeline; |
| 7038 | 315 | | _version = version; |
| 7038 | 316 | | _clientDiagnostics = clientDiagnostics; |
| 7038 | 317 | | _customerProvidedKey = customerProvidedKey; |
| 7038 | 318 | | _clientSideEncryption = clientSideEncryption?.Clone(); |
| 7038 | 319 | | _encryptionScope = encryptionScope; |
| 7038 | 320 | | BlobErrors.VerifyCpkAndEncryptionScopeNotBothSet(_customerProvidedKey, _encryptionScope); |
| 7038 | 321 | | BlobErrors.VerifyHttpsCustomerProvidedKey(_uri, _customerProvidedKey); |
| 7034 | 322 | | } |
| | 323 | |
|
| | 324 | | /// <summary> |
| | 325 | | /// Intended for DataLake to create a backing blob client. |
| | 326 | | /// |
| | 327 | | /// Initializes a new instance of the <see cref="BlobServiceClient"/> |
| | 328 | | /// class. |
| | 329 | | /// </summary> |
| | 330 | | /// <param name="serviceUri"> |
| | 331 | | /// A <see cref="Uri"/> referencing the block blob that includes the |
| | 332 | | /// name of the account, the name of the container, and the name of |
| | 333 | | /// the blob. |
| | 334 | | /// </param> |
| | 335 | | /// <param name="options"> |
| | 336 | | /// Optional client options that define the transport pipeline |
| | 337 | | /// policies for authentication, retries, etc., that are applied to |
| | 338 | | /// every request. |
| | 339 | | /// </param> |
| | 340 | | /// <param name="authentication"> |
| | 341 | | /// An optional authentication policy used to sign requests. |
| | 342 | | /// </param> |
| | 343 | | /// <param name="pipeline"> |
| | 344 | | /// The transport pipeline used to send every request. |
| | 345 | | /// </param> |
| | 346 | | /// <returns> |
| | 347 | | /// New instanc of the <see cref="BlobServiceClient"/> class. |
| | 348 | | /// </returns> |
| | 349 | | protected static BlobServiceClient CreateClient( |
| | 350 | | Uri serviceUri, |
| | 351 | | BlobClientOptions options, |
| | 352 | | HttpPipelinePolicy authentication, |
| | 353 | | HttpPipeline pipeline) |
| | 354 | | { |
| 2918 | 355 | | return new BlobServiceClient( |
| 2918 | 356 | | serviceUri, |
| 2918 | 357 | | authentication, |
| 2918 | 358 | | options.Version, |
| 2918 | 359 | | new ClientDiagnostics(options), |
| 2918 | 360 | | customerProvidedKey: null, |
| 2918 | 361 | | clientSideEncryption: null, |
| 2918 | 362 | | encryptionScope: null, |
| 2918 | 363 | | pipeline); |
| | 364 | | } |
| | 365 | | #endregion ctors |
| | 366 | |
|
| | 367 | | /// <summary> |
| | 368 | | /// Create a new <see cref="BlobContainerClient"/> object by appending |
| | 369 | | /// <paramref name="blobContainerName"/> to the end of <see cref="Uri"/>. |
| | 370 | | /// The new <see cref="BlobContainerClient"/> uses the same request |
| | 371 | | /// policy pipeline as the <see cref="BlobServiceClient"/>. |
| | 372 | | /// </summary> |
| | 373 | | /// <param name="blobContainerName"> |
| | 374 | | /// The name of the blob container to reference. |
| | 375 | | /// </param> |
| | 376 | | /// <returns> |
| | 377 | | /// A <see cref="BlobContainerClient"/> for the desired container. |
| | 378 | | /// </returns> |
| | 379 | | public virtual BlobContainerClient GetBlobContainerClient(string blobContainerName) => |
| 4092 | 380 | | new BlobContainerClient(Uri.AppendToPath(blobContainerName), Pipeline, Version, ClientDiagnostics, CustomerP |
| | 381 | |
|
| | 382 | | #region protected static accessors for Azure.Storage.Blobs.Batch |
| | 383 | | /// <summary> |
| | 384 | | /// Get a <see cref="BlobServiceClient"/>'s <see cref="HttpPipeline"/> |
| | 385 | | /// for creating child clients. |
| | 386 | | /// </summary> |
| | 387 | | /// <param name="client">The BlobServiceClient.</param> |
| | 388 | | /// <returns>The BlobServiceClient's HttpPipeline.</returns> |
| | 389 | | protected static HttpPipeline GetHttpPipeline(BlobServiceClient client) => |
| 116 | 390 | | client.Pipeline; |
| | 391 | |
|
| | 392 | | /// <summary> |
| | 393 | | /// Get a <see cref="BlobServiceClient"/>'s authentication |
| | 394 | | /// <see cref="HttpPipelinePolicy"/> for creating child clients. |
| | 395 | | /// </summary> |
| | 396 | | /// <param name="client">The BlobServiceClient.</param> |
| | 397 | | /// <returns>The BlobServiceClient's authentication policy.</returns> |
| | 398 | | protected static HttpPipelinePolicy GetAuthenticationPolicy(BlobServiceClient client) => |
| 116 | 399 | | client.AuthenticationPolicy; |
| | 400 | |
|
| | 401 | | /// <summary> |
| | 402 | | /// Get a <see cref="BlobServiceClient"/>'s <see cref="BlobClientOptions"/> |
| | 403 | | /// for creating child clients. |
| | 404 | | /// </summary> |
| | 405 | | /// <param name="client">The BlobServiceClient.</param> |
| | 406 | | /// <returns>The BlobServiceClient's BlobClientOptions.</returns> |
| | 407 | | protected static BlobClientOptions GetClientOptions(BlobServiceClient client) => |
| 116 | 408 | | new BlobClientOptions(client.Version) |
| 116 | 409 | | { |
| 116 | 410 | | // We only use this for communicating diagnostics, at the moment |
| 116 | 411 | | Diagnostics = |
| 116 | 412 | | { |
| 116 | 413 | | IsDistributedTracingEnabled = client.ClientDiagnostics.IsActivityEnabled |
| 116 | 414 | | } |
| 116 | 415 | | }; |
| | 416 | | #endregion protected static accessors for Azure.Storage.Blobs.Batch |
| | 417 | |
|
| | 418 | | #region GetBlobContainers |
| | 419 | | /// <summary> |
| | 420 | | /// The <see cref="GetBlobContainers(BlobContainerTraits, BlobContainerStates, string, CancellationToken)"/> |
| | 421 | | /// operation returns an asyncsequence of blob containers in the storage account. Enumerating the |
| | 422 | | /// blob containers may make multiple requests to the service while fetching |
| | 423 | | /// all the values. Containers are ordered lexicographically by name. |
| | 424 | | /// |
| | 425 | | /// For more information, |
| | 426 | | /// see <see href="https://docs.microsoft.com/rest/api/storageservices/list-containers2"> |
| | 427 | | /// List Containers</see>. |
| | 428 | | /// </summary> |
| | 429 | | /// <param name="traits"> |
| | 430 | | /// Specifies trait options for shaping the blob containers. |
| | 431 | | /// </param> |
| | 432 | | /// <param name="states"> |
| | 433 | | /// Specifies state options for shaping the blob containers. |
| | 434 | | /// </param> |
| | 435 | | /// <param name="prefix"> |
| | 436 | | /// Specifies a string that filters the results to return only containers |
| | 437 | | /// whose name begins with the specified <paramref name="prefix"/>. |
| | 438 | | /// </param> |
| | 439 | | /// <param name="cancellationToken"> |
| | 440 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 441 | | /// notifications that the operation should be cancelled. |
| | 442 | | /// </param> |
| | 443 | | /// <returns> |
| | 444 | | /// An <see cref="IEnumerable{T}"/> of <see cref="Response{BlobContainerItem}"/> |
| | 445 | | /// describing the blob containers in the storage account. |
| | 446 | | /// </returns> |
| | 447 | | /// <remarks> |
| | 448 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 449 | | /// a failure occurs. |
| | 450 | | /// </remarks> |
| | 451 | | public virtual Pageable<BlobContainerItem> GetBlobContainers( |
| | 452 | | BlobContainerTraits traits = BlobContainerTraits.None, |
| | 453 | | BlobContainerStates states = BlobContainerStates.None, |
| | 454 | | string prefix = default, |
| | 455 | | CancellationToken cancellationToken = default) => |
| 16 | 456 | | new GetBlobContainersAsyncCollection(this, traits, states, prefix).ToSyncCollection(cancellationToken); |
| | 457 | |
|
| | 458 | | /// <summary> |
| | 459 | | /// The <see cref="GetBlobContainers(BlobContainerTraits, string, CancellationToken)"/> operation returns an asy |
| | 460 | | /// sequence of blob containers in the storage account. Enumerating the |
| | 461 | | /// blob containers may make multiple requests to the service while fetching |
| | 462 | | /// all the values. Containers are ordered lexicographically by name. |
| | 463 | | /// |
| | 464 | | /// For more information, see |
| | 465 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/list-containers2"> |
| | 466 | | /// List Containers</see>. |
| | 467 | | /// </summary> |
| | 468 | | /// <param name="traits"> |
| | 469 | | /// Specifies trait options for shaping the blob containers. |
| | 470 | | /// </param> |
| | 471 | | /// <param name="prefix"> |
| | 472 | | /// Specifies a string that filters the results to return only containers |
| | 473 | | /// whose name begins with the specified <paramref name="prefix"/>. |
| | 474 | | /// </param> |
| | 475 | | /// <param name="cancellationToken"> |
| | 476 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 477 | | /// notifications that the operation should be cancelled. |
| | 478 | | /// </param> |
| | 479 | | /// <returns> |
| | 480 | | /// An <see cref="IEnumerable{T}"/> of <see cref="Response{BlobContainerItem}"/> |
| | 481 | | /// describing the blob containers in the storage account. |
| | 482 | | /// </returns> |
| | 483 | | /// <remarks> |
| | 484 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 485 | | /// a failure occurs. |
| | 486 | | /// </remarks> |
| | 487 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | 488 | | #pragma warning disable AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional Ca |
| | 489 | | public virtual Pageable<BlobContainerItem> GetBlobContainers( |
| | 490 | | #pragma warning restore AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional Ca |
| | 491 | | BlobContainerTraits traits, |
| | 492 | | string prefix, |
| | 493 | | CancellationToken cancellationToken) => |
| 14 | 494 | | new GetBlobContainersAsyncCollection(this, traits, default, prefix).ToSyncCollection(cancellationToken); |
| | 495 | |
|
| | 496 | | /// <summary> |
| | 497 | | /// The <see cref="GetBlobContainersAsync(BlobContainerTraits, BlobContainerStates, string, CancellationToken)"/ |
| | 498 | | /// operation returns an async sequence of blob containers in the storage account. Enumerating the |
| | 499 | | /// blob containers may make multiple requests to the service while fetching |
| | 500 | | /// all the values. Containers are ordered lexicographically by name. |
| | 501 | | /// |
| | 502 | | /// For more information, see |
| | 503 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/list-containers2"> |
| | 504 | | /// List Containers</see>. |
| | 505 | | /// </summary> |
| | 506 | | /// <param name="traits"> |
| | 507 | | /// Specifies trait options for shaping the blob containers. |
| | 508 | | /// </param> |
| | 509 | | /// <param name="states"> |
| | 510 | | /// Specifies states options for shaping the blob containers. |
| | 511 | | /// </param> |
| | 512 | | /// <param name="prefix"> |
| | 513 | | /// Specifies a string that filters the results to return only containers |
| | 514 | | /// whose name begins with the specified <paramref name="prefix"/>. |
| | 515 | | /// </param> |
| | 516 | | /// <param name="cancellationToken"> |
| | 517 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 518 | | /// notifications that the operation should be cancelled. |
| | 519 | | /// </param> |
| | 520 | | /// <returns> |
| | 521 | | /// An <see cref="AsyncPageable{T}"/> describing the |
| | 522 | | /// containers in the storage account. |
| | 523 | | /// </returns> |
| | 524 | | /// <remarks> |
| | 525 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 526 | | /// a failure occurs. |
| | 527 | | /// </remarks> |
| | 528 | | public virtual AsyncPageable<BlobContainerItem> GetBlobContainersAsync( |
| | 529 | | BlobContainerTraits traits = BlobContainerTraits.None, |
| | 530 | | BlobContainerStates states = BlobContainerStates.None, |
| | 531 | | string prefix = default, |
| | 532 | | CancellationToken cancellationToken = default) => |
| 20 | 533 | | new GetBlobContainersAsyncCollection(this, traits, states, prefix).ToAsyncCollection(cancellationToken); |
| | 534 | |
|
| | 535 | | /// <summary> |
| | 536 | | /// The <see cref="GetBlobContainersAsync(BlobContainerTraits, string, CancellationToken)"/> |
| | 537 | | /// operation returns an async sequence of blob containers in the storage account. Enumerating the |
| | 538 | | /// blob containers may make multiple requests to the service while fetching |
| | 539 | | /// all the values. Containers are ordered lexicographically by name. |
| | 540 | | /// |
| | 541 | | /// For more information, see |
| | 542 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/list-containers2"> |
| | 543 | | /// List Containers</see>. |
| | 544 | | /// </summary> |
| | 545 | | /// <param name="traits"> |
| | 546 | | /// Specifies trait options for shaping the blob containers. |
| | 547 | | /// </param> |
| | 548 | | /// <param name="prefix"> |
| | 549 | | /// Specifies a string that filters the results to return only containers |
| | 550 | | /// whose name begins with the specified <paramref name="prefix"/>. |
| | 551 | | /// </param> |
| | 552 | | /// <param name="cancellationToken"> |
| | 553 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 554 | | /// notifications that the operation should be cancelled. |
| | 555 | | /// </param> |
| | 556 | | /// <returns> |
| | 557 | | /// An <see cref="AsyncPageable{T}"/> describing the |
| | 558 | | /// containers in the storage account. |
| | 559 | | /// </returns> |
| | 560 | | /// <remarks> |
| | 561 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 562 | | /// a failure occurs. |
| | 563 | | /// </remarks> |
| | 564 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | 565 | | #pragma warning disable AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional Ca |
| | 566 | | public virtual AsyncPageable<BlobContainerItem> GetBlobContainersAsync( |
| | 567 | | #pragma warning restore AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional Ca |
| | 568 | | BlobContainerTraits traits, |
| | 569 | | string prefix, |
| | 570 | | CancellationToken cancellationToken) => |
| 18 | 571 | | new GetBlobContainersAsyncCollection(this, traits, default, prefix).ToAsyncCollection(cancellationToken); |
| | 572 | |
|
| | 573 | | /// <summary> |
| | 574 | | /// The <see cref="GetBlobContainersInternal"/> operation returns a |
| | 575 | | /// single segment of blob containers in the storage account, starting |
| | 576 | | /// from the specified <paramref name="continuationToken"/>. Use an empty |
| | 577 | | /// <paramref name="continuationToken"/> to start enumeration from the beginning |
| | 578 | | /// and the <see cref="BlobContainersSegment.NextMarker"/> if it's not |
| | 579 | | /// empty to make subsequent calls to <see cref="GetBlobContainersInternal"/> |
| | 580 | | /// to continue enumerating the containers segment by segment. |
| | 581 | | /// Containers are ordered lexicographically by name. |
| | 582 | | /// |
| | 583 | | /// For more information, see |
| | 584 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/list-containers2"> |
| | 585 | | /// List Containers</see>. |
| | 586 | | /// </summary> |
| | 587 | | /// <param name="continuationToken"> |
| | 588 | | /// An optional string value that identifies the segment of the list |
| | 589 | | /// of blob containers to be returned with the next listing operation. The |
| | 590 | | /// operation returns a non-empty <see cref="BlobContainersSegment.NextMarker"/> |
| | 591 | | /// if the listing operation did not return all blob containers remaining |
| | 592 | | /// to be listed with the current segment. The NextMarker value can |
| | 593 | | /// be used as the value for the <paramref name="continuationToken"/> parameter |
| | 594 | | /// in a subsequent call to request the next segment of list items. |
| | 595 | | /// </param> |
| | 596 | | /// <param name="traits"> |
| | 597 | | /// Specifies trait options for shaping the blob containers. |
| | 598 | | /// </param> |
| | 599 | | /// <param name="states"> |
| | 600 | | /// Specifies state options for shaping the blob containers. |
| | 601 | | /// </param> |
| | 602 | | /// <param name="prefix"> |
| | 603 | | /// Specifies a string that filters the results to return only containers |
| | 604 | | /// whose name begins with the specified <paramref name="prefix"/>. |
| | 605 | | /// </param> |
| | 606 | | /// <param name="pageSizeHint"> |
| | 607 | | /// Gets or sets a value indicating the size of the page that should be |
| | 608 | | /// requested. |
| | 609 | | /// </param> |
| | 610 | | /// <param name="async"> |
| | 611 | | /// Whether to invoke the operation asynchronously. |
| | 612 | | /// </param> |
| | 613 | | /// <param name="cancellationToken"> |
| | 614 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 615 | | /// notifications that the operation should be cancelled. |
| | 616 | | /// </param> |
| | 617 | | /// <returns> |
| | 618 | | /// A <see cref="Response{BlobContainersSegment}"/> describing a |
| | 619 | | /// segment of the blob containers in the storage account. |
| | 620 | | /// </returns> |
| | 621 | | /// <remarks> |
| | 622 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 623 | | /// a failure occurs. |
| | 624 | | /// </remarks> |
| | 625 | | internal async Task<Response<BlobContainersSegment>> GetBlobContainersInternal( |
| | 626 | | string continuationToken, |
| | 627 | | BlobContainerTraits traits, |
| | 628 | | BlobContainerStates states, |
| | 629 | | string prefix, |
| | 630 | | int? pageSizeHint, |
| | 631 | | bool async, |
| | 632 | | CancellationToken cancellationToken) |
| | 633 | | { |
| 68 | 634 | | using (Pipeline.BeginLoggingScope(nameof(BlobServiceClient))) |
| | 635 | | { |
| | 636 | | Pipeline.LogMethodEnter( |
| | 637 | | nameof(BlobServiceClient), |
| | 638 | | message: |
| | 639 | | $"{nameof(Uri)}: {Uri}\n" + |
| | 640 | | $"{nameof(continuationToken)}: {continuationToken}\n" + |
| | 641 | | $"{nameof(traits)}: {traits}"); |
| | 642 | | try |
| | 643 | | { |
| 68 | 644 | | Response<BlobContainersSegment> response = await BlobRestClient.Service.ListBlobContainersSegmentAsy |
| 68 | 645 | | ClientDiagnostics, |
| 68 | 646 | | Pipeline, |
| 68 | 647 | | Uri, |
| 68 | 648 | | version: Version.ToVersionString(), |
| 68 | 649 | | marker: continuationToken, |
| 68 | 650 | | prefix: prefix, |
| 68 | 651 | | maxresults: pageSizeHint, |
| 68 | 652 | | include: BlobExtensions.AsIncludeItems(traits, states), |
| 68 | 653 | | async: async, |
| 68 | 654 | | cancellationToken: cancellationToken) |
| 68 | 655 | | .ConfigureAwait(false); |
| 64 | 656 | | if ((traits & BlobContainerTraits.Metadata) != BlobContainerTraits.Metadata) |
| | 657 | | { |
| 56 | 658 | | IEnumerable<BlobContainerItem> containerItems = response.Value.BlobContainerItems; |
| 39904 | 659 | | foreach (BlobContainerItem containerItem in containerItems) |
| | 660 | | { |
| 19896 | 661 | | containerItem.Properties.Metadata = null; |
| | 662 | | } |
| | 663 | | } |
| 64 | 664 | | return response; |
| | 665 | | } |
| 4 | 666 | | catch (Exception ex) |
| | 667 | | { |
| | 668 | | Pipeline.LogException(ex); |
| 4 | 669 | | throw; |
| | 670 | | } |
| | 671 | | finally |
| | 672 | | { |
| | 673 | | Pipeline.LogMethodExit(nameof(BlobServiceClient)); |
| | 674 | | } |
| | 675 | | } |
| 64 | 676 | | } |
| | 677 | | #endregion GetBlobContainers |
| | 678 | |
|
| | 679 | | #region GetAccountInfo |
| | 680 | | /// <summary> |
| | 681 | | /// The <see cref="GetAccountInfo"/> operation returns the sku |
| | 682 | | /// name and account kind for the specified account. |
| | 683 | | /// |
| | 684 | | /// For more information, see |
| | 685 | | /// <see href="https://docs.microsoft.com/en-us/rest/api/storageservices/get-account-information"> |
| | 686 | | /// Get Account Information</see>. |
| | 687 | | /// </summary> |
| | 688 | | /// <param name="cancellationToken"> |
| | 689 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 690 | | /// notifications that the operation should be cancelled. |
| | 691 | | /// </param> |
| | 692 | | /// <returns> |
| | 693 | | /// A <see cref="Response{AccountInfo}"/> describing the account. |
| | 694 | | /// </returns> |
| | 695 | | /// <remarks> |
| | 696 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 697 | | /// a failure occurs. |
| | 698 | | /// </remarks> |
| | 699 | | public virtual Response<AccountInfo> GetAccountInfo( |
| | 700 | | CancellationToken cancellationToken = default) => |
| 16 | 701 | | GetAccountInfoInternal( |
| 16 | 702 | | false, // async |
| 16 | 703 | | cancellationToken) |
| 16 | 704 | | .EnsureCompleted(); |
| | 705 | |
|
| | 706 | | /// <summary> |
| | 707 | | /// The <see cref="GetAccountInfoAsync"/> operation returns the sku |
| | 708 | | /// name and account kind for the specified account. |
| | 709 | | /// |
| | 710 | | /// For more information, see |
| | 711 | | /// <see href="https://docs.microsoft.com/en-us/rest/api/storageservices/get-account-information"> |
| | 712 | | /// Get Account Information</see>. |
| | 713 | | /// </summary> |
| | 714 | | /// <param name="cancellationToken"> |
| | 715 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 716 | | /// notifications that the operation should be cancelled. |
| | 717 | | /// </param> |
| | 718 | | /// <returns> |
| | 719 | | /// A <see cref="Response{AccountInfo}"/> describing the account. |
| | 720 | | /// </returns> |
| | 721 | | /// <remarks> |
| | 722 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 723 | | /// a failure occurs. |
| | 724 | | /// </remarks> |
| | 725 | | public virtual async Task<Response<AccountInfo>> GetAccountInfoAsync( |
| | 726 | | CancellationToken cancellationToken = default) => |
| 16 | 727 | | await GetAccountInfoInternal( |
| 16 | 728 | | true, // async |
| 16 | 729 | | cancellationToken) |
| 16 | 730 | | .ConfigureAwait(false); |
| | 731 | |
|
| | 732 | | /// <summary> |
| | 733 | | /// The <see cref="GetAccountInfoInternal"/> operation returns the sku |
| | 734 | | /// name and account kind for the specified account. |
| | 735 | | /// |
| | 736 | | /// For more information, see |
| | 737 | | /// <see href="https://docs.microsoft.com/en-us/rest/api/storageservices/get-account-information"> |
| | 738 | | /// Get Account Information</see>. |
| | 739 | | /// </summary> |
| | 740 | | /// <param name="async"> |
| | 741 | | /// Whether to invoke the operation asynchronously. |
| | 742 | | /// </param> |
| | 743 | | /// <param name="cancellationToken"> |
| | 744 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 745 | | /// notifications that the operation should be cancelled. |
| | 746 | | /// </param> |
| | 747 | | /// <returns> |
| | 748 | | /// A <see cref="Response{AccountInfo}"/> describing the account. |
| | 749 | | /// </returns> |
| | 750 | | /// <remarks> |
| | 751 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 752 | | /// a failure occurs. |
| | 753 | | /// </remarks> |
| | 754 | | private async Task<Response<AccountInfo>> GetAccountInfoInternal( |
| | 755 | | bool async, |
| | 756 | | CancellationToken cancellationToken) |
| | 757 | | { |
| 32 | 758 | | using (Pipeline.BeginLoggingScope(nameof(BlobServiceClient))) |
| | 759 | | { |
| | 760 | | Pipeline.LogMethodEnter(nameof(BlobServiceClient), message: $"{nameof(Uri)}: {Uri}"); |
| | 761 | | try |
| | 762 | | { |
| 32 | 763 | | return await BlobRestClient.Service.GetAccountInfoAsync( |
| 32 | 764 | | ClientDiagnostics, |
| 32 | 765 | | Pipeline, |
| 32 | 766 | | Uri, |
| 32 | 767 | | version: Version.ToVersionString(), |
| 32 | 768 | | async: async, |
| 32 | 769 | | operationName: $"{nameof(BlobServiceClient)}.{nameof(GetAccountInfo)}", |
| 32 | 770 | | cancellationToken: cancellationToken) |
| 32 | 771 | | .ConfigureAwait(false); |
| | 772 | | } |
| 12 | 773 | | catch (Exception ex) |
| | 774 | | { |
| | 775 | | Pipeline.LogException(ex); |
| 12 | 776 | | throw; |
| | 777 | | } |
| | 778 | | finally |
| | 779 | | { |
| | 780 | | Pipeline.LogMethodExit(nameof(BlobServiceClient)); |
| | 781 | | } |
| | 782 | | } |
| 20 | 783 | | } |
| | 784 | | #endregion GetAccountInfo |
| | 785 | |
|
| | 786 | | #region GetProperties |
| | 787 | | /// <summary> |
| | 788 | | /// The <see cref="GetProperties"/> operation gets the properties |
| | 789 | | /// of a storage account’s blob service, including properties for |
| | 790 | | /// Storage Analytics and CORS (Cross-Origin Resource Sharing) rules. |
| | 791 | | /// |
| | 792 | | /// For more information, see |
| | 793 | | /// <see href="https://docs.microsoft.com/en-us/rest/api/storageservices/get-blob-service-properties"> |
| | 794 | | /// Get Blob Service Properties</see>. |
| | 795 | | /// </summary> |
| | 796 | | /// <param name="cancellationToken"> |
| | 797 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 798 | | /// notifications that the operation should be cancelled. |
| | 799 | | /// </param> |
| | 800 | | /// <returns> |
| | 801 | | /// A <see cref="Response{BlobServiceProperties}"/> describing |
| | 802 | | /// the service properties. |
| | 803 | | /// </returns> |
| | 804 | | /// <remarks> |
| | 805 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 806 | | /// a failure occurs. |
| | 807 | | /// </remarks> |
| | 808 | | public virtual Response<BlobServiceProperties> GetProperties( |
| | 809 | | CancellationToken cancellationToken = default) => |
| 24 | 810 | | GetPropertiesInternal( |
| 24 | 811 | | false, //async |
| 24 | 812 | | cancellationToken) |
| 24 | 813 | | .EnsureCompleted(); |
| | 814 | |
|
| | 815 | | /// <summary> |
| | 816 | | /// The <see cref="GetPropertiesAsync"/> operation gets the properties |
| | 817 | | /// of a storage account’s blob service, including properties for |
| | 818 | | /// Storage Analytics and CORS (Cross-Origin Resource Sharing) rules. |
| | 819 | | /// |
| | 820 | | /// For more information, see |
| | 821 | | /// <see href="https://docs.microsoft.com/en-us/rest/api/storageservices/get-blob-service-properties"> |
| | 822 | | /// Get Blob Service Properties</see>. |
| | 823 | | /// </summary> |
| | 824 | | /// <param name="cancellationToken"> |
| | 825 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 826 | | /// notifications that the operation should be cancelled. |
| | 827 | | /// </param> |
| | 828 | | /// <returns> |
| | 829 | | /// A <see cref="Response{BlobServiceProperties}"/> describing |
| | 830 | | /// the service properties. |
| | 831 | | /// </returns> |
| | 832 | | /// <remarks> |
| | 833 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 834 | | /// a failure occurs. |
| | 835 | | /// </remarks> |
| | 836 | | public virtual async Task<Response<BlobServiceProperties>> GetPropertiesAsync( |
| | 837 | | CancellationToken cancellationToken = default) => |
| 24 | 838 | | await GetPropertiesInternal( |
| 24 | 839 | | true, //async |
| 24 | 840 | | cancellationToken) |
| 24 | 841 | | .ConfigureAwait(false); |
| | 842 | |
|
| | 843 | | /// <summary> |
| | 844 | | /// The <see cref="GetPropertiesInternal"/> operation gets the properties |
| | 845 | | /// of a storage account’s blob service, including properties for |
| | 846 | | /// Storage Analytics and CORS (Cross-Origin Resource Sharing) rules. |
| | 847 | | /// |
| | 848 | | /// For more information, see |
| | 849 | | /// <see href="https://docs.microsoft.com/en-us/rest/api/storageservices/get-blob-service-properties"> |
| | 850 | | /// Get Blob Service Properties</see>. |
| | 851 | | /// </summary> |
| | 852 | | /// <param name="async"> |
| | 853 | | /// Whether to invoke the operation asynchronously. |
| | 854 | | /// </param> |
| | 855 | | /// <param name="cancellationToken"> |
| | 856 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 857 | | /// notifications that the operation should be cancelled. |
| | 858 | | /// </param> |
| | 859 | | /// <returns> |
| | 860 | | /// A <see cref="Response{BlobServiceProperties}"/> describing |
| | 861 | | /// the service properties. |
| | 862 | | /// </returns> |
| | 863 | | /// <remarks> |
| | 864 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 865 | | /// a failure occurs. |
| | 866 | | /// </remarks> |
| | 867 | | private async Task<Response<BlobServiceProperties>> GetPropertiesInternal( |
| | 868 | | bool async, |
| | 869 | | CancellationToken cancellationToken) |
| | 870 | | { |
| 48 | 871 | | using (Pipeline.BeginLoggingScope(nameof(BlobServiceClient))) |
| | 872 | | { |
| | 873 | | Pipeline.LogMethodEnter(nameof(BlobServiceClient), message: $"{nameof(Uri)}: {Uri}"); |
| | 874 | | try |
| | 875 | | { |
| 48 | 876 | | return await BlobRestClient.Service.GetPropertiesAsync( |
| 48 | 877 | | ClientDiagnostics, |
| 48 | 878 | | Pipeline, |
| 48 | 879 | | Uri, |
| 48 | 880 | | version: Version.ToVersionString(), |
| 48 | 881 | | async: async, |
| 48 | 882 | | operationName: $"{nameof(BlobServiceClient)}.{nameof(GetProperties)}", |
| 48 | 883 | | cancellationToken: cancellationToken) |
| 48 | 884 | | .ConfigureAwait(false); |
| | 885 | | } |
| 4 | 886 | | catch (Exception ex) |
| | 887 | | { |
| | 888 | | Pipeline.LogException(ex); |
| 4 | 889 | | throw; |
| | 890 | | } |
| | 891 | | finally |
| | 892 | | { |
| | 893 | | Pipeline.LogMethodExit(nameof(BlobServiceClient)); |
| | 894 | | } |
| | 895 | | } |
| 44 | 896 | | } |
| | 897 | | #endregion GetProperties |
| | 898 | |
|
| | 899 | | #region SetProperties |
| | 900 | | /// <summary> |
| | 901 | | /// The <see cref="SetProperties"/> operation sets properties for |
| | 902 | | /// a storage account’s Blob service endpoint, including properties |
| | 903 | | /// for Storage Analytics, CORS (Cross-Origin Resource Sharing) rules |
| | 904 | | /// and soft delete settings. You can also use this operation to set |
| | 905 | | /// the default request version for all incoming requests to the Blob |
| | 906 | | /// service that do not have a version specified. |
| | 907 | | /// |
| | 908 | | /// For more information, see |
| | 909 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/set-blob-service-properties"> |
| | 910 | | /// Set Blob Service Properties</see>. |
| | 911 | | /// </summary> |
| | 912 | | /// <param name="properties">The blob service properties.</param> |
| | 913 | | /// <param name="cancellationToken"> |
| | 914 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 915 | | /// notifications that the operation should be cancelled. |
| | 916 | | /// </param> |
| | 917 | | /// <returns> |
| | 918 | | /// A <see cref="Response"/> describing |
| | 919 | | /// the service properties. |
| | 920 | | /// </returns> |
| | 921 | | /// <remarks> |
| | 922 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 923 | | /// a failure occurs. |
| | 924 | | /// </remarks> |
| | 925 | | public virtual Response SetProperties( |
| | 926 | | BlobServiceProperties properties, |
| | 927 | | CancellationToken cancellationToken = default) => |
| 14 | 928 | | SetPropertiesInternal( |
| 14 | 929 | | properties, |
| 14 | 930 | | false, // async |
| 14 | 931 | | cancellationToken) |
| 14 | 932 | | .EnsureCompleted(); |
| | 933 | |
|
| | 934 | | /// <summary> |
| | 935 | | /// The <see cref="SetPropertiesAsync"/> operation sets properties for |
| | 936 | | /// a storage account’s Blob service endpoint, including properties |
| | 937 | | /// for Storage Analytics, CORS (Cross-Origin Resource Sharing) rules |
| | 938 | | /// and soft delete settings. You can also use this operation to set |
| | 939 | | /// the default request version for all incoming requests to the Blob |
| | 940 | | /// service that do not have a version specified. |
| | 941 | | /// |
| | 942 | | /// For more information, see |
| | 943 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/set-blob-service-properties"> |
| | 944 | | /// Set Blob Service Properties</see>. |
| | 945 | | /// </summary> |
| | 946 | | /// <param name="properties">The blob service properties.</param> |
| | 947 | | /// <param name="cancellationToken"> |
| | 948 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 949 | | /// notifications that the operation should be cancelled. |
| | 950 | | /// </param> |
| | 951 | | /// <returns> |
| | 952 | | /// A <see cref="Response"/> describing |
| | 953 | | /// the service properties. |
| | 954 | | /// </returns> |
| | 955 | | /// <remarks> |
| | 956 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 957 | | /// a failure occurs. |
| | 958 | | /// </remarks> |
| | 959 | | public virtual async Task<Response> SetPropertiesAsync( |
| | 960 | | BlobServiceProperties properties, |
| | 961 | | CancellationToken cancellationToken = default) => |
| 14 | 962 | | await SetPropertiesInternal( |
| 14 | 963 | | properties, |
| 14 | 964 | | true, // async |
| 14 | 965 | | cancellationToken) |
| 14 | 966 | | .ConfigureAwait(false); |
| | 967 | |
|
| | 968 | | /// <summary> |
| | 969 | | /// The <see cref="SetPropertiesInternal"/> operation sets properties for |
| | 970 | | /// a storage account’s Blob service endpoint, including properties |
| | 971 | | /// for Storage Analytics, CORS (Cross-Origin Resource Sharing) rules |
| | 972 | | /// and soft delete settings. You can also use this operation to set |
| | 973 | | /// the default request version for all incoming requests to the Blob |
| | 974 | | /// service that do not have a version specified. |
| | 975 | | /// |
| | 976 | | /// For more information, see |
| | 977 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/set-blob-service-properties"> |
| | 978 | | /// Set Blob Service Properties</see>. |
| | 979 | | /// </summary> |
| | 980 | | /// <param name="properties">The blob service properties.</param> |
| | 981 | | /// <param name="async"> |
| | 982 | | /// Whether to invoke the operation asynchronously. |
| | 983 | | /// </param> |
| | 984 | | /// <param name="cancellationToken"> |
| | 985 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 986 | | /// notifications that the operation should be cancelled. |
| | 987 | | /// </param> |
| | 988 | | /// <returns> |
| | 989 | | /// A <see cref="Response"/> describing |
| | 990 | | /// the service properties. |
| | 991 | | /// </returns> |
| | 992 | | /// <remarks> |
| | 993 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 994 | | /// a failure occurs. |
| | 995 | | /// </remarks> |
| | 996 | | private async Task<Response> SetPropertiesInternal( |
| | 997 | | BlobServiceProperties properties, |
| | 998 | | bool async, |
| | 999 | | CancellationToken cancellationToken) |
| | 1000 | | { |
| 28 | 1001 | | using (Pipeline.BeginLoggingScope(nameof(BlobServiceClient))) |
| | 1002 | | { |
| | 1003 | | Pipeline.LogMethodEnter( |
| | 1004 | | nameof(BlobServiceClient), |
| | 1005 | | message: |
| | 1006 | | $"{nameof(Uri)}: {Uri}\n" + |
| | 1007 | | $"{nameof(properties)}: {properties}"); |
| | 1008 | | try |
| | 1009 | | { |
| 28 | 1010 | | return await BlobRestClient.Service.SetPropertiesAsync( |
| 28 | 1011 | | ClientDiagnostics, |
| 28 | 1012 | | Pipeline, |
| 28 | 1013 | | Uri, |
| 28 | 1014 | | properties, |
| 28 | 1015 | | version: Version.ToVersionString(), |
| 28 | 1016 | | async: async, |
| 28 | 1017 | | operationName: $"{nameof(BlobServiceClient)}.{nameof(SetProperties)}", |
| 28 | 1018 | | cancellationToken: cancellationToken) |
| 28 | 1019 | | .ConfigureAwait(false); |
| | 1020 | | } |
| 4 | 1021 | | catch (Exception ex) |
| | 1022 | | { |
| | 1023 | | Pipeline.LogException(ex); |
| 4 | 1024 | | throw; |
| | 1025 | | } |
| | 1026 | | finally |
| | 1027 | | { |
| | 1028 | | Pipeline.LogMethodExit(nameof(BlobServiceClient)); |
| | 1029 | | } |
| | 1030 | | } |
| 24 | 1031 | | } |
| | 1032 | | #endregion SetProperties |
| | 1033 | |
|
| | 1034 | | #region GetStatistics |
| | 1035 | | /// <summary> |
| | 1036 | | /// The <see cref="GetStatistics"/> operation retrieves |
| | 1037 | | /// statistics related to replication for the Blob service. It is |
| | 1038 | | /// only available on the secondary location endpoint when read-access |
| | 1039 | | /// geo-redundant replication (<see cref="Models.SkuName.StandardRagrs"/>) |
| | 1040 | | /// is enabled for the storage account. |
| | 1041 | | /// |
| | 1042 | | /// For more information, see |
| | 1043 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/get-blob-service-stats"> |
| | 1044 | | /// Get Blob Service Stats</see>. |
| | 1045 | | /// </summary> |
| | 1046 | | /// <param name="cancellationToken"> |
| | 1047 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1048 | | /// notifications that the operation should be cancelled. |
| | 1049 | | /// </param> |
| | 1050 | | /// <returns> |
| | 1051 | | /// A <see cref="Response{BlobServiceStatistics}"/> describing |
| | 1052 | | /// the service replication statistics. |
| | 1053 | | /// </returns> |
| | 1054 | | /// <remarks> |
| | 1055 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1056 | | /// a failure occurs. |
| | 1057 | | /// </remarks> |
| | 1058 | | public virtual Response<BlobServiceStatistics> GetStatistics( |
| | 1059 | | CancellationToken cancellationToken = default) => |
| 2 | 1060 | | GetStatisticsInternal( |
| 2 | 1061 | | false, // async |
| 2 | 1062 | | cancellationToken) |
| 2 | 1063 | | .EnsureCompleted(); |
| | 1064 | |
|
| | 1065 | | /// <summary> |
| | 1066 | | /// The <see cref="GetStatisticsAsync"/> operation retrieves |
| | 1067 | | /// statistics related to replication for the Blob service. It is |
| | 1068 | | /// only available on the secondary location endpoint when read-access |
| | 1069 | | /// geo-redundant replication (<see cref="Models.SkuName.StandardRagrs"/>) |
| | 1070 | | /// is enabled for the storage account. |
| | 1071 | | /// |
| | 1072 | | /// For more information, see |
| | 1073 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/get-blob-service-stats"> |
| | 1074 | | /// Get Blob Service Stats</see>. |
| | 1075 | | /// </summary> |
| | 1076 | | /// <param name="cancellationToken"> |
| | 1077 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1078 | | /// notifications that the operation should be cancelled. |
| | 1079 | | /// </param> |
| | 1080 | | /// <returns> |
| | 1081 | | /// A <see cref="Response{BlobServiceStatistics}"/> describing |
| | 1082 | | /// the service replication statistics. |
| | 1083 | | /// </returns> |
| | 1084 | | /// <remarks> |
| | 1085 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1086 | | /// a failure occurs. |
| | 1087 | | /// </remarks> |
| | 1088 | | public virtual async Task<Response<BlobServiceStatistics>> GetStatisticsAsync( |
| | 1089 | | CancellationToken cancellationToken = default) => |
| 2 | 1090 | | await GetStatisticsInternal( |
| 2 | 1091 | | true, // async |
| 2 | 1092 | | cancellationToken) |
| 2 | 1093 | | .ConfigureAwait(false); |
| | 1094 | |
|
| | 1095 | | /// <summary> |
| | 1096 | | /// The <see cref="GetStatisticsInternal"/> operation retrieves |
| | 1097 | | /// statistics related to replication for the Blob service. It is |
| | 1098 | | /// only available on the secondary location endpoint when read-access |
| | 1099 | | /// geo-redundant replication (<see cref="Models.SkuName.StandardRagrs"/>) |
| | 1100 | | /// is enabled for the storage account. |
| | 1101 | | /// |
| | 1102 | | /// For more information, see |
| | 1103 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/get-blob-service-stats"> |
| | 1104 | | /// Get Blob Service Stats</see>. |
| | 1105 | | /// </summary> |
| | 1106 | | /// <param name="async"> |
| | 1107 | | /// Whether to invoke the operation asynchronously. |
| | 1108 | | /// </param> |
| | 1109 | | /// <param name="cancellationToken"> |
| | 1110 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1111 | | /// notifications that the operation should be cancelled. |
| | 1112 | | /// </param> |
| | 1113 | | /// <returns> |
| | 1114 | | /// A <see cref="Response{BlobServiceStatistics}"/> describing |
| | 1115 | | /// the service replication statistics. |
| | 1116 | | /// </returns> |
| | 1117 | | /// <remarks> |
| | 1118 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1119 | | /// a failure occurs. |
| | 1120 | | /// </remarks> |
| | 1121 | | private async Task<Response<BlobServiceStatistics>> GetStatisticsInternal( |
| | 1122 | | bool async, |
| | 1123 | | CancellationToken cancellationToken) |
| | 1124 | | { |
| 4 | 1125 | | using (Pipeline.BeginLoggingScope(nameof(BlobServiceClient))) |
| | 1126 | | { |
| | 1127 | | Pipeline.LogMethodEnter(nameof(BlobServiceClient), message: $"{nameof(Uri)}: {Uri}"); |
| | 1128 | | try |
| | 1129 | | { |
| 4 | 1130 | | return await BlobRestClient.Service.GetStatisticsAsync( |
| 4 | 1131 | | ClientDiagnostics, |
| 4 | 1132 | | Pipeline, |
| 4 | 1133 | | Uri, |
| 4 | 1134 | | version: Version.ToVersionString(), |
| 4 | 1135 | | async: async, |
| 4 | 1136 | | operationName: $"{nameof(BlobServiceClient)}.{nameof(GetStatistics)}", |
| 4 | 1137 | | cancellationToken: cancellationToken) |
| 4 | 1138 | | .ConfigureAwait(false); |
| | 1139 | | } |
| 0 | 1140 | | catch (Exception ex) |
| | 1141 | | { |
| | 1142 | | Pipeline.LogException(ex); |
| 0 | 1143 | | throw; |
| | 1144 | | } |
| | 1145 | | finally |
| | 1146 | | { |
| | 1147 | | Pipeline.LogMethodExit(nameof(BlobServiceClient)); |
| | 1148 | | } |
| | 1149 | | } |
| 4 | 1150 | | } |
| | 1151 | | #endregion GetStatistics |
| | 1152 | |
|
| | 1153 | | #region GetUserDelegationKey |
| | 1154 | | /// <summary> |
| | 1155 | | /// The <see cref="GetUserDelegationKey"/> operation retrieves a |
| | 1156 | | /// key that can be used to delegate Active Directory authorization to |
| | 1157 | | /// shared access signatures created with <see cref="Sas.BlobSasBuilder"/>. |
| | 1158 | | /// </summary> |
| | 1159 | | /// <param name="startsOn"> |
| | 1160 | | /// Start time for the key's validity, with null indicating an |
| | 1161 | | /// immediate start. The time should be specified in UTC. |
| | 1162 | | /// </param> |
| | 1163 | | /// <param name="expiresOn"> |
| | 1164 | | /// Expiration of the key's validity. The time should be specified |
| | 1165 | | /// in UTC. |
| | 1166 | | /// </param> |
| | 1167 | | /// <param name="cancellationToken"> |
| | 1168 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1169 | | /// notifications that the operation should be cancelled. |
| | 1170 | | /// </param> |
| | 1171 | | /// <returns> |
| | 1172 | | /// A <see cref="Response{BlobServiceStatistics}"/> describing |
| | 1173 | | /// the service replication statistics. |
| | 1174 | | /// </returns> |
| | 1175 | | /// <remarks> |
| | 1176 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1177 | | /// a failure occurs. |
| | 1178 | | /// </remarks> |
| | 1179 | | public virtual Response<UserDelegationKey> GetUserDelegationKey( |
| | 1180 | | DateTimeOffset? startsOn, |
| | 1181 | | DateTimeOffset expiresOn, |
| | 1182 | | CancellationToken cancellationToken = default) => |
| 52 | 1183 | | GetUserDelegationKeyInternal( |
| 52 | 1184 | | startsOn, |
| 52 | 1185 | | expiresOn, |
| 52 | 1186 | | false, // async |
| 52 | 1187 | | cancellationToken) |
| 52 | 1188 | | .EnsureCompleted(); |
| | 1189 | |
|
| | 1190 | | /// <summary> |
| | 1191 | | /// The <see cref="GetUserDelegationKeyAsync"/> operation retrieves a |
| | 1192 | | /// key that can be used to delegate Active Directory authorization to |
| | 1193 | | /// shared access signatures created with <see cref="Sas.BlobSasBuilder"/>. |
| | 1194 | | /// </summary> |
| | 1195 | | /// <param name="startsOn"> |
| | 1196 | | /// Start time for the key's validity, with null indicating an |
| | 1197 | | /// immediate start. The time should be specified in UTC. |
| | 1198 | | /// </param> |
| | 1199 | | /// <param name="expiresOn"> |
| | 1200 | | /// Expiration of the key's validity. The time should be specified |
| | 1201 | | /// in UTC. |
| | 1202 | | /// </param> |
| | 1203 | | /// <param name="cancellationToken"> |
| | 1204 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1205 | | /// notifications that the operation should be cancelled. |
| | 1206 | | /// </param> |
| | 1207 | | /// <returns> |
| | 1208 | | /// A <see cref="Response{BlobServiceStatistics}"/> describing |
| | 1209 | | /// the service replication statistics. |
| | 1210 | | /// </returns> |
| | 1211 | | /// <remarks> |
| | 1212 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1213 | | /// a failure occurs. |
| | 1214 | | /// </remarks> |
| | 1215 | | public virtual async Task<Response<UserDelegationKey>> GetUserDelegationKeyAsync( |
| | 1216 | | DateTimeOffset? startsOn, |
| | 1217 | | DateTimeOffset expiresOn, |
| | 1218 | | CancellationToken cancellationToken = default) => |
| 52 | 1219 | | await GetUserDelegationKeyInternal( |
| 52 | 1220 | | startsOn, |
| 52 | 1221 | | expiresOn, |
| 52 | 1222 | | true, // async |
| 52 | 1223 | | cancellationToken) |
| 52 | 1224 | | .ConfigureAwait(false); |
| | 1225 | |
|
| | 1226 | | /// <summary> |
| | 1227 | | /// The <see cref="GetUserDelegationKeyInternal"/> operation retrieves a |
| | 1228 | | /// key that can be used to delegate Active Directory authorization to |
| | 1229 | | /// shared access signatures created with <see cref="Sas.BlobSasBuilder"/>. |
| | 1230 | | /// </summary> |
| | 1231 | | /// <param name="startsOn"> |
| | 1232 | | /// Start time for the key's validity, with null indicating an |
| | 1233 | | /// immediate start. The time should be specified in UTC. |
| | 1234 | | /// </param> |
| | 1235 | | /// <param name="expiresOn"> |
| | 1236 | | /// Expiration of the key's validity. The time should be specified |
| | 1237 | | /// in UTC. |
| | 1238 | | /// </param> |
| | 1239 | | /// <param name="cancellationToken"> |
| | 1240 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1241 | | /// notifications that the operation should be cancelled. |
| | 1242 | | /// </param> |
| | 1243 | | /// <param name="async"/> |
| | 1244 | | /// <returns> |
| | 1245 | | /// A <see cref="Response{BlobServiceStatistics}"/> describing |
| | 1246 | | /// the service replication statistics. |
| | 1247 | | /// </returns> |
| | 1248 | | /// <remarks> |
| | 1249 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1250 | | /// a failure occurs. |
| | 1251 | | /// </remarks> |
| | 1252 | | private async Task<Response<UserDelegationKey>> GetUserDelegationKeyInternal( |
| | 1253 | | DateTimeOffset? startsOn, |
| | 1254 | | DateTimeOffset expiresOn, |
| | 1255 | | bool async, |
| | 1256 | | CancellationToken cancellationToken) |
| | 1257 | | { |
| 104 | 1258 | | using (Pipeline.BeginLoggingScope(nameof(BlobServiceClient))) |
| | 1259 | | { |
| | 1260 | | Pipeline.LogMethodEnter(nameof(BlobServiceClient), message: $"{nameof(Uri)}: {Uri}"); |
| | 1261 | | try |
| | 1262 | | { |
| 104 | 1263 | | if (startsOn.HasValue && startsOn.Value.Offset != TimeSpan.Zero) |
| | 1264 | | { |
| 0 | 1265 | | throw BlobErrors.InvalidDateTimeUtc(nameof(startsOn)); |
| | 1266 | | } |
| | 1267 | |
|
| 104 | 1268 | | if (expiresOn.Offset != TimeSpan.Zero) |
| | 1269 | | { |
| 4 | 1270 | | throw BlobErrors.InvalidDateTimeUtc(nameof(expiresOn)); |
| | 1271 | | } |
| | 1272 | |
|
| 100 | 1273 | | var keyInfo = new KeyInfo { StartsOn = startsOn, ExpiresOn = expiresOn }; |
| | 1274 | |
|
| 100 | 1275 | | return await BlobRestClient.Service.GetUserDelegationKeyAsync( |
| 100 | 1276 | | ClientDiagnostics, |
| 100 | 1277 | | Pipeline, |
| 100 | 1278 | | Uri, |
| 100 | 1279 | | keyInfo: keyInfo, |
| 100 | 1280 | | version: Version.ToVersionString(), |
| 100 | 1281 | | async: async, |
| 100 | 1282 | | operationName: $"{nameof(BlobServiceClient)}.{nameof(GetUserDelegationKey)}", |
| 100 | 1283 | | cancellationToken: cancellationToken) |
| 100 | 1284 | | .ConfigureAwait(false); |
| | 1285 | | } |
| 12 | 1286 | | catch (Exception ex) |
| | 1287 | | { |
| | 1288 | | Pipeline.LogException(ex); |
| 12 | 1289 | | throw; |
| | 1290 | | } |
| | 1291 | | finally |
| | 1292 | | { |
| | 1293 | | Pipeline.LogMethodExit(nameof(BlobServiceClient)); |
| | 1294 | | } |
| | 1295 | | } |
| 92 | 1296 | | } |
| | 1297 | | #endregion GetUserDelegationKey |
| | 1298 | |
|
| | 1299 | | #region CreateBlobContainer |
| | 1300 | | /// <summary> |
| | 1301 | | /// The <see cref="CreateBlobContainer"/> operation creates a new |
| | 1302 | | /// blob container under the specified account. If the container with the |
| | 1303 | | /// same name already exists, the operation fails. |
| | 1304 | | /// |
| | 1305 | | /// For more information, see |
| | 1306 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/create-container"> |
| | 1307 | | /// Create Container</see>. |
| | 1308 | | /// </summary> |
| | 1309 | | /// <param name="blobContainerName"> |
| | 1310 | | /// The name of the container to create. |
| | 1311 | | /// </param> |
| | 1312 | | /// <param name="publicAccessType"> |
| | 1313 | | /// Optionally specifies whether data in the container may be accessed |
| | 1314 | | /// publicly and the level of access. <see cref="PublicAccessType.BlobContainer"/> |
| | 1315 | | /// specifies full public read access for container and blob data. |
| | 1316 | | /// Clients can enumerate blobs within the container via anonymous |
| | 1317 | | /// request, but cannot enumerate containers within the storage |
| | 1318 | | /// account. <see cref="PublicAccessType.Blob"/> specifies public |
| | 1319 | | /// read access for blobs. Blob data within this container can be |
| | 1320 | | /// read via anonymous request, but container data is not available. |
| | 1321 | | /// Clients cannot enumerate blobs within the container via anonymous |
| | 1322 | | /// request. <see cref="PublicAccessType.None"/> specifies that the |
| | 1323 | | /// container data is private to the account owner. |
| | 1324 | | /// </param> |
| | 1325 | | /// <param name="metadata"> |
| | 1326 | | /// Optional custom metadata to set for this container. |
| | 1327 | | /// </param> |
| | 1328 | | /// <param name="cancellationToken"> |
| | 1329 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1330 | | /// notifications that the operation should be cancelled. |
| | 1331 | | /// </param> |
| | 1332 | | /// <returns> |
| | 1333 | | /// A <see cref="Response{BlobContainerClient}"/> referencing the |
| | 1334 | | /// newly created container. |
| | 1335 | | /// </returns> |
| | 1336 | | /// <remarks> |
| | 1337 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1338 | | /// a failure occurs. |
| | 1339 | | /// </remarks> |
| | 1340 | | [ForwardsClientCalls] |
| | 1341 | | public virtual Response<BlobContainerClient> CreateBlobContainer( |
| | 1342 | | string blobContainerName, |
| | 1343 | | PublicAccessType publicAccessType = PublicAccessType.None, |
| | 1344 | | Metadata metadata = default, |
| | 1345 | | CancellationToken cancellationToken = default) |
| | 1346 | | { |
| 6 | 1347 | | BlobContainerClient container = GetBlobContainerClient(blobContainerName); |
| 6 | 1348 | | Response<BlobContainerInfo> response = container.Create(publicAccessType, metadata, cancellationToken); |
| 6 | 1349 | | return Response.FromValue(container, response.GetRawResponse()); |
| | 1350 | | } |
| | 1351 | |
|
| | 1352 | | /// <summary> |
| | 1353 | | /// The <see cref="CreateBlobContainerAsync"/> operation creates a new |
| | 1354 | | /// blob container under the specified account. If the container with the |
| | 1355 | | /// same name already exists, the operation fails. |
| | 1356 | | /// |
| | 1357 | | /// For more information, see |
| | 1358 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/create-container"> |
| | 1359 | | /// Create Container</see>. |
| | 1360 | | /// </summary> |
| | 1361 | | /// <param name="blobContainerName"> |
| | 1362 | | /// The name of the container to create. |
| | 1363 | | /// </param> |
| | 1364 | | /// <param name="publicAccessType"> |
| | 1365 | | /// Optionally specifies whether data in the container may be accessed |
| | 1366 | | /// publicly and the level of access. <see cref="PublicAccessType.BlobContainer"/> |
| | 1367 | | /// specifies full public read access for container and blob data. |
| | 1368 | | /// Clients can enumerate blobs within the container via anonymous |
| | 1369 | | /// request, but cannot enumerate containers within the storage |
| | 1370 | | /// account. <see cref="PublicAccessType.Blob"/> specifies public |
| | 1371 | | /// read access for blobs. Blob data within this container can be |
| | 1372 | | /// read via anonymous request, but container data is not available. |
| | 1373 | | /// Clients cannot enumerate blobs within the container via anonymous |
| | 1374 | | /// request. <see cref="PublicAccessType.None"/> specifies that the |
| | 1375 | | /// container data is private to the account owner. |
| | 1376 | | /// </param> |
| | 1377 | | /// <param name="metadata"> |
| | 1378 | | /// Optional custom metadata to set for this container. |
| | 1379 | | /// </param> |
| | 1380 | | /// <param name="cancellationToken"> |
| | 1381 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1382 | | /// notifications that the operation should be cancelled. |
| | 1383 | | /// </param> |
| | 1384 | | /// <returns> |
| | 1385 | | /// A <see cref="Response{BlobContainerClient}"/> referencing the |
| | 1386 | | /// newly created container. |
| | 1387 | | /// </returns> |
| | 1388 | | /// <remarks> |
| | 1389 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1390 | | /// a failure occurs. |
| | 1391 | | /// </remarks> |
| | 1392 | | [ForwardsClientCalls] |
| | 1393 | | public virtual async Task<Response<BlobContainerClient>> CreateBlobContainerAsync( |
| | 1394 | | string blobContainerName, |
| | 1395 | | PublicAccessType publicAccessType = PublicAccessType.None, |
| | 1396 | | Metadata metadata = default, |
| | 1397 | | CancellationToken cancellationToken = default) |
| | 1398 | | { |
| 6 | 1399 | | BlobContainerClient container = GetBlobContainerClient(blobContainerName); |
| 6 | 1400 | | Response<BlobContainerInfo> response = await container.CreateAsync(publicAccessType, metadata, cancellationT |
| 6 | 1401 | | return Response.FromValue(container, response.GetRawResponse()); |
| 6 | 1402 | | } |
| | 1403 | | #endregion CreateBlobContainer |
| | 1404 | |
|
| | 1405 | | #region DeleteBlobContainer |
| | 1406 | | /// <summary> |
| | 1407 | | /// The <see cref="DeleteBlobContainer"/> operation marks the |
| | 1408 | | /// specified blob container for deletion. The container and any blobs |
| | 1409 | | /// contained within it are later deleted during garbage collection. |
| | 1410 | | /// |
| | 1411 | | /// For more information, see |
| | 1412 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/delete-container"> |
| | 1413 | | /// Delete Container</see>. |
| | 1414 | | /// </summary> |
| | 1415 | | /// <param name="blobContainerName"> |
| | 1416 | | /// The name of the container to delete. |
| | 1417 | | /// </param> |
| | 1418 | | /// <param name="conditions"> |
| | 1419 | | /// Optional <see cref="BlobRequestConditions"/> to add |
| | 1420 | | /// conditions on the deletion of this container. |
| | 1421 | | /// </param> |
| | 1422 | | /// <param name="cancellationToken"> |
| | 1423 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1424 | | /// notifications that the operation should be cancelled. |
| | 1425 | | /// </param> |
| | 1426 | | /// <returns> |
| | 1427 | | /// A <see cref="Response"/> if successful. |
| | 1428 | | /// </returns> |
| | 1429 | | /// <remarks> |
| | 1430 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1431 | | /// a failure occurs. |
| | 1432 | | /// </remarks> |
| | 1433 | | [ForwardsClientCalls] |
| | 1434 | | public virtual Response DeleteBlobContainer( |
| | 1435 | | string blobContainerName, |
| | 1436 | | BlobRequestConditions conditions = default, |
| | 1437 | | CancellationToken cancellationToken = default) => |
| 4 | 1438 | | GetBlobContainerClient(blobContainerName) |
| 4 | 1439 | | .Delete( |
| 4 | 1440 | | conditions, |
| 4 | 1441 | | cancellationToken); |
| | 1442 | |
|
| | 1443 | | /// <summary> |
| | 1444 | | /// The <see cref="DeleteBlobContainerAsync"/> operation marks the |
| | 1445 | | /// specified container for deletion. The container and any blobs |
| | 1446 | | /// contained within it are later deleted during garbage collection. |
| | 1447 | | /// |
| | 1448 | | /// For more information, see |
| | 1449 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/delete-container"> |
| | 1450 | | /// Delete Container</see>. |
| | 1451 | | /// </summary> |
| | 1452 | | /// <param name="blobContainerName"> |
| | 1453 | | /// The name of the blob container to delete. |
| | 1454 | | /// </param> |
| | 1455 | | /// <param name="conditions"> |
| | 1456 | | /// Optional <see cref="BlobRequestConditions"/> to add |
| | 1457 | | /// conditions on the deletion of this blob container. |
| | 1458 | | /// </param> |
| | 1459 | | /// <param name="cancellationToken"> |
| | 1460 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1461 | | /// notifications that the operation should be cancelled. |
| | 1462 | | /// </param> |
| | 1463 | | /// <returns> |
| | 1464 | | /// A <see cref="Response"/> if successful. |
| | 1465 | | /// </returns> |
| | 1466 | | /// <remarks> |
| | 1467 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1468 | | /// a failure occurs. |
| | 1469 | | /// </remarks> |
| | 1470 | | [ForwardsClientCalls] |
| | 1471 | | public virtual async Task<Response> DeleteBlobContainerAsync( |
| | 1472 | | string blobContainerName, |
| | 1473 | | BlobRequestConditions conditions = default, |
| | 1474 | | CancellationToken cancellationToken = default) => |
| 4 | 1475 | | await |
| 4 | 1476 | | GetBlobContainerClient(blobContainerName) |
| 4 | 1477 | | .DeleteAsync( |
| 4 | 1478 | | conditions, |
| 4 | 1479 | | cancellationToken) |
| 4 | 1480 | | .ConfigureAwait(false); |
| | 1481 | | #endregion DeleteBlobContainer |
| | 1482 | |
|
| | 1483 | | #region UndeleteBlobContainer |
| | 1484 | | /// <summary> |
| | 1485 | | /// Restores a previously deleted container. |
| | 1486 | | /// This API is only functional is Container Soft Delete is enabled |
| | 1487 | | /// for the storage account associated with the container. |
| | 1488 | | /// </summary> |
| | 1489 | | /// <param name="deletedContainerName"> |
| | 1490 | | /// The name of the previously deleted container. |
| | 1491 | | /// </param> |
| | 1492 | | /// <param name="deletedContainerVersion"> |
| | 1493 | | /// The version of the previously deleted container. |
| | 1494 | | /// </param> |
| | 1495 | | /// <param name="destinationContainerName"> |
| | 1496 | | /// Optional. Use this parameter if you would like to restore the container |
| | 1497 | | /// under a different name. |
| | 1498 | | /// </param> |
| | 1499 | | /// <param name="cancellationToken"> |
| | 1500 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1501 | | /// notifications that the operation should be cancelled. |
| | 1502 | | /// </param> |
| | 1503 | | /// <returns> |
| | 1504 | | /// A <see cref="Response{BlobContainerClient}"/> pointed at the undeleted container. |
| | 1505 | | /// </returns> |
| | 1506 | | /// <remarks> |
| | 1507 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1508 | | /// a failure occurs. |
| | 1509 | | /// </remarks> |
| | 1510 | | internal virtual Response<BlobContainerClient> UndeleteBlobContainer( |
| | 1511 | | string deletedContainerName, |
| | 1512 | | string deletedContainerVersion, |
| | 1513 | | string destinationContainerName = default, |
| | 1514 | | CancellationToken cancellationToken = default) |
| 0 | 1515 | | => UndeleteBlobContainerInternal( |
| 0 | 1516 | | deletedContainerName, |
| 0 | 1517 | | deletedContainerVersion, |
| 0 | 1518 | | destinationContainerName, |
| 0 | 1519 | | async: false, |
| 0 | 1520 | | cancellationToken) |
| 0 | 1521 | | .EnsureCompleted(); |
| | 1522 | |
|
| | 1523 | | /// <summary> |
| | 1524 | | /// Restores a previously deleted container. |
| | 1525 | | /// This API is only functional is Container Soft Delete is enabled |
| | 1526 | | /// for the storage account associated with the container. |
| | 1527 | | /// </summary> |
| | 1528 | | /// <param name="deletedContainerName"> |
| | 1529 | | /// The name of the previously deleted container. |
| | 1530 | | /// </param> |
| | 1531 | | /// <param name="deletedContainerVersion"> |
| | 1532 | | /// The version of the previously deleted container. |
| | 1533 | | /// </param> |
| | 1534 | | /// <param name="destinationContainerName"> |
| | 1535 | | /// Optional. Use this parameter if you would like to restore the container |
| | 1536 | | /// under a different name. |
| | 1537 | | /// </param> |
| | 1538 | | /// <param name="cancellationToken"> |
| | 1539 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1540 | | /// notifications that the operation should be cancelled. |
| | 1541 | | /// </param> |
| | 1542 | | /// <returns> |
| | 1543 | | /// A <see cref="Response{BlobContainerClient}"/> pointed at the undeleted container. |
| | 1544 | | /// </returns> |
| | 1545 | | /// <remarks> |
| | 1546 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1547 | | /// a failure occurs. |
| | 1548 | | /// </remarks> |
| | 1549 | | internal virtual async Task<Response<BlobContainerClient>> UndeleteBlobContainerAsync( |
| | 1550 | | string deletedContainerName, |
| | 1551 | | string deletedContainerVersion, |
| | 1552 | | string destinationContainerName = default, |
| | 1553 | | CancellationToken cancellationToken = default) |
| 0 | 1554 | | => await UndeleteBlobContainerInternal( |
| 0 | 1555 | | deletedContainerName, |
| 0 | 1556 | | deletedContainerVersion, |
| 0 | 1557 | | destinationContainerName, |
| 0 | 1558 | | async: true, |
| 0 | 1559 | | cancellationToken) |
| 0 | 1560 | | .ConfigureAwait(false); |
| | 1561 | |
|
| | 1562 | | /// <summary> |
| | 1563 | | /// Restores a previously deleted container. |
| | 1564 | | /// This API is only functional is Container Soft Delete is enabled |
| | 1565 | | /// for the storage account associated with the container. |
| | 1566 | | /// </summary> |
| | 1567 | | /// <param name="deletedContainerName"> |
| | 1568 | | /// The name of the previously deleted container. |
| | 1569 | | /// </param> |
| | 1570 | | /// <param name="deletedContainerVersion"> |
| | 1571 | | /// The version of the previously deleted container. |
| | 1572 | | /// </param> |
| | 1573 | | /// <param name="destinationContainerName"> |
| | 1574 | | /// Optional. Use this parameter if you would like to restore the container |
| | 1575 | | /// under a different name. |
| | 1576 | | /// </param> |
| | 1577 | | /// <param name="async"> |
| | 1578 | | /// Whether to invoke the operation asynchronously. |
| | 1579 | | /// </param> |
| | 1580 | | /// <param name="cancellationToken"> |
| | 1581 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1582 | | /// notifications that the operation should be cancelled. |
| | 1583 | | /// </param> |
| | 1584 | | /// <returns> |
| | 1585 | | /// A <see cref="Response{BlobContainerClient}"/> pointed at the undeleted container. |
| | 1586 | | /// </returns> |
| | 1587 | | /// <remarks> |
| | 1588 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1589 | | /// a failure occurs. |
| | 1590 | | /// </remarks> |
| | 1591 | | internal async Task<Response<BlobContainerClient>> UndeleteBlobContainerInternal( |
| | 1592 | | string deletedContainerName, |
| | 1593 | | string deletedContainerVersion, |
| | 1594 | | string destinationContainerName, |
| | 1595 | | bool async, |
| | 1596 | | CancellationToken cancellationToken) |
| | 1597 | | { |
| 0 | 1598 | | using (Pipeline.BeginLoggingScope(nameof(BlobContainerClient))) |
| | 1599 | | { |
| | 1600 | | Pipeline.LogMethodEnter( |
| | 1601 | | nameof(BlobContainerClient), |
| | 1602 | | message: |
| | 1603 | | $"{nameof(Uri)}: {Uri}\n" + |
| | 1604 | | $"{nameof(deletedContainerName)}: {deletedContainerName}\n" + |
| | 1605 | | $"{nameof(deletedContainerVersion)}: {deletedContainerVersion}"); |
| | 1606 | |
|
| | 1607 | | try |
| | 1608 | | { |
| | 1609 | | BlobContainerClient containerClient; |
| 0 | 1610 | | if (destinationContainerName != null) |
| | 1611 | | { |
| 0 | 1612 | | containerClient = GetBlobContainerClient(destinationContainerName); |
| | 1613 | | } |
| | 1614 | | else |
| | 1615 | | { |
| 0 | 1616 | | containerClient = GetBlobContainerClient(deletedContainerName); |
| | 1617 | | } |
| | 1618 | |
|
| 0 | 1619 | | Response response = await BlobRestClient.Container.RestoreAsync( |
| 0 | 1620 | | ClientDiagnostics, |
| 0 | 1621 | | Pipeline, |
| 0 | 1622 | | containerClient.Uri, |
| 0 | 1623 | | Version.ToVersionString(), |
| 0 | 1624 | | deletedContainerName: deletedContainerName, |
| 0 | 1625 | | deletedContainerVersion: deletedContainerVersion, |
| 0 | 1626 | | async: async, |
| 0 | 1627 | | operationName: $"{nameof(BlobServiceClient)}.{nameof(UndeleteBlobContainer)}", |
| 0 | 1628 | | cancellationToken: cancellationToken) |
| 0 | 1629 | | .ConfigureAwait(false); |
| | 1630 | |
|
| 0 | 1631 | | return Response.FromValue(containerClient, response); |
| | 1632 | | } |
| 0 | 1633 | | catch (Exception ex) |
| | 1634 | | { |
| | 1635 | | Pipeline.LogException(ex); |
| 0 | 1636 | | throw; |
| | 1637 | | } |
| | 1638 | | finally |
| | 1639 | | { |
| | 1640 | | Pipeline.LogMethodExit(nameof(BlobContainerClient)); |
| | 1641 | | } |
| | 1642 | | } |
| 0 | 1643 | | } |
| | 1644 | | #endregion UndeleteBlobContainer |
| | 1645 | |
|
| | 1646 | | #region FilterBlobs |
| | 1647 | | /// <summary> |
| | 1648 | | /// The Filter Blobs operation enables callers to list blobs across all containers whose tags |
| | 1649 | | /// match a given search expression. Filter blobs searches across all containers within a |
| | 1650 | | /// storage account but can be scoped within the expression to a single container. |
| | 1651 | | /// |
| | 1652 | | /// For more information, see |
| | 1653 | | /// <see href="https://docs.microsoft.com/en-us/rest/api/storageservices/find-blobs-by-tags"> |
| | 1654 | | /// Find Blobs by Tags</see>. |
| | 1655 | | /// </summary> |
| | 1656 | | /// <param name="tagFilterSqlExpression"> |
| | 1657 | | /// The where parameter enables the caller to query blobs whose tags match a given expression. |
| | 1658 | | /// The given expression must evaluate to true for a blob to be returned in the results. |
| | 1659 | | /// The[OData - ABNF] filter syntax rule defines the formal grammar for the value of the where query parameter; |
| | 1660 | | /// however, only a subset of the OData filter syntax is supported in the Blob service. |
| | 1661 | | /// </param> |
| | 1662 | | /// <param name="cancellationToken"> |
| | 1663 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1664 | | /// notifications that the operation should be cancelled. |
| | 1665 | | /// </param> |
| | 1666 | | /// <returns> |
| | 1667 | | /// An <see cref="AsyncPageable{T}"/> describing the blobs. |
| | 1668 | | /// </returns> |
| | 1669 | | /// <remarks> |
| | 1670 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1671 | | /// a failure occurs. |
| | 1672 | | /// </remarks> |
| | 1673 | | public virtual Pageable<TaggedBlobItem> FindBlobsByTags( |
| | 1674 | | string tagFilterSqlExpression, |
| | 1675 | | CancellationToken cancellationToken = default) => |
| 4 | 1676 | | new FilterBlobsAsyncCollection(this, tagFilterSqlExpression).ToSyncCollection(cancellationToken); |
| | 1677 | |
|
| | 1678 | | /// <summary> |
| | 1679 | | /// The Filter Blobs operation enables callers to list blobs across all containers whose tags |
| | 1680 | | /// match a given search expression. Filter blobs searches across all containers within a |
| | 1681 | | /// storage account but can be scoped within the expression to a single container. |
| | 1682 | | /// |
| | 1683 | | /// For more information, see |
| | 1684 | | /// <see href="https://docs.microsoft.com/en-us/rest/api/storageservices/find-blobs-by-tags"> |
| | 1685 | | /// Find Blobs by Tags</see>. |
| | 1686 | | /// </summary> |
| | 1687 | | /// <param name="tagFilterSqlExpression"> |
| | 1688 | | /// The where parameter enables the caller to query blobs whose tags match a given expression. |
| | 1689 | | /// The given expression must evaluate to true for a blob to be returned in the results. |
| | 1690 | | /// The[OData - ABNF] filter syntax rule defines the formal grammar for the value of the where query parameter; |
| | 1691 | | /// however, only a subset of the OData filter syntax is supported in the Blob service. |
| | 1692 | | /// </param> |
| | 1693 | | /// <param name="cancellationToken"> |
| | 1694 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1695 | | /// notifications that the operation should be cancelled. |
| | 1696 | | /// </param> |
| | 1697 | | /// <returns> |
| | 1698 | | /// An <see cref="AsyncPageable{T}"/> describing the blobs. |
| | 1699 | | /// </returns> |
| | 1700 | | /// <remarks> |
| | 1701 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1702 | | /// a failure occurs. |
| | 1703 | | /// </remarks> |
| | 1704 | | public virtual AsyncPageable<TaggedBlobItem> FindBlobsByTagsAsync( |
| | 1705 | | string tagFilterSqlExpression, |
| | 1706 | | CancellationToken cancellationToken = default) => |
| 12 | 1707 | | new FilterBlobsAsyncCollection(this, tagFilterSqlExpression).ToAsyncCollection(cancellationToken); |
| | 1708 | |
|
| | 1709 | | internal async Task<Response<FilterBlobSegment>> FindBlobsByTagsInternal( |
| | 1710 | | string marker, |
| | 1711 | | string expression, |
| | 1712 | | int? pageSizeHint, |
| | 1713 | | bool async, |
| | 1714 | | CancellationToken cancellationToken) |
| | 1715 | | { |
| 16 | 1716 | | using (Pipeline.BeginLoggingScope(nameof(BlobServiceClient))) |
| | 1717 | | { |
| | 1718 | | Pipeline.LogMethodEnter( |
| | 1719 | | nameof(BlobServiceClient), |
| | 1720 | | message: |
| | 1721 | | $"{nameof(Uri)}: {Uri}\n" + |
| | 1722 | | $"{nameof(expression)}: {expression}"); |
| | 1723 | |
|
| | 1724 | | try |
| | 1725 | | { |
| 16 | 1726 | | return await BlobRestClient.Service.FilterBlobsAsync( |
| 16 | 1727 | | clientDiagnostics: ClientDiagnostics, |
| 16 | 1728 | | pipeline: Pipeline, |
| 16 | 1729 | | resourceUri: Uri, |
| 16 | 1730 | | version: Version.ToVersionString(), |
| 16 | 1731 | | where: expression, |
| 16 | 1732 | | marker: marker, |
| 16 | 1733 | | maxresults: pageSizeHint, |
| 16 | 1734 | | async: async, |
| 16 | 1735 | | cancellationToken: cancellationToken) |
| 16 | 1736 | | .ConfigureAwait(false); |
| | 1737 | | } |
| 4 | 1738 | | catch (Exception ex) |
| | 1739 | | { |
| | 1740 | | Pipeline.LogException(ex); |
| 4 | 1741 | | throw; |
| | 1742 | | } |
| | 1743 | | finally |
| | 1744 | | { |
| | 1745 | | Pipeline.LogMethodExit(nameof(BlobServiceClient)); |
| | 1746 | | } |
| | 1747 | | } |
| 12 | 1748 | | } |
| | 1749 | | #endregion FilterBlobs |
| | 1750 | | } |
| | 1751 | | } |