1 | import { __asyncDelegator, __asyncGenerator, __asyncValues, __await } from "tslib";
|
2 | // Copyright (c) Microsoft Corporation.
|
3 | // Licensed under the MIT license.
|
4 | import { isTokenCredential, isNode, getDefaultProxySettings, } from "@azure/core-http";
|
5 | import { SpanStatusCode } from "@azure/core-tracing";
|
6 | import { Container, Service } from "./generated/src/operations";
|
7 | import { newPipeline, isPipelineLike } from "./Pipeline";
|
8 | import { ContainerClient, } from "./ContainerClient";
|
9 | import { appendToURLPath, appendToURLQuery, extractConnectionStringParts, toTags, } from "./utils/utils.common";
|
10 | import { StorageSharedKeyCredential } from "./credentials/StorageSharedKeyCredential";
|
11 | import { AnonymousCredential } from "./credentials/AnonymousCredential";
|
12 | import "@azure/core-paging";
|
13 | import { truncatedISO8061Date } from "./utils/utils.common";
|
14 | import { convertTracingToRequestOptionsBase, createSpan } from "./utils/tracing";
|
15 | import { BlobBatchClient } from "./BlobBatchClient";
|
16 | import { StorageClient } from "./StorageClient";
|
17 | import { AccountSASPermissions } from "./sas/AccountSASPermissions";
|
18 | import { generateAccountSASQueryParameters } from "./sas/AccountSASSignatureValues";
|
19 | import { AccountSASServices } from "./sas/AccountSASServices";
|
20 | /**
|
21 | * A BlobServiceClient represents a Client to the Azure Storage Blob service allowing you
|
22 | * to manipulate blob containers.
|
23 | */
|
24 | export class BlobServiceClient extends StorageClient {
|
25 | constructor(url, credentialOrPipeline,
|
26 | // Legacy, no fix for eslint error without breaking. Disable it for this interface.
|
27 | /* eslint-disable-next-line @azure/azure-sdk/ts-naming-options*/
|
28 | options) {
|
29 | let pipeline;
|
30 | if (isPipelineLike(credentialOrPipeline)) {
|
31 | pipeline = credentialOrPipeline;
|
32 | }
|
33 | else if ((isNode && credentialOrPipeline instanceof StorageSharedKeyCredential) ||
|
34 | credentialOrPipeline instanceof AnonymousCredential ||
|
35 | isTokenCredential(credentialOrPipeline)) {
|
36 | pipeline = newPipeline(credentialOrPipeline, options);
|
37 | }
|
38 | else {
|
39 | // The second parameter is undefined. Use anonymous credential
|
40 | pipeline = newPipeline(new AnonymousCredential(), options);
|
41 | }
|
42 | super(url, pipeline);
|
43 | this.serviceContext = new Service(this.storageClientContext);
|
44 | }
|
45 | /**
|
46 | *
|
47 | * Creates an instance of BlobServiceClient from connection string.
|
48 | *
|
49 | * @param connectionString - Account connection string or a SAS connection string of an Azure storage account.
|
50 | * [ Note - Account connection string can only be used in NODE.JS runtime. ]
|
51 | * Account connection string example -
|
52 | * `DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=accountKey;EndpointSuffix=core.windows.net`
|
53 | * SAS connection string example -
|
54 | * `BlobEndpoint=https://myaccount.blob.core.windows.net/;QueueEndpoint=https://myaccount.queue.core.windows.net/;FileEndpoint=https://myaccount.file.core.windows.net/;TableEndpoint=https://myaccount.table.core.windows.net/;SharedAccessSignature=sasString`
|
55 | * @param options - Optional. Options to configure the HTTP pipeline.
|
56 | */
|
57 | static fromConnectionString(connectionString,
|
58 | // Legacy, no fix for eslint error without breaking. Disable it for this interface.
|
59 | /* eslint-disable-next-line @azure/azure-sdk/ts-naming-options*/
|
60 | options) {
|
61 | options = options || {};
|
62 | const extractedCreds = extractConnectionStringParts(connectionString);
|
63 | if (extractedCreds.kind === "AccountConnString") {
|
64 | if (isNode) {
|
65 | const sharedKeyCredential = new StorageSharedKeyCredential(extractedCreds.accountName, extractedCreds.accountKey);
|
66 | if (!options.proxyOptions) {
|
67 | options.proxyOptions = getDefaultProxySettings(extractedCreds.proxyUri);
|
68 | }
|
69 | const pipeline = newPipeline(sharedKeyCredential, options);
|
70 | return new BlobServiceClient(extractedCreds.url, pipeline);
|
71 | }
|
72 | else {
|
73 | throw new Error("Account connection string is only supported in Node.js environment");
|
74 | }
|
75 | }
|
76 | else if (extractedCreds.kind === "SASConnString") {
|
77 | const pipeline = newPipeline(new AnonymousCredential(), options);
|
78 | return new BlobServiceClient(extractedCreds.url + "?" + extractedCreds.accountSas, pipeline);
|
79 | }
|
80 | else {
|
81 | throw new Error("Connection string must be either an Account connection string or a SAS connection string");
|
82 | }
|
83 | }
|
84 | /**
|
85 | * Creates a {@link ContainerClient} object
|
86 | *
|
87 | * @param containerName - A container name
|
88 | * @returns A new ContainerClient object for the given container name.
|
89 | *
|
90 | * Example usage:
|
91 | *
|
92 | * ```js
|
93 | * const containerClient = blobServiceClient.getContainerClient("<container name>");
|
94 | * ```
|
95 | */
|
96 | getContainerClient(containerName) {
|
97 | return new ContainerClient(appendToURLPath(this.url, encodeURIComponent(containerName)), this.pipeline);
|
98 | }
|
99 | /**
|
100 | * Create a Blob container.
|
101 | *
|
102 | * @param containerName - Name of the container to create.
|
103 | * @param options - Options to configure Container Create operation.
|
104 | * @returns Container creation response and the corresponding container client.
|
105 | */
|
106 | async createContainer(containerName, options = {}) {
|
107 | const { span, updatedOptions } = createSpan("BlobServiceClient-createContainer", options);
|
108 | try {
|
109 | const containerClient = this.getContainerClient(containerName);
|
110 | const containerCreateResponse = await containerClient.create(updatedOptions);
|
111 | return {
|
112 | containerClient,
|
113 | containerCreateResponse,
|
114 | };
|
115 | }
|
116 | catch (e) {
|
117 | span.setStatus({
|
118 | code: SpanStatusCode.ERROR,
|
119 | message: e.message,
|
120 | });
|
121 | throw e;
|
122 | }
|
123 | finally {
|
124 | span.end();
|
125 | }
|
126 | }
|
127 | /**
|
128 | * Deletes a Blob container.
|
129 | *
|
130 | * @param containerName - Name of the container to delete.
|
131 | * @param options - Options to configure Container Delete operation.
|
132 | * @returns Container deletion response.
|
133 | */
|
134 | async deleteContainer(containerName, options = {}) {
|
135 | const { span, updatedOptions } = createSpan("BlobServiceClient-deleteContainer", options);
|
136 | try {
|
137 | const containerClient = this.getContainerClient(containerName);
|
138 | return await containerClient.delete(updatedOptions);
|
139 | }
|
140 | catch (e) {
|
141 | span.setStatus({
|
142 | code: SpanStatusCode.ERROR,
|
143 | message: e.message,
|
144 | });
|
145 | throw e;
|
146 | }
|
147 | finally {
|
148 | span.end();
|
149 | }
|
150 | }
|
151 | /**
|
152 | * Restore a previously deleted Blob container.
|
153 | * This API is only functional if Container Soft Delete is enabled for the storage account associated with the container.
|
154 | *
|
155 | * @param deletedContainerName - Name of the previously deleted container.
|
156 | * @param deletedContainerVersion - Version of the previously deleted container, used to uniquely identify the deleted container.
|
157 | * @param options - Options to configure Container Restore operation.
|
158 | * @returns Container deletion response.
|
159 | */
|
160 | async undeleteContainer(deletedContainerName, deletedContainerVersion, options = {}) {
|
161 | const { span, updatedOptions } = createSpan("BlobServiceClient-undeleteContainer", options);
|
162 | try {
|
163 | const containerClient = this.getContainerClient(options.destinationContainerName || deletedContainerName);
|
164 | // Hack to access a protected member.
|
165 | const containerContext = new Container(containerClient["storageClientContext"]);
|
166 | const containerUndeleteResponse = await containerContext.restore(Object.assign({ deletedContainerName,
|
167 | deletedContainerVersion }, updatedOptions));
|
168 | return { containerClient, containerUndeleteResponse };
|
169 | }
|
170 | catch (e) {
|
171 | span.setStatus({
|
172 | code: SpanStatusCode.ERROR,
|
173 | message: e.message,
|
174 | });
|
175 | throw e;
|
176 | }
|
177 | finally {
|
178 | span.end();
|
179 | }
|
180 | }
|
181 | /**
|
182 | * Rename an existing Blob Container.
|
183 | *
|
184 | * @param sourceContainerName - The name of the source container.
|
185 | * @param destinationContainerName - The new name of the container.
|
186 | * @param options - Options to configure Container Rename operation.
|
187 | */
|
188 | /* eslint-disable-next-line @typescript-eslint/ban-ts-comment */
|
189 | // @ts-ignore Need to hide this interface for now. Make it public and turn on the live tests for it when the service is ready.
|
190 | async renameContainer(sourceContainerName, destinationContainerName, options = {}) {
|
191 | var _a;
|
192 | const { span, updatedOptions } = createSpan("BlobServiceClient-renameContainer", options);
|
193 | try {
|
194 | const containerClient = this.getContainerClient(destinationContainerName);
|
195 | // Hack to access a protected member.
|
196 | const containerContext = new Container(containerClient["storageClientContext"]);
|
197 | const containerRenameResponse = await containerContext.rename(sourceContainerName, Object.assign(Object.assign({}, updatedOptions), { sourceLeaseId: (_a = options.sourceCondition) === null || _a === void 0 ? void 0 : _a.leaseId }));
|
198 | return { containerClient, containerRenameResponse };
|
199 | }
|
200 | catch (e) {
|
201 | span.setStatus({
|
202 | code: SpanStatusCode.ERROR,
|
203 | message: e.message,
|
204 | });
|
205 | throw e;
|
206 | }
|
207 | finally {
|
208 | span.end();
|
209 | }
|
210 | }
|
211 | /**
|
212 | * Gets the properties of a storage account’s Blob service, including properties
|
213 | * for Storage Analytics and CORS (Cross-Origin Resource Sharing) rules.
|
214 | * @see https://docs.microsoft.com/en-us/rest/api/storageservices/get-blob-service-properties
|
215 | *
|
216 | * @param options - Options to the Service Get Properties operation.
|
217 | * @returns Response data for the Service Get Properties operation.
|
218 | */
|
219 | async getProperties(options = {}) {
|
220 | const { span, updatedOptions } = createSpan("BlobServiceClient-getProperties", options);
|
221 | try {
|
222 | return await this.serviceContext.getProperties(Object.assign({ abortSignal: options.abortSignal }, convertTracingToRequestOptionsBase(updatedOptions)));
|
223 | }
|
224 | catch (e) {
|
225 | span.setStatus({
|
226 | code: SpanStatusCode.ERROR,
|
227 | message: e.message,
|
228 | });
|
229 | throw e;
|
230 | }
|
231 | finally {
|
232 | span.end();
|
233 | }
|
234 | }
|
235 | /**
|
236 | * Sets properties for a storage account’s Blob service endpoint, including properties
|
237 | * for Storage Analytics, CORS (Cross-Origin Resource Sharing) rules and soft delete settings.
|
238 | * @see https://docs.microsoft.com/en-us/rest/api/storageservices/set-blob-service-properties
|
239 | *
|
240 | * @param properties -
|
241 | * @param options - Options to the Service Set Properties operation.
|
242 | * @returns Response data for the Service Set Properties operation.
|
243 | */
|
244 | async setProperties(properties, options = {}) {
|
245 | const { span, updatedOptions } = createSpan("BlobServiceClient-setProperties", options);
|
246 | try {
|
247 | return await this.serviceContext.setProperties(properties, Object.assign({ abortSignal: options.abortSignal }, convertTracingToRequestOptionsBase(updatedOptions)));
|
248 | }
|
249 | catch (e) {
|
250 | span.setStatus({
|
251 | code: SpanStatusCode.ERROR,
|
252 | message: e.message,
|
253 | });
|
254 | throw e;
|
255 | }
|
256 | finally {
|
257 | span.end();
|
258 | }
|
259 | }
|
260 | /**
|
261 | * Retrieves statistics related to replication for the Blob service. It is only
|
262 | * available on the secondary location endpoint when read-access geo-redundant
|
263 | * replication is enabled for the storage account.
|
264 | * @see https://docs.microsoft.com/en-us/rest/api/storageservices/get-blob-service-stats
|
265 | *
|
266 | * @param options - Options to the Service Get Statistics operation.
|
267 | * @returns Response data for the Service Get Statistics operation.
|
268 | */
|
269 | async getStatistics(options = {}) {
|
270 | const { span, updatedOptions } = createSpan("BlobServiceClient-getStatistics", options);
|
271 | try {
|
272 | return await this.serviceContext.getStatistics(Object.assign({ abortSignal: options.abortSignal }, convertTracingToRequestOptionsBase(updatedOptions)));
|
273 | }
|
274 | catch (e) {
|
275 | span.setStatus({
|
276 | code: SpanStatusCode.ERROR,
|
277 | message: e.message,
|
278 | });
|
279 | throw e;
|
280 | }
|
281 | finally {
|
282 | span.end();
|
283 | }
|
284 | }
|
285 | /**
|
286 | * The Get Account Information operation returns the sku name and account kind
|
287 | * for the specified account.
|
288 | * The Get Account Information operation is available on service versions beginning
|
289 | * with version 2018-03-28.
|
290 | * @see https://docs.microsoft.com/en-us/rest/api/storageservices/get-account-information
|
291 | *
|
292 | * @param options - Options to the Service Get Account Info operation.
|
293 | * @returns Response data for the Service Get Account Info operation.
|
294 | */
|
295 | async getAccountInfo(options = {}) {
|
296 | const { span, updatedOptions } = createSpan("BlobServiceClient-getAccountInfo", options);
|
297 | try {
|
298 | return await this.serviceContext.getAccountInfo(Object.assign({ abortSignal: options.abortSignal }, convertTracingToRequestOptionsBase(updatedOptions)));
|
299 | }
|
300 | catch (e) {
|
301 | span.setStatus({
|
302 | code: SpanStatusCode.ERROR,
|
303 | message: e.message,
|
304 | });
|
305 | throw e;
|
306 | }
|
307 | finally {
|
308 | span.end();
|
309 | }
|
310 | }
|
311 | /**
|
312 | * Returns a list of the containers under the specified account.
|
313 | * @see https://docs.microsoft.com/en-us/rest/api/storageservices/list-containers2
|
314 | *
|
315 | * @param marker - A string value that identifies the portion of
|
316 | * the list of containers to be returned with the next listing operation. The
|
317 | * operation returns the continuationToken value within the response body if the
|
318 | * listing operation did not return all containers remaining to be listed
|
319 | * with the current page. The continuationToken value can be used as the value for
|
320 | * the marker parameter in a subsequent call to request the next page of list
|
321 | * items. The marker value is opaque to the client.
|
322 | * @param options - Options to the Service List Container Segment operation.
|
323 | * @returns Response data for the Service List Container Segment operation.
|
324 | */
|
325 | async listContainersSegment(marker, options = {}) {
|
326 | const { span, updatedOptions } = createSpan("BlobServiceClient-listContainersSegment", options);
|
327 | try {
|
328 | return await this.serviceContext.listContainersSegment(Object.assign(Object.assign(Object.assign({ abortSignal: options.abortSignal, marker }, options), { include: typeof options.include === "string" ? [options.include] : options.include }), convertTracingToRequestOptionsBase(updatedOptions)));
|
329 | }
|
330 | catch (e) {
|
331 | span.setStatus({
|
332 | code: SpanStatusCode.ERROR,
|
333 | message: e.message,
|
334 | });
|
335 | throw e;
|
336 | }
|
337 | finally {
|
338 | span.end();
|
339 | }
|
340 | }
|
341 | /**
|
342 | * The Filter Blobs operation enables callers to list blobs across all containers whose tags
|
343 | * match a given search expression. Filter blobs searches across all containers within a
|
344 | * storage account but can be scoped within the expression to a single container.
|
345 | *
|
346 | * @param tagFilterSqlExpression - The where parameter enables the caller to query blobs whose tags match a given expression.
|
347 | * The given expression must evaluate to true for a blob to be returned in the results.
|
348 | * The[OData - ABNF] filter syntax rule defines the formal grammar for the value of the where query parameter;
|
349 | * however, only a subset of the OData filter syntax is supported in the Blob service.
|
350 | * @param marker - A string value that identifies the portion of
|
351 | * the list of blobs to be returned with the next listing operation. The
|
352 | * operation returns the continuationToken value within the response body if the
|
353 | * listing operation did not return all blobs remaining to be listed
|
354 | * with the current page. The continuationToken value can be used as the value for
|
355 | * the marker parameter in a subsequent call to request the next page of list
|
356 | * items. The marker value is opaque to the client.
|
357 | * @param options - Options to find blobs by tags.
|
358 | */
|
359 | async findBlobsByTagsSegment(tagFilterSqlExpression, marker, options = {}) {
|
360 | const { span, updatedOptions } = createSpan("BlobServiceClient-findBlobsByTagsSegment", options);
|
361 | try {
|
362 | const response = await this.serviceContext.filterBlobs(Object.assign({ abortSignal: options.abortSignal, where: tagFilterSqlExpression, marker, maxPageSize: options.maxPageSize }, convertTracingToRequestOptionsBase(updatedOptions)));
|
363 | const wrappedResponse = Object.assign(Object.assign({}, response), { _response: response._response, blobs: response.blobs.map((blob) => {
|
364 | var _a;
|
365 | let tagValue = "";
|
366 | if (((_a = blob.tags) === null || _a === void 0 ? void 0 : _a.blobTagSet.length) === 1) {
|
367 | tagValue = blob.tags.blobTagSet[0].value;
|
368 | }
|
369 | return Object.assign(Object.assign({}, blob), { tags: toTags(blob.tags), tagValue });
|
370 | }) });
|
371 | return wrappedResponse;
|
372 | }
|
373 | catch (e) {
|
374 | span.setStatus({
|
375 | code: SpanStatusCode.ERROR,
|
376 | message: e.message,
|
377 | });
|
378 | throw e;
|
379 | }
|
380 | finally {
|
381 | span.end();
|
382 | }
|
383 | }
|
384 | /**
|
385 | * Returns an AsyncIterableIterator for ServiceFindBlobsByTagsSegmentResponse.
|
386 | *
|
387 | * @param tagFilterSqlExpression - The where parameter enables the caller to query blobs whose tags match a given expression.
|
388 | * The given expression must evaluate to true for a blob to be returned in the results.
|
389 | * The[OData - ABNF] filter syntax rule defines the formal grammar for the value of the where query parameter;
|
390 | * however, only a subset of the OData filter syntax is supported in the Blob service.
|
391 | * @param marker - A string value that identifies the portion of
|
392 | * the list of blobs to be returned with the next listing operation. The
|
393 | * operation returns the continuationToken value within the response body if the
|
394 | * listing operation did not return all blobs remaining to be listed
|
395 | * with the current page. The continuationToken value can be used as the value for
|
396 | * the marker parameter in a subsequent call to request the next page of list
|
397 | * items. The marker value is opaque to the client.
|
398 | * @param options - Options to find blobs by tags.
|
399 | */
|
400 | findBlobsByTagsSegments(tagFilterSqlExpression, marker, options = {}) {
|
401 | return __asyncGenerator(this, arguments, function* findBlobsByTagsSegments_1() {
|
402 | let response;
|
403 | if (!!marker || marker === undefined) {
|
404 | do {
|
405 | response = yield __await(this.findBlobsByTagsSegment(tagFilterSqlExpression, marker, options));
|
406 | response.blobs = response.blobs || [];
|
407 | marker = response.continuationToken;
|
408 | yield yield __await(response);
|
409 | } while (marker);
|
410 | }
|
411 | });
|
412 | }
|
413 | /**
|
414 | * Returns an AsyncIterableIterator for blobs.
|
415 | *
|
416 | * @param tagFilterSqlExpression - The where parameter enables the caller to query blobs whose tags match a given expression.
|
417 | * The given expression must evaluate to true for a blob to be returned in the results.
|
418 | * The[OData - ABNF] filter syntax rule defines the formal grammar for the value of the where query parameter;
|
419 | * however, only a subset of the OData filter syntax is supported in the Blob service.
|
420 | * @param options - Options to findBlobsByTagsItems.
|
421 | */
|
422 | findBlobsByTagsItems(tagFilterSqlExpression, options = {}) {
|
423 | return __asyncGenerator(this, arguments, function* findBlobsByTagsItems_1() {
|
424 | var e_1, _a;
|
425 | let marker;
|
426 | try {
|
427 | for (var _b = __asyncValues(this.findBlobsByTagsSegments(tagFilterSqlExpression, marker, options)), _c; _c = yield __await(_b.next()), !_c.done;) {
|
428 | const segment = _c.value;
|
429 | yield __await(yield* __asyncDelegator(__asyncValues(segment.blobs)));
|
430 | }
|
431 | }
|
432 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
433 | finally {
|
434 | try {
|
435 | if (_c && !_c.done && (_a = _b.return)) yield __await(_a.call(_b));
|
436 | }
|
437 | finally { if (e_1) throw e_1.error; }
|
438 | }
|
439 | });
|
440 | }
|
441 | /**
|
442 | * Returns an async iterable iterator to find all blobs with specified tag
|
443 | * under the specified account.
|
444 | *
|
445 | * .byPage() returns an async iterable iterator to list the blobs in pages.
|
446 | *
|
447 | * @see https://docs.microsoft.com/en-us/rest/api/storageservices/get-blob-service-properties
|
448 | *
|
449 | * Example using `for await` syntax:
|
450 | *
|
451 | * ```js
|
452 | * let i = 1;
|
453 | * for await (const blob of blobServiceClient.findBlobsByTags("tagkey='tagvalue'")) {
|
454 | * console.log(`Blob ${i++}: ${container.name}`);
|
455 | * }
|
456 | * ```
|
457 | *
|
458 | * Example using `iter.next()`:
|
459 | *
|
460 | * ```js
|
461 | * let i = 1;
|
462 | * const iter = blobServiceClient.findBlobsByTags("tagkey='tagvalue'");
|
463 | * let blobItem = await iter.next();
|
464 | * while (!blobItem.done) {
|
465 | * console.log(`Blob ${i++}: ${blobItem.value.name}`);
|
466 | * blobItem = await iter.next();
|
467 | * }
|
468 | * ```
|
469 | *
|
470 | * Example using `byPage()`:
|
471 | *
|
472 | * ```js
|
473 | * // passing optional maxPageSize in the page settings
|
474 | * let i = 1;
|
475 | * for await (const response of blobServiceClient.findBlobsByTags("tagkey='tagvalue'").byPage({ maxPageSize: 20 })) {
|
476 | * if (response.blobs) {
|
477 | * for (const blob of response.blobs) {
|
478 | * console.log(`Blob ${i++}: ${blob.name}`);
|
479 | * }
|
480 | * }
|
481 | * }
|
482 | * ```
|
483 | *
|
484 | * Example using paging with a marker:
|
485 | *
|
486 | * ```js
|
487 | * let i = 1;
|
488 | * let iterator = blobServiceClient.findBlobsByTags("tagkey='tagvalue'").byPage({ maxPageSize: 2 });
|
489 | * let response = (await iterator.next()).value;
|
490 | *
|
491 | * // Prints 2 blob names
|
492 | * if (response.blobs) {
|
493 | * for (const blob of response.blobs) {
|
494 | * console.log(`Blob ${i++}: ${blob.name}`);
|
495 | * }
|
496 | * }
|
497 | *
|
498 | * // Gets next marker
|
499 | * let marker = response.continuationToken;
|
500 | * // Passing next marker as continuationToken
|
501 | * iterator = blobServiceClient
|
502 | * .findBlobsByTags("tagkey='tagvalue'")
|
503 | * .byPage({ continuationToken: marker, maxPageSize: 10 });
|
504 | * response = (await iterator.next()).value;
|
505 | *
|
506 | * // Prints blob names
|
507 | * if (response.blobs) {
|
508 | * for (const blob of response.blobs) {
|
509 | * console.log(`Blob ${i++}: ${blob.name}`);
|
510 | * }
|
511 | * }
|
512 | * ```
|
513 | *
|
514 | * @param tagFilterSqlExpression - The where parameter enables the caller to query blobs whose tags match a given expression.
|
515 | * The given expression must evaluate to true for a blob to be returned in the results.
|
516 | * The[OData - ABNF] filter syntax rule defines the formal grammar for the value of the where query parameter;
|
517 | * however, only a subset of the OData filter syntax is supported in the Blob service.
|
518 | * @param options - Options to find blobs by tags.
|
519 | */
|
520 | findBlobsByTags(tagFilterSqlExpression, options = {}) {
|
521 | // AsyncIterableIterator to iterate over blobs
|
522 | const listSegmentOptions = Object.assign({}, options);
|
523 | const iter = this.findBlobsByTagsItems(tagFilterSqlExpression, listSegmentOptions);
|
524 | return {
|
525 | /**
|
526 | * The next method, part of the iteration protocol
|
527 | */
|
528 | next() {
|
529 | return iter.next();
|
530 | },
|
531 | /**
|
532 | * The connection to the async iterator, part of the iteration protocol
|
533 | */
|
534 | [Symbol.asyncIterator]() {
|
535 | return this;
|
536 | },
|
537 | /**
|
538 | * Return an AsyncIterableIterator that works a page at a time
|
539 | */
|
540 | byPage: (settings = {}) => {
|
541 | return this.findBlobsByTagsSegments(tagFilterSqlExpression, settings.continuationToken, Object.assign({ maxPageSize: settings.maxPageSize }, listSegmentOptions));
|
542 | },
|
543 | };
|
544 | }
|
545 | /**
|
546 | * Returns an AsyncIterableIterator for ServiceListContainersSegmentResponses
|
547 | *
|
548 | * @param marker - A string value that identifies the portion of
|
549 | * the list of containers to be returned with the next listing operation. The
|
550 | * operation returns the continuationToken value within the response body if the
|
551 | * listing operation did not return all containers remaining to be listed
|
552 | * with the current page. The continuationToken value can be used as the value for
|
553 | * the marker parameter in a subsequent call to request the next page of list
|
554 | * items. The marker value is opaque to the client.
|
555 | * @param options - Options to list containers operation.
|
556 | */
|
557 | listSegments(marker, options = {}) {
|
558 | return __asyncGenerator(this, arguments, function* listSegments_1() {
|
559 | let listContainersSegmentResponse;
|
560 | if (!!marker || marker === undefined) {
|
561 | do {
|
562 | listContainersSegmentResponse = yield __await(this.listContainersSegment(marker, options));
|
563 | listContainersSegmentResponse.containerItems =
|
564 | listContainersSegmentResponse.containerItems || [];
|
565 | marker = listContainersSegmentResponse.continuationToken;
|
566 | yield yield __await(yield __await(listContainersSegmentResponse));
|
567 | } while (marker);
|
568 | }
|
569 | });
|
570 | }
|
571 | /**
|
572 | * Returns an AsyncIterableIterator for Container Items
|
573 | *
|
574 | * @param options - Options to list containers operation.
|
575 | */
|
576 | listItems(options = {}) {
|
577 | return __asyncGenerator(this, arguments, function* listItems_1() {
|
578 | var e_2, _a;
|
579 | let marker;
|
580 | try {
|
581 | for (var _b = __asyncValues(this.listSegments(marker, options)), _c; _c = yield __await(_b.next()), !_c.done;) {
|
582 | const segment = _c.value;
|
583 | yield __await(yield* __asyncDelegator(__asyncValues(segment.containerItems)));
|
584 | }
|
585 | }
|
586 | catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
587 | finally {
|
588 | try {
|
589 | if (_c && !_c.done && (_a = _b.return)) yield __await(_a.call(_b));
|
590 | }
|
591 | finally { if (e_2) throw e_2.error; }
|
592 | }
|
593 | });
|
594 | }
|
595 | /**
|
596 | * Returns an async iterable iterator to list all the containers
|
597 | * under the specified account.
|
598 | *
|
599 | * .byPage() returns an async iterable iterator to list the containers in pages.
|
600 | *
|
601 | * Example using `for await` syntax:
|
602 | *
|
603 | * ```js
|
604 | * let i = 1;
|
605 | * for await (const container of blobServiceClient.listContainers()) {
|
606 | * console.log(`Container ${i++}: ${container.name}`);
|
607 | * }
|
608 | * ```
|
609 | *
|
610 | * Example using `iter.next()`:
|
611 | *
|
612 | * ```js
|
613 | * let i = 1;
|
614 | * const iter = blobServiceClient.listContainers();
|
615 | * let containerItem = await iter.next();
|
616 | * while (!containerItem.done) {
|
617 | * console.log(`Container ${i++}: ${containerItem.value.name}`);
|
618 | * containerItem = await iter.next();
|
619 | * }
|
620 | * ```
|
621 | *
|
622 | * Example using `byPage()`:
|
623 | *
|
624 | * ```js
|
625 | * // passing optional maxPageSize in the page settings
|
626 | * let i = 1;
|
627 | * for await (const response of blobServiceClient.listContainers().byPage({ maxPageSize: 20 })) {
|
628 | * if (response.containerItems) {
|
629 | * for (const container of response.containerItems) {
|
630 | * console.log(`Container ${i++}: ${container.name}`);
|
631 | * }
|
632 | * }
|
633 | * }
|
634 | * ```
|
635 | *
|
636 | * Example using paging with a marker:
|
637 | *
|
638 | * ```js
|
639 | * let i = 1;
|
640 | * let iterator = blobServiceClient.listContainers().byPage({ maxPageSize: 2 });
|
641 | * let response = (await iterator.next()).value;
|
642 | *
|
643 | * // Prints 2 container names
|
644 | * if (response.containerItems) {
|
645 | * for (const container of response.containerItems) {
|
646 | * console.log(`Container ${i++}: ${container.name}`);
|
647 | * }
|
648 | * }
|
649 | *
|
650 | * // Gets next marker
|
651 | * let marker = response.continuationToken;
|
652 | * // Passing next marker as continuationToken
|
653 | * iterator = blobServiceClient
|
654 | * .listContainers()
|
655 | * .byPage({ continuationToken: marker, maxPageSize: 10 });
|
656 | * response = (await iterator.next()).value;
|
657 | *
|
658 | * // Prints 10 container names
|
659 | * if (response.containerItems) {
|
660 | * for (const container of response.containerItems) {
|
661 | * console.log(`Container ${i++}: ${container.name}`);
|
662 | * }
|
663 | * }
|
664 | * ```
|
665 | *
|
666 | * @param options - Options to list containers.
|
667 | * @returns An asyncIterableIterator that supports paging.
|
668 | */
|
669 | listContainers(options = {}) {
|
670 | if (options.prefix === "") {
|
671 | options.prefix = undefined;
|
672 | }
|
673 | const include = [];
|
674 | if (options.includeDeleted) {
|
675 | include.push("deleted");
|
676 | }
|
677 | if (options.includeMetadata) {
|
678 | include.push("metadata");
|
679 | }
|
680 | if (options.includeSystem) {
|
681 | include.push("system");
|
682 | }
|
683 | // AsyncIterableIterator to iterate over containers
|
684 | const listSegmentOptions = Object.assign(Object.assign({}, options), (include.length > 0 ? { include } : {}));
|
685 | const iter = this.listItems(listSegmentOptions);
|
686 | return {
|
687 | /**
|
688 | * The next method, part of the iteration protocol
|
689 | */
|
690 | next() {
|
691 | return iter.next();
|
692 | },
|
693 | /**
|
694 | * The connection to the async iterator, part of the iteration protocol
|
695 | */
|
696 | [Symbol.asyncIterator]() {
|
697 | return this;
|
698 | },
|
699 | /**
|
700 | * Return an AsyncIterableIterator that works a page at a time
|
701 | */
|
702 | byPage: (settings = {}) => {
|
703 | return this.listSegments(settings.continuationToken, Object.assign({ maxPageSize: settings.maxPageSize }, listSegmentOptions));
|
704 | },
|
705 | };
|
706 | }
|
707 | /**
|
708 | * ONLY AVAILABLE WHEN USING BEARER TOKEN AUTHENTICATION (TokenCredential).
|
709 | *
|
710 | * Retrieves a user delegation key for the Blob service. This is only a valid operation when using
|
711 | * bearer token authentication.
|
712 | *
|
713 | * @see https://docs.microsoft.com/en-us/rest/api/storageservices/get-user-delegation-key
|
714 | *
|
715 | * @param startsOn - The start time for the user delegation SAS. Must be within 7 days of the current time
|
716 | * @param expiresOn - The end time for the user delegation SAS. Must be within 7 days of the current time
|
717 | */
|
718 | async getUserDelegationKey(startsOn, expiresOn, options = {}) {
|
719 | const { span, updatedOptions } = createSpan("BlobServiceClient-getUserDelegationKey", options);
|
720 | try {
|
721 | const response = await this.serviceContext.getUserDelegationKey({
|
722 | startsOn: truncatedISO8061Date(startsOn, false),
|
723 | expiresOn: truncatedISO8061Date(expiresOn, false),
|
724 | }, Object.assign({ abortSignal: options.abortSignal }, convertTracingToRequestOptionsBase(updatedOptions)));
|
725 | const userDelegationKey = {
|
726 | signedObjectId: response.signedObjectId,
|
727 | signedTenantId: response.signedTenantId,
|
728 | signedStartsOn: new Date(response.signedStartsOn),
|
729 | signedExpiresOn: new Date(response.signedExpiresOn),
|
730 | signedService: response.signedService,
|
731 | signedVersion: response.signedVersion,
|
732 | value: response.value,
|
733 | };
|
734 | const res = Object.assign({ _response: response._response, requestId: response.requestId, clientRequestId: response.clientRequestId, version: response.version, date: response.date, errorCode: response.errorCode }, userDelegationKey);
|
735 | return res;
|
736 | }
|
737 | catch (e) {
|
738 | span.setStatus({
|
739 | code: SpanStatusCode.ERROR,
|
740 | message: e.message,
|
741 | });
|
742 | throw e;
|
743 | }
|
744 | finally {
|
745 | span.end();
|
746 | }
|
747 | }
|
748 | /**
|
749 | * Creates a BlobBatchClient object to conduct batch operations.
|
750 | *
|
751 | * @see https://docs.microsoft.com/en-us/rest/api/storageservices/blob-batch
|
752 | *
|
753 | * @returns A new BlobBatchClient object for this service.
|
754 | */
|
755 | getBlobBatchClient() {
|
756 | return new BlobBatchClient(this.url, this.pipeline);
|
757 | }
|
758 | /**
|
759 | * Only available for BlobServiceClient constructed with a shared key credential.
|
760 | *
|
761 | * Generates a Blob account Shared Access Signature (SAS) URI based on the client properties
|
762 | * and parameters passed in. The SAS is signed by the shared key credential of the client.
|
763 | *
|
764 | * @see https://docs.microsoft.com/en-us/rest/api/storageservices/create-account-sas
|
765 | *
|
766 | * @param expiresOn - Optional. The time at which the shared access signature becomes invalid. Default to an hour later if not provided.
|
767 | * @param permissions - Specifies the list of permissions to be associated with the SAS.
|
768 | * @param resourceTypes - Specifies the resource types associated with the shared access signature.
|
769 | * @param options - Optional parameters.
|
770 | * @returns An account SAS URI consisting of the URI to the resource represented by this client, followed by the generated SAS token.
|
771 | */
|
772 | generateAccountSasUrl(expiresOn, permissions = AccountSASPermissions.parse("r"), resourceTypes = "sco", options = {}) {
|
773 | if (!(this.credential instanceof StorageSharedKeyCredential)) {
|
774 | throw RangeError("Can only generate the account SAS when the client is initialized with a shared key credential");
|
775 | }
|
776 | if (expiresOn === undefined) {
|
777 | const now = new Date();
|
778 | expiresOn = new Date(now.getTime() + 3600 * 1000);
|
779 | }
|
780 | const sas = generateAccountSASQueryParameters(Object.assign({ permissions,
|
781 | expiresOn,
|
782 | resourceTypes, services: AccountSASServices.parse("b").toString() }, options), this.credential).toString();
|
783 | return appendToURLQuery(this.url, sas);
|
784 | }
|
785 | }
|
786 | //# sourceMappingURL=BlobServiceClient.js.map |
\ | No newline at end of file |