| | 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.Text; |
| | 7 | | using System.Threading; |
| | 8 | | using System.Threading.Tasks; |
| | 9 | | using Azure.Core; |
| | 10 | | using Azure.Core.Pipeline; |
| | 11 | | using Azure.Storage.Blobs; |
| | 12 | | using Azure.Storage.Files.DataLake.Models; |
| | 13 | | using Metadata = System.Collections.Generic.IDictionary<string, string>; |
| | 14 | |
|
| | 15 | | namespace Azure.Storage.Files.DataLake |
| | 16 | | { |
| | 17 | | /// <summary> |
| | 18 | | /// The <see cref="DataLakeServiceClient"/> allows you to manipulate Azure |
| | 19 | | /// Data Lake service resources and file systems. The storage account provides |
| | 20 | | /// the top-level namespace for the Data Lake service. |
| | 21 | | /// </summary> |
| | 22 | | public class DataLakeServiceClient |
| | 23 | | { |
| | 24 | | /// <summary> |
| | 25 | | /// The <see cref="BlobServiceClient"/> associated with the file system. |
| | 26 | | /// </summary> |
| | 27 | | private readonly BlobServiceClient _blobServiceClient; |
| | 28 | |
|
| | 29 | | /// <summary> |
| | 30 | | /// The Data Lake service's customer-provided <see cref="Uri"/> endpoint. |
| | 31 | | /// </summary> |
| | 32 | | private readonly Uri _uri; |
| | 33 | |
|
| | 34 | | /// <summary> |
| | 35 | | /// The Data Lake service's blob <see cref="Uri"/> endpoint. |
| | 36 | | /// </summary> |
| | 37 | | private readonly Uri _blobUri; |
| | 38 | |
|
| | 39 | | /// <summary> |
| | 40 | | /// Gets the Data Lake service's primary <see cref="Uri"/> endpoint. |
| | 41 | | /// </summary> |
| 2962 | 42 | | public virtual Uri Uri => _uri; |
| | 43 | |
|
| | 44 | | /// <summary> |
| | 45 | | /// The <see cref="HttpPipeline"/> transport pipeline used to send |
| | 46 | | /// every request. |
| | 47 | | /// </summary> |
| | 48 | | private readonly HttpPipeline _pipeline; |
| | 49 | |
|
| | 50 | | /// <summary> |
| | 51 | | /// Gets tghe <see cref="HttpPipeline"/> transport pipeline used to |
| | 52 | | /// send every request. |
| | 53 | | /// </summary> |
| 2926 | 54 | | internal virtual HttpPipeline Pipeline => _pipeline; |
| | 55 | |
|
| | 56 | | /// <summary> |
| | 57 | | /// The version of the service to use when sending requests. |
| | 58 | | /// </summary> |
| | 59 | | private readonly DataLakeClientOptions.ServiceVersion _version; |
| | 60 | |
|
| | 61 | | /// <summary> |
| | 62 | | /// The version of the service to use when sending requests. |
| | 63 | | /// </summary> |
| 5844 | 64 | | internal virtual DataLakeClientOptions.ServiceVersion Version => _version; |
| | 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> |
| 3006 | 76 | | internal virtual ClientDiagnostics ClientDiagnostics => _clientDiagnostics; |
| | 77 | |
|
| | 78 | | /// <summary> |
| | 79 | | /// The Storage account name corresponding to the file service client. |
| | 80 | | /// </summary> |
| | 81 | | private string _accountName; |
| | 82 | |
|
| | 83 | | /// <summary> |
| | 84 | | /// Gets the Storage account name corresponding to the file service client. |
| | 85 | | /// </summary> |
| | 86 | | public virtual string AccountName |
| | 87 | | { |
| | 88 | | get |
| | 89 | | { |
| 8 | 90 | | if (_accountName == null) |
| | 91 | | { |
| 4 | 92 | | _accountName = new DataLakeUriBuilder(Uri).AccountName; |
| | 93 | | } |
| 8 | 94 | | return _accountName; |
| | 95 | | } |
| | 96 | | } |
| | 97 | |
|
| | 98 | | #region ctors |
| | 99 | | /// <summary> |
| | 100 | | /// Initializes a new instance of the <see cref="DataLakeServiceClient"/> |
| | 101 | | /// class for mocking. |
| | 102 | | /// </summary> |
| 2910 | 103 | | protected DataLakeServiceClient() |
| | 104 | | { |
| 2910 | 105 | | } |
| | 106 | |
|
| | 107 | | /// <summary> |
| | 108 | | /// Initializes a new instance of the <see cref="DataLakeServiceClient"/> |
| | 109 | | /// class. |
| | 110 | | /// </summary> |
| | 111 | | /// <param name="serviceUri"> |
| | 112 | | /// A <see cref="Uri"/> referencing the Data Lake service. |
| | 113 | | /// </param> |
| | 114 | | public DataLakeServiceClient(Uri serviceUri) |
| 0 | 115 | | : this(serviceUri, (HttpPipelinePolicy)null, null) |
| | 116 | | { |
| 0 | 117 | | } |
| | 118 | |
|
| | 119 | | /// <summary> |
| | 120 | | /// Initializes a new instance of the <see cref="DataLakeServiceClient"/> |
| | 121 | | /// class. |
| | 122 | | /// </summary> |
| | 123 | | /// <param name="serviceUri"> |
| | 124 | | /// A <see cref="Uri"/> referencing the Data Lake service. |
| | 125 | | /// </param> |
| | 126 | | /// <param name="options"> |
| | 127 | | /// Optional client options that define the transport pipeline |
| | 128 | | /// policies for authentication, retries, etc., that are applied to |
| | 129 | | /// every request. |
| | 130 | | /// </param> |
| | 131 | | public DataLakeServiceClient(Uri serviceUri, DataLakeClientOptions options) |
| 80 | 132 | | : this(serviceUri, (HttpPipelinePolicy)null, options) |
| | 133 | | { |
| 80 | 134 | | } |
| | 135 | |
|
| | 136 | | /// <summary> |
| | 137 | | /// Initializes a new instance of the <see cref="DataLakeServiceClient"/> |
| | 138 | | /// class. |
| | 139 | | /// </summary> |
| | 140 | | /// <param name="serviceUri"> |
| | 141 | | /// A <see cref="Uri"/> referencing the Data Lake service. |
| | 142 | | /// </param> |
| | 143 | | /// <param name="credential"> |
| | 144 | | /// The shared key credential used to sign requests. |
| | 145 | | /// </param> |
| | 146 | | public DataLakeServiceClient(Uri serviceUri, StorageSharedKeyCredential credential) |
| 0 | 147 | | : this(serviceUri, credential.AsPolicy(), null) |
| | 148 | | { |
| 0 | 149 | | } |
| | 150 | |
|
| | 151 | | /// <summary> |
| | 152 | | /// Initializes a new instance of the <see cref="DataLakeServiceClient"/> |
| | 153 | | /// class. |
| | 154 | | /// </summary> |
| | 155 | | /// <param name="serviceUri"> |
| | 156 | | /// A <see cref="Uri"/> referencing the Data Lake service. |
| | 157 | | /// </param> |
| | 158 | | /// <param name="credential"> |
| | 159 | | /// The shared key credential used to sign requests. |
| | 160 | | /// </param> |
| | 161 | | /// <param name="options"> |
| | 162 | | /// Optional client options that define the transport pipeline |
| | 163 | | /// policies for authentication, retries, etc., that are applied to |
| | 164 | | /// every request. |
| | 165 | | /// </param> |
| | 166 | | public DataLakeServiceClient(Uri serviceUri, StorageSharedKeyCredential credential, DataLakeClientOptions option |
| 2770 | 167 | | : this(serviceUri, credential.AsPolicy(), options) |
| | 168 | | { |
| 2770 | 169 | | } |
| | 170 | |
|
| | 171 | | /// <summary> |
| | 172 | | /// Initializes a new instance of the <see cref="DataLakeServiceClient"/> |
| | 173 | | /// class. |
| | 174 | | /// </summary> |
| | 175 | | /// <param name="serviceUri"> |
| | 176 | | /// A <see cref="Uri"/> referencing the Data Lake service. |
| | 177 | | /// </param> |
| | 178 | | /// <param name="credential"> |
| | 179 | | /// The token credential used to sign requests. |
| | 180 | | /// </param> |
| | 181 | | public DataLakeServiceClient(Uri serviceUri, TokenCredential credential) |
| 4 | 182 | | : this(serviceUri, credential.AsPolicy(), null) |
| | 183 | | { |
| 4 | 184 | | Errors.VerifyHttpsTokenAuth(serviceUri); |
| 0 | 185 | | } |
| | 186 | |
|
| | 187 | | /// <summary> |
| | 188 | | /// Initializes a new instance of the <see cref="DataLakeServiceClient"/> |
| | 189 | | /// class. |
| | 190 | | /// </summary> |
| | 191 | | /// <param name="serviceUri"> |
| | 192 | | /// A <see cref="Uri"/> referencing the Data Lake service. |
| | 193 | | /// </param> |
| | 194 | | /// <param name="credential"> |
| | 195 | | /// The token credential used to sign requests. |
| | 196 | | /// </param> |
| | 197 | | /// <param name="options"> |
| | 198 | | /// Optional client options that define the transport pipeline |
| | 199 | | /// policies for authentication, retries, etc., that are applied to |
| | 200 | | /// every request. |
| | 201 | | /// </param> |
| | 202 | | public DataLakeServiceClient(Uri serviceUri, TokenCredential credential, DataLakeClientOptions options) |
| 64 | 203 | | : this(serviceUri, credential.AsPolicy(), options) |
| | 204 | | { |
| 64 | 205 | | Errors.VerifyHttpsTokenAuth(serviceUri); |
| 60 | 206 | | } |
| | 207 | |
|
| | 208 | | /// <summary> |
| | 209 | | /// Initializes a new instance of the <see cref="DataLakeServiceClient"/> |
| | 210 | | /// class. |
| | 211 | | /// </summary> |
| | 212 | | /// <param name="serviceUri"> |
| | 213 | | /// A <see cref="Uri"/> referencing the Data Lake service |
| | 214 | | /// </param> |
| | 215 | | /// <param name="authentication"> |
| | 216 | | /// An optional authentication policy used to sign requests. |
| | 217 | | /// </param> |
| | 218 | | /// <param name="options"> |
| | 219 | | /// Optional client options that define the transport pipeline |
| | 220 | | /// policies for authentication, retries, etc., that are applied to |
| | 221 | | /// every request. |
| | 222 | | /// </param> |
| | 223 | | internal DataLakeServiceClient(Uri serviceUri, HttpPipelinePolicy authentication, DataLakeClientOptions options) |
| 2918 | 224 | | : this(serviceUri, authentication, options, null) |
| | 225 | | { |
| | 226 | |
|
| 2918 | 227 | | } |
| | 228 | |
|
| | 229 | | /// <summary> |
| | 230 | | /// Initializes a new instance of the <see cref="DataLakeServiceClient"/> |
| | 231 | | /// class. |
| | 232 | | /// </summary> |
| | 233 | | /// <param name="serviceUri"> |
| | 234 | | /// A <see cref="Uri"/> referencing the Data Lake service. |
| | 235 | | /// </param> |
| | 236 | | /// <param name="authentication"> |
| | 237 | | /// An optional authentication policy used to sign requests. |
| | 238 | | /// </param> |
| | 239 | | /// <param name="options"> |
| | 240 | | /// Optional client options that define the transport pipeline |
| | 241 | | /// policies for authentication, retries, etc., that are applied to |
| | 242 | | /// every request. |
| | 243 | | /// </param> |
| | 244 | | /// <param name="clientDiagnostics"></param> |
| 2918 | 245 | | internal DataLakeServiceClient( |
| 2918 | 246 | | Uri serviceUri, |
| 2918 | 247 | | HttpPipelinePolicy authentication, |
| 2918 | 248 | | DataLakeClientOptions options, |
| 2918 | 249 | | ClientDiagnostics clientDiagnostics) |
| | 250 | | { |
| 2918 | 251 | | options ??= new DataLakeClientOptions(); |
| 2918 | 252 | | _pipeline = options.Build(authentication); |
| 2918 | 253 | | _uri = serviceUri; |
| 2918 | 254 | | _blobUri = new DataLakeUriBuilder(serviceUri).ToBlobUri(); |
| 2918 | 255 | | _version = options.Version; |
| 2918 | 256 | | _clientDiagnostics = clientDiagnostics ?? new ClientDiagnostics(options); |
| 2918 | 257 | | _blobServiceClient = BlobServiceClientInternals.Create( |
| 2918 | 258 | | _blobUri, |
| 2918 | 259 | | _pipeline, |
| 2918 | 260 | | authentication, |
| 2918 | 261 | | Version.AsBlobsVersion(), |
| 2918 | 262 | | _clientDiagnostics); |
| 2918 | 263 | | } |
| | 264 | |
|
| | 265 | | /// <summary> |
| | 266 | | /// Helper to access protected static members of BlobServiceClient |
| | 267 | | /// that should not be exposed directly to customers. |
| | 268 | | /// </summary> |
| | 269 | | private class BlobServiceClientInternals : BlobServiceClient |
| | 270 | | { |
| | 271 | | public static BlobServiceClient Create(Uri uri, HttpPipeline pipeline, HttpPipelinePolicy authentication, Bl |
| | 272 | | { |
| 2918 | 273 | | return BlobServiceClient.CreateClient( |
| 2918 | 274 | | uri, |
| 2918 | 275 | | new BlobClientOptions(version) |
| 2918 | 276 | | { |
| 2918 | 277 | | Diagnostics = { IsDistributedTracingEnabled = diagnostics.IsActivityEnabled } |
| 2918 | 278 | | }, |
| 2918 | 279 | | authentication, |
| 2918 | 280 | | pipeline); |
| | 281 | | } |
| | 282 | | } |
| | 283 | | #endregion ctors |
| | 284 | |
|
| | 285 | | /// <summary> |
| | 286 | | /// Create a new <see cref="DataLakeFileSystemClient"/> object by appending |
| | 287 | | /// <paramref name="fileSystemName"/> to the end of <see cref="Uri"/>. |
| | 288 | | /// The new <see cref="DataLakeFileSystemClient"/> uses the same request |
| | 289 | | /// policy pipeline as the <see cref="DataLakeFileSystemClient"/>. |
| | 290 | | /// </summary> |
| | 291 | | /// <param name="fileSystemName"> |
| | 292 | | /// The name of the share to reference. |
| | 293 | | /// </param> |
| | 294 | | /// <returns> |
| | 295 | | /// A <see cref="DataLakeFileSystemClient"/> for the desired share. |
| | 296 | | /// </returns> |
| | 297 | | public virtual DataLakeFileSystemClient GetFileSystemClient(string fileSystemName) |
| 2926 | 298 | | => new DataLakeFileSystemClient(Uri.AppendToPath(fileSystemName), Pipeline, Version, ClientDiagnostics); |
| | 299 | |
|
| | 300 | | #region Get User Delegation Key |
| | 301 | | /// <summary> |
| | 302 | | /// The <see cref="GetUserDelegationKey"/> operation retrieves a |
| | 303 | | /// key that can be used to delegate Active Directory authorization to |
| | 304 | | /// shared access signatures created with <see cref="Sas.DataLakeSasBuilder"/>. |
| | 305 | | /// </summary> |
| | 306 | | /// <param name="startsOn"> |
| | 307 | | /// Start time for the key's validity, with null indicating an |
| | 308 | | /// immediate start. The time should be specified in UTC. |
| | 309 | | /// </param> |
| | 310 | | /// <param name="expiresOn"> |
| | 311 | | /// Expiration of the key's validity. The time should be specified |
| | 312 | | /// in UTC. |
| | 313 | | /// </param> |
| | 314 | | /// <param name="cancellationToken"> |
| | 315 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 316 | | /// notifications that the operation should be cancelled. |
| | 317 | | /// </param> |
| | 318 | | /// <returns> |
| | 319 | | /// A <see cref="Response{UserDelegationKey}"/> describing |
| | 320 | | /// the use delegation key. |
| | 321 | | /// </returns> |
| | 322 | | /// <remarks> |
| | 323 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 324 | | /// a failure occurs. |
| | 325 | | /// </remarks> |
| | 326 | | public virtual Response<UserDelegationKey> GetUserDelegationKey( |
| | 327 | | DateTimeOffset? startsOn, |
| | 328 | | DateTimeOffset expiresOn, |
| | 329 | | CancellationToken cancellationToken = default) |
| | 330 | | { |
| 20 | 331 | | DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(DataLakeServiceClient)}.{nameof(GetUserDeleg |
| | 332 | |
|
| | 333 | | try |
| | 334 | | { |
| 20 | 335 | | scope.Start(); |
| | 336 | |
|
| 20 | 337 | | Response<Blobs.Models.UserDelegationKey> response = _blobServiceClient.GetUserDelegationKey( |
| 20 | 338 | | startsOn, |
| 20 | 339 | | expiresOn, |
| 20 | 340 | | cancellationToken); |
| | 341 | |
|
| 18 | 342 | | return Response.FromValue( |
| 18 | 343 | | new UserDelegationKey(response.Value), |
| 18 | 344 | | response.GetRawResponse()); |
| | 345 | | } |
| 2 | 346 | | catch (Exception ex) |
| | 347 | | { |
| 2 | 348 | | scope.Failed(ex); |
| 2 | 349 | | throw; |
| | 350 | | } |
| | 351 | | finally |
| | 352 | | { |
| 20 | 353 | | scope.Dispose(); |
| 20 | 354 | | } |
| 18 | 355 | | } |
| | 356 | |
|
| | 357 | | /// <summary> |
| | 358 | | /// The <see cref="GetUserDelegationKeyAsync"/> operation retrieves a |
| | 359 | | /// key that can be used to delegate Active Directory authorization to |
| | 360 | | /// shared access signatures created with <see cref="Sas.DataLakeSasBuilder"/>. |
| | 361 | | /// </summary> |
| | 362 | | /// <param name="startsOn"> |
| | 363 | | /// Start time for the key's validity, with null indicating an |
| | 364 | | /// immediate start. The time should be specified in UTC. |
| | 365 | | /// </param> |
| | 366 | | /// <param name="expiresOn"> |
| | 367 | | /// Expiration of the key's validity. The time should be specified |
| | 368 | | /// in UTC. |
| | 369 | | /// </param> |
| | 370 | | /// <param name="cancellationToken"> |
| | 371 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 372 | | /// notifications that the operation should be cancelled. |
| | 373 | | /// </param> |
| | 374 | | /// <returns> |
| | 375 | | /// A <see cref="Response{UserDelegationKey}"/> describing |
| | 376 | | /// the use delegation key. |
| | 377 | | /// </returns> |
| | 378 | | /// <remarks> |
| | 379 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 380 | | /// a failure occurs. |
| | 381 | | /// </remarks> |
| | 382 | | public virtual async Task<Response<UserDelegationKey>> GetUserDelegationKeyAsync( |
| | 383 | | DateTimeOffset? startsOn, |
| | 384 | | DateTimeOffset expiresOn, |
| | 385 | | CancellationToken cancellationToken = default) |
| | 386 | | { |
| 20 | 387 | | DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(DataLakeServiceClient)}.{nameof(GetUserDeleg |
| | 388 | |
|
| | 389 | | try |
| | 390 | | { |
| 20 | 391 | | scope.Start(); |
| | 392 | |
|
| 20 | 393 | | Response<Blobs.Models.UserDelegationKey> response = await _blobServiceClient.GetUserDelegationKeyAsync( |
| 20 | 394 | | startsOn, |
| 20 | 395 | | expiresOn, |
| 20 | 396 | | cancellationToken) |
| 20 | 397 | | .ConfigureAwait(false); |
| | 398 | |
|
| 18 | 399 | | return Response.FromValue( |
| 18 | 400 | | new UserDelegationKey(response.Value), |
| 18 | 401 | | response.GetRawResponse()); |
| | 402 | | } |
| 2 | 403 | | catch (Exception ex) |
| | 404 | | { |
| 2 | 405 | | scope.Failed(ex); |
| 2 | 406 | | throw; |
| | 407 | | } |
| | 408 | | finally |
| | 409 | | { |
| 20 | 410 | | scope.Dispose(); |
| | 411 | | } |
| 18 | 412 | | } |
| | 413 | |
|
| | 414 | | #endregion Get User Delegation Key |
| | 415 | |
|
| | 416 | | #region Get File Systems |
| | 417 | | /// <summary> |
| | 418 | | /// The <see cref="GetFileSystems"/> operation returns an async |
| | 419 | | /// sequence of file systems in the storage account. Enumerating the |
| | 420 | | /// file systems may make multiple requests to the service while fetching |
| | 421 | | /// all the values. File systems are ordered lexicographically by name. |
| | 422 | | /// |
| | 423 | | /// For more information, see |
| | 424 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/list-containers2"> |
| | 425 | | /// List Containers</see>. |
| | 426 | | /// </summary> |
| | 427 | | /// <param name="traits"> |
| | 428 | | /// Specifies trait options for shaping the file systems. |
| | 429 | | /// </param> |
| | 430 | | /// <param name="prefix"> |
| | 431 | | /// Specifies a string that filters the results to return only file systems |
| | 432 | | /// whose name begins with the specified <paramref name="prefix"/>. |
| | 433 | | /// </param> |
| | 434 | | /// <param name="cancellationToken"> |
| | 435 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 436 | | /// notifications that the operation should be cancelled. |
| | 437 | | /// </param> |
| | 438 | | /// <returns> |
| | 439 | | /// An <see cref="IEnumerable{T}"/> of <see cref="Response{FileSystemItem}"/> |
| | 440 | | /// describing the file systems in the storage account. |
| | 441 | | /// </returns> |
| | 442 | | /// <remarks> |
| | 443 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 444 | | /// a failure occurs. |
| | 445 | | /// </remarks> |
| | 446 | | public virtual Pageable<FileSystemItem> GetFileSystems( |
| | 447 | | FileSystemTraits traits = FileSystemTraits.None, |
| | 448 | | string prefix = default, |
| | 449 | | CancellationToken cancellationToken = default) => |
| 14 | 450 | | new GetFileSystemsAsyncCollection(_blobServiceClient, traits, prefix).ToSyncCollection(cancellationToken); |
| | 451 | |
|
| | 452 | | /// <summary> |
| | 453 | | /// The <see cref="GetFileSystemsAsync"/> operation returns an async |
| | 454 | | /// sequence of file systems in the storage account. Enumerating the |
| | 455 | | /// files systems may make multiple requests to the service while fetching |
| | 456 | | /// all the values. File systems are ordered lexicographically by name. |
| | 457 | | /// |
| | 458 | | /// For more information, see |
| | 459 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/list-containers2"> |
| | 460 | | /// List Containers</see>. |
| | 461 | | /// </summary> |
| | 462 | | /// <param name="traits"> |
| | 463 | | /// Specifies trait options for shaping the file systems. |
| | 464 | | /// </param> |
| | 465 | | /// <param name="prefix"> |
| | 466 | | /// Specifies a string that filters the results to return only file systems |
| | 467 | | /// whose name begins with the specified <paramref name="prefix"/>. |
| | 468 | | /// </param> |
| | 469 | | /// <param name="cancellationToken"> |
| | 470 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 471 | | /// notifications that the operation should be cancelled. |
| | 472 | | /// </param> |
| | 473 | | /// <returns> |
| | 474 | | /// An <see cref="AsyncPageable{T}"/> describing the |
| | 475 | | /// file systems in the storage account. |
| | 476 | | /// </returns> |
| | 477 | | /// <remarks> |
| | 478 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 479 | | /// a failure occurs. |
| | 480 | | /// </remarks> |
| | 481 | | public virtual AsyncPageable<FileSystemItem> GetFileSystemsAsync( |
| | 482 | | FileSystemTraits traits = FileSystemTraits.None, |
| | 483 | | string prefix = default, |
| | 484 | | CancellationToken cancellationToken = default) => |
| 18 | 485 | | new GetFileSystemsAsyncCollection(_blobServiceClient, traits, prefix).ToAsyncCollection(cancellationToken); |
| | 486 | | #endregion Get File Systems |
| | 487 | |
|
| | 488 | | #region Create File System |
| | 489 | | /// <summary> |
| | 490 | | /// The <see cref="CreateFileSystem"/> operation creates a new |
| | 491 | | /// file system under the specified account. If the file systen with the |
| | 492 | | /// same name already exists, the operation fails. |
| | 493 | | /// |
| | 494 | | /// For more information, see |
| | 495 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/create-container"> |
| | 496 | | /// Create Container</see>. |
| | 497 | | /// </summary> |
| | 498 | | /// <param name="fileSystemName"> |
| | 499 | | /// The name of the file system to create. |
| | 500 | | /// </param> |
| | 501 | | /// <param name="publicAccessType"> |
| | 502 | | /// Optionally specifies whether data in the file system may be accessed |
| | 503 | | /// publicly and the level of access. <see cref="PublicAccessType.FileSystem"/> |
| | 504 | | /// specifies full public read access for file system and path data. |
| | 505 | | /// Clients can enumerate paths within the file system via anonymous |
| | 506 | | /// request, but cannot enumerate file systems within the storage |
| | 507 | | /// account. <see cref="PublicAccessType.Path"/> specifies public |
| | 508 | | /// read access for paths. Path data within this file system can be |
| | 509 | | /// read via anonymous request, but file system data is not available. |
| | 510 | | /// Clients cannot enumerate paths within the file system via anonymous |
| | 511 | | /// request. <see cref="PublicAccessType.None"/> specifies that the |
| | 512 | | /// file system data is private to the account owner. |
| | 513 | | /// </param> |
| | 514 | | /// <param name="metadata"> |
| | 515 | | /// Optional custom metadata to set for this file system. |
| | 516 | | /// </param> |
| | 517 | | /// <param name="cancellationToken"> |
| | 518 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 519 | | /// notifications that the operation should be cancelled. |
| | 520 | | /// </param> |
| | 521 | | /// <returns> |
| | 522 | | /// A <see cref="Response{FileSystemClient}"/> referencing the |
| | 523 | | /// newly created file system. |
| | 524 | | /// </returns> |
| | 525 | | /// <remarks> |
| | 526 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 527 | | /// a failure occurs. |
| | 528 | | /// </remarks> |
| | 529 | | public virtual Response<DataLakeFileSystemClient> CreateFileSystem( |
| | 530 | | string fileSystemName, |
| | 531 | | PublicAccessType publicAccessType = PublicAccessType.None, |
| | 532 | | Metadata metadata = default, |
| | 533 | | CancellationToken cancellationToken = default) |
| | 534 | | { |
| 10 | 535 | | DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(DataLakeServiceClient)}.{nameof(CreateFileSy |
| | 536 | |
|
| | 537 | | try |
| | 538 | | { |
| 10 | 539 | | scope.Start(); |
| | 540 | |
|
| 10 | 541 | | DataLakeFileSystemClient fileSystem = GetFileSystemClient(fileSystemName); |
| 10 | 542 | | Response<FileSystemInfo> response = fileSystem.Create(publicAccessType, metadata, cancellationToken); |
| 10 | 543 | | return Response.FromValue(fileSystem, response.GetRawResponse()); |
| | 544 | | } |
| 0 | 545 | | catch (Exception ex) |
| | 546 | | { |
| 0 | 547 | | scope.Failed(ex); |
| 0 | 548 | | throw; |
| | 549 | | } |
| | 550 | | finally |
| | 551 | | { |
| 10 | 552 | | scope.Dispose(); |
| 10 | 553 | | } |
| 10 | 554 | | } |
| | 555 | |
|
| | 556 | | /// <summary> |
| | 557 | | /// The <see cref="CreateFileSystemAsync"/> operation creates a new |
| | 558 | | /// file system under the specified account. If the file system with the |
| | 559 | | /// same name already exists, the operation fails. |
| | 560 | | /// |
| | 561 | | /// For more information, see |
| | 562 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/create-container"> |
| | 563 | | /// Create Container</see>. |
| | 564 | | /// </summary> |
| | 565 | | /// <param name="fileSystemName"> |
| | 566 | | /// The name of the file system to create. |
| | 567 | | /// </param> |
| | 568 | | /// <param name="publicAccessType"> |
| | 569 | | /// Optionally specifies whether data in the file system may be accessed |
| | 570 | | /// publicly and the level of access. <see cref="PublicAccessType.FileSystem"/> |
| | 571 | | /// specifies full public read access for file system and path data. |
| | 572 | | /// Clients can enumerate paths within the file system via anonymous |
| | 573 | | /// request, but cannot enumerate file systems within the storage |
| | 574 | | /// account. <see cref="PublicAccessType.Path"/> specifies public |
| | 575 | | /// read access for paths. Path data within this file system can be |
| | 576 | | /// read via anonymous request, but file system data is not available. |
| | 577 | | /// Clients cannot enumerate paths within the file system via anonymous |
| | 578 | | /// request. <see cref="PublicAccessType.None"/> specifies that the |
| | 579 | | /// file system data is private to the account owner. |
| | 580 | | /// </param> |
| | 581 | | /// <param name="metadata"> |
| | 582 | | /// Optional custom metadata to set for this file system. |
| | 583 | | /// </param> |
| | 584 | | /// <param name="cancellationToken"> |
| | 585 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 586 | | /// notifications that the operation should be cancelled. |
| | 587 | | /// </param> |
| | 588 | | /// <returns> |
| | 589 | | /// A <see cref="Response{FileSystemClient}"/> referencing the |
| | 590 | | /// newly created file system. |
| | 591 | | /// </returns> |
| | 592 | | /// <remarks> |
| | 593 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 594 | | /// a failure occurs. |
| | 595 | | /// </remarks> |
| | 596 | | public virtual async Task<Response<DataLakeFileSystemClient>> CreateFileSystemAsync( |
| | 597 | | string fileSystemName, |
| | 598 | | PublicAccessType publicAccessType = PublicAccessType.None, |
| | 599 | | Metadata metadata = default, |
| | 600 | | CancellationToken cancellationToken = default) |
| | 601 | | { |
| 10 | 602 | | DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(DataLakeServiceClient)}.{nameof(CreateFileSy |
| | 603 | |
|
| | 604 | | try |
| | 605 | | { |
| 10 | 606 | | scope.Start(); |
| | 607 | |
|
| 10 | 608 | | DataLakeFileSystemClient fileSystem = GetFileSystemClient(fileSystemName); |
| 10 | 609 | | Response<FileSystemInfo> response = await fileSystem.CreateAsync(publicAccessType, metadata, cancellatio |
| 10 | 610 | | return Response.FromValue(fileSystem, response.GetRawResponse()); |
| | 611 | | } |
| 0 | 612 | | catch (Exception ex) |
| | 613 | | { |
| 0 | 614 | | scope.Failed(ex); |
| 0 | 615 | | throw; |
| | 616 | | } |
| | 617 | | finally |
| | 618 | | { |
| 10 | 619 | | scope.Dispose(); |
| | 620 | | } |
| 10 | 621 | | } |
| | 622 | | #endregion Create File System |
| | 623 | |
|
| | 624 | | #region Delete File System |
| | 625 | | /// <summary> |
| | 626 | | /// The <see cref="DeleteFileSystem"/> operation marks the |
| | 627 | | /// specified file system for deletion. The file system and any paths |
| | 628 | | /// contained within it are later deleted during garbage collection. |
| | 629 | | /// |
| | 630 | | /// For more information, see |
| | 631 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/delete-container"> |
| | 632 | | /// Delete Container</see>. |
| | 633 | | /// </summary> |
| | 634 | | /// <param name="fileSystemName"> |
| | 635 | | /// The name of the file system to delete. |
| | 636 | | /// </param> |
| | 637 | | /// <param name="conditions"> |
| | 638 | | /// Optional <see cref="DataLakeRequestConditions"/> to add |
| | 639 | | /// conditions on the deletion of this file system. |
| | 640 | | /// </param> |
| | 641 | | /// <param name="cancellationToken"> |
| | 642 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 643 | | /// notifications that the operation should be cancelled. |
| | 644 | | /// </param> |
| | 645 | | /// <returns> |
| | 646 | | /// A <see cref="Response"/> if successful. |
| | 647 | | /// </returns> |
| | 648 | | /// <remarks> |
| | 649 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 650 | | /// a failure occurs. |
| | 651 | | /// </remarks> |
| | 652 | | public virtual Response DeleteFileSystem( |
| | 653 | | string fileSystemName, |
| | 654 | | DataLakeRequestConditions conditions = default, |
| | 655 | | CancellationToken cancellationToken = default) |
| | 656 | | { |
| 10 | 657 | | DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(DataLakeServiceClient)}.{nameof(DeleteFileSy |
| | 658 | |
|
| | 659 | | try |
| | 660 | | { |
| 10 | 661 | | scope.Start(); |
| | 662 | |
|
| 10 | 663 | | return GetFileSystemClient(fileSystemName) |
| 10 | 664 | | .Delete( |
| 10 | 665 | | conditions, |
| 10 | 666 | | cancellationToken); |
| | 667 | | } |
| 0 | 668 | | catch (Exception ex) |
| | 669 | | { |
| 0 | 670 | | scope.Failed(ex); |
| 0 | 671 | | throw; |
| | 672 | | } |
| | 673 | | finally |
| | 674 | | { |
| 10 | 675 | | scope.Dispose(); |
| 10 | 676 | | } |
| 10 | 677 | | } |
| | 678 | |
|
| | 679 | | /// <summary> |
| | 680 | | /// The <see cref="DeleteFileSystemAsync"/> operation marks the |
| | 681 | | /// specified file system for deletion. The file system and any paths |
| | 682 | | /// contained within it are later deleted during garbage collection. |
| | 683 | | /// |
| | 684 | | /// For more information, see |
| | 685 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/delete-container"> |
| | 686 | | /// Delete Container</see>. |
| | 687 | | /// </summary> |
| | 688 | | /// <param name="fileSystemName"> |
| | 689 | | /// The name of the file system to delete. |
| | 690 | | /// </param> |
| | 691 | | /// <param name="conditions"> |
| | 692 | | /// Optional <see cref="DataLakeRequestConditions"/> to add |
| | 693 | | /// conditions on the deletion of this file system. |
| | 694 | | /// </param> |
| | 695 | | /// <param name="cancellationToken"> |
| | 696 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 697 | | /// notifications that the operation should be cancelled. |
| | 698 | | /// </param> |
| | 699 | | /// <returns> |
| | 700 | | /// A <see cref="Response"/> if successful. |
| | 701 | | /// </returns> |
| | 702 | | /// <remarks> |
| | 703 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 704 | | /// a failure occurs. |
| | 705 | | /// </remarks> |
| | 706 | | public virtual async Task<Response> DeleteFileSystemAsync( |
| | 707 | | string fileSystemName, |
| | 708 | | DataLakeRequestConditions conditions = default, |
| | 709 | | CancellationToken cancellationToken = default) |
| | 710 | | { |
| 10 | 711 | | DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(DataLakeServiceClient)}.{nameof(DeleteFileSy |
| | 712 | |
|
| | 713 | | try |
| | 714 | | { |
| 10 | 715 | | scope.Start(); |
| | 716 | |
|
| 10 | 717 | | return await GetFileSystemClient(fileSystemName) |
| 10 | 718 | | .DeleteAsync( |
| 10 | 719 | | conditions, |
| 10 | 720 | | cancellationToken) |
| 10 | 721 | | .ConfigureAwait(false); |
| | 722 | | } |
| 0 | 723 | | catch (Exception ex) |
| | 724 | | { |
| 0 | 725 | | scope.Failed(ex); |
| 0 | 726 | | throw; |
| | 727 | | } |
| | 728 | | finally |
| | 729 | | { |
| 10 | 730 | | scope.Dispose(); |
| | 731 | | } |
| 10 | 732 | | } |
| | 733 | | #endregion Delete File System |
| | 734 | | } |
| | 735 | | } |