@google-cloud/storage
Advanced tools
Comparing version 4.7.0 to 5.0.0
@@ -16,2 +16,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.AclRoleAccessorMethods = exports.Acl = void 0; | ||
const promisify_1 = require("@google-cloud/promisify"); | ||
@@ -34,218 +35,221 @@ const arrify = require("arrify"); | ||
*/ | ||
class AclRoleAccessorMethods { | ||
constructor() { | ||
this.owners = {}; | ||
this.readers = {}; | ||
this.writers = {}; | ||
/** | ||
* An object of convenience methods to add or delete owner ACL permissions | ||
* for a given entity. | ||
* | ||
* The supported methods include: | ||
* | ||
* - `myFile.acl.owners.addAllAuthenticatedUsers` | ||
* - `myFile.acl.owners.deleteAllAuthenticatedUsers` | ||
* - `myFile.acl.owners.addAllUsers` | ||
* - `myFile.acl.owners.deleteAllUsers` | ||
* - `myFile.acl.owners.addDomain` | ||
* - `myFile.acl.owners.deleteDomain` | ||
* - `myFile.acl.owners.addGroup` | ||
* - `myFile.acl.owners.deleteGroup` | ||
* - `myFile.acl.owners.addProject` | ||
* - `myFile.acl.owners.deleteProject` | ||
* - `myFile.acl.owners.addUser` | ||
* - `myFile.acl.owners.deleteUser` | ||
* | ||
* @name Acl#owners | ||
* | ||
* @example | ||
* const storage = require('@google-cloud/storage')(); | ||
* const myBucket = storage.bucket('my-bucket'); | ||
* const myFile = myBucket.file('my-file'); | ||
* | ||
* //- | ||
* // Add a user as an owner of a file. | ||
* //- | ||
* const myBucket = gcs.bucket('my-bucket'); | ||
* const myFile = myBucket.file('my-file'); | ||
* myFile.acl.owners.addUser('email@example.com', function(err, aclObject) | ||
* {}); | ||
* | ||
* //- | ||
* // For reference, the above command is the same as running the following. | ||
* //- | ||
* myFile.acl.add({ | ||
* entity: 'user-email@example.com', | ||
* role: gcs.acl.OWNER_ROLE | ||
* }, function(err, aclObject) {}); | ||
* | ||
* //- | ||
* // If the callback is omitted, we'll return a Promise. | ||
* //- | ||
* myFile.acl.owners.addUser('email@example.com').then(function(data) { | ||
* const aclObject = data[0]; | ||
* const apiResponse = data[1]; | ||
* }); | ||
*/ | ||
this.owners = {}; | ||
/** | ||
* An object of convenience methods to add or delete reader ACL permissions | ||
* for a given entity. | ||
* | ||
* The supported methods include: | ||
* | ||
* - `myFile.acl.readers.addAllAuthenticatedUsers` | ||
* - `myFile.acl.readers.deleteAllAuthenticatedUsers` | ||
* - `myFile.acl.readers.addAllUsers` | ||
* - `myFile.acl.readers.deleteAllUsers` | ||
* - `myFile.acl.readers.addDomain` | ||
* - `myFile.acl.readers.deleteDomain` | ||
* - `myFile.acl.readers.addGroup` | ||
* - `myFile.acl.readers.deleteGroup` | ||
* - `myFile.acl.readers.addProject` | ||
* - `myFile.acl.readers.deleteProject` | ||
* - `myFile.acl.readers.addUser` | ||
* - `myFile.acl.readers.deleteUser` | ||
* | ||
* @name Acl#readers | ||
* | ||
* @example | ||
* const storage = require('@google-cloud/storage')(); | ||
* const myBucket = storage.bucket('my-bucket'); | ||
* const myFile = myBucket.file('my-file'); | ||
* | ||
* //- | ||
* // Add a user as a reader of a file. | ||
* //- | ||
* myFile.acl.readers.addUser('email@example.com', function(err, aclObject) | ||
* {}); | ||
* | ||
* //- | ||
* // For reference, the above command is the same as running the following. | ||
* //- | ||
* myFile.acl.add({ | ||
* entity: 'user-email@example.com', | ||
* role: gcs.acl.READER_ROLE | ||
* }, function(err, aclObject) {}); | ||
* | ||
* //- | ||
* // If the callback is omitted, we'll return a Promise. | ||
* //- | ||
* myFile.acl.readers.addUser('email@example.com').then(function(data) { | ||
* const aclObject = data[0]; | ||
* const apiResponse = data[1]; | ||
* }); | ||
*/ | ||
this.readers = {}; | ||
/** | ||
* An object of convenience methods to add or delete writer ACL permissions | ||
* for a given entity. | ||
* | ||
* The supported methods include: | ||
* | ||
* - `myFile.acl.writers.addAllAuthenticatedUsers` | ||
* - `myFile.acl.writers.deleteAllAuthenticatedUsers` | ||
* - `myFile.acl.writers.addAllUsers` | ||
* - `myFile.acl.writers.deleteAllUsers` | ||
* - `myFile.acl.writers.addDomain` | ||
* - `myFile.acl.writers.deleteDomain` | ||
* - `myFile.acl.writers.addGroup` | ||
* - `myFile.acl.writers.deleteGroup` | ||
* - `myFile.acl.writers.addProject` | ||
* - `myFile.acl.writers.deleteProject` | ||
* - `myFile.acl.writers.addUser` | ||
* - `myFile.acl.writers.deleteUser` | ||
* | ||
* @name Acl#writers | ||
* | ||
* @example | ||
* const storage = require('@google-cloud/storage')(); | ||
* const myBucket = storage.bucket('my-bucket'); | ||
* const myFile = myBucket.file('my-file'); | ||
* | ||
* //- | ||
* // Add a user as a writer of a file. | ||
* //- | ||
* myFile.acl.writers.addUser('email@example.com', function(err, aclObject) | ||
* {}); | ||
* | ||
* //- | ||
* // For reference, the above command is the same as running the following. | ||
* //- | ||
* myFile.acl.add({ | ||
* entity: 'user-email@example.com', | ||
* role: gcs.acl.WRITER_ROLE | ||
* }, function(err, aclObject) {}); | ||
* | ||
* //- | ||
* // If the callback is omitted, we'll return a Promise. | ||
* //- | ||
* myFile.acl.writers.addUser('email@example.com').then(function(data) { | ||
* const aclObject = data[0]; | ||
* const apiResponse = data[1]; | ||
* }); | ||
*/ | ||
this.writers = {}; | ||
AclRoleAccessorMethods.roles.forEach(this._assignAccessMethods.bind(this)); | ||
} | ||
_assignAccessMethods(role) { | ||
const accessMethods = AclRoleAccessorMethods.accessMethods; | ||
const entities = AclRoleAccessorMethods.entities; | ||
const roleGroup = role.toLowerCase() + 's'; | ||
// tslint:disable-next-line:no-any | ||
this[roleGroup] = entities.reduce((acc, entity) => { | ||
const isPrefix = entity.charAt(entity.length - 1) === '-'; | ||
accessMethods.forEach(accessMethod => { | ||
let method = accessMethod + entity[0].toUpperCase() + entity.substr(1); | ||
if (isPrefix) { | ||
method = method.replace('-', ''); | ||
} | ||
// Wrap the parent accessor method (e.g. `add` or `delete`) to avoid the | ||
// more complex API of specifying an `entity` and `role`. | ||
// tslint:disable-next-line:no-any | ||
acc[method] = (entityId, options, callback) => { | ||
let apiEntity; | ||
if (typeof options === 'function') { | ||
callback = options; | ||
options = {}; | ||
} | ||
let AclRoleAccessorMethods = /** @class */ (() => { | ||
class AclRoleAccessorMethods { | ||
constructor() { | ||
this.owners = {}; | ||
this.readers = {}; | ||
this.writers = {}; | ||
/** | ||
* An object of convenience methods to add or delete owner ACL permissions | ||
* for a given entity. | ||
* | ||
* The supported methods include: | ||
* | ||
* - `myFile.acl.owners.addAllAuthenticatedUsers` | ||
* - `myFile.acl.owners.deleteAllAuthenticatedUsers` | ||
* - `myFile.acl.owners.addAllUsers` | ||
* - `myFile.acl.owners.deleteAllUsers` | ||
* - `myFile.acl.owners.addDomain` | ||
* - `myFile.acl.owners.deleteDomain` | ||
* - `myFile.acl.owners.addGroup` | ||
* - `myFile.acl.owners.deleteGroup` | ||
* - `myFile.acl.owners.addProject` | ||
* - `myFile.acl.owners.deleteProject` | ||
* - `myFile.acl.owners.addUser` | ||
* - `myFile.acl.owners.deleteUser` | ||
* | ||
* @name Acl#owners | ||
* | ||
* @example | ||
* const storage = require('@google-cloud/storage')(); | ||
* const myBucket = storage.bucket('my-bucket'); | ||
* const myFile = myBucket.file('my-file'); | ||
* | ||
* //- | ||
* // Add a user as an owner of a file. | ||
* //- | ||
* const myBucket = gcs.bucket('my-bucket'); | ||
* const myFile = myBucket.file('my-file'); | ||
* myFile.acl.owners.addUser('email@example.com', function(err, aclObject) | ||
* {}); | ||
* | ||
* //- | ||
* // For reference, the above command is the same as running the following. | ||
* //- | ||
* myFile.acl.add({ | ||
* entity: 'user-email@example.com', | ||
* role: gcs.acl.OWNER_ROLE | ||
* }, function(err, aclObject) {}); | ||
* | ||
* //- | ||
* // If the callback is omitted, we'll return a Promise. | ||
* //- | ||
* myFile.acl.owners.addUser('email@example.com').then(function(data) { | ||
* const aclObject = data[0]; | ||
* const apiResponse = data[1]; | ||
* }); | ||
*/ | ||
this.owners = {}; | ||
/** | ||
* An object of convenience methods to add or delete reader ACL permissions | ||
* for a given entity. | ||
* | ||
* The supported methods include: | ||
* | ||
* - `myFile.acl.readers.addAllAuthenticatedUsers` | ||
* - `myFile.acl.readers.deleteAllAuthenticatedUsers` | ||
* - `myFile.acl.readers.addAllUsers` | ||
* - `myFile.acl.readers.deleteAllUsers` | ||
* - `myFile.acl.readers.addDomain` | ||
* - `myFile.acl.readers.deleteDomain` | ||
* - `myFile.acl.readers.addGroup` | ||
* - `myFile.acl.readers.deleteGroup` | ||
* - `myFile.acl.readers.addProject` | ||
* - `myFile.acl.readers.deleteProject` | ||
* - `myFile.acl.readers.addUser` | ||
* - `myFile.acl.readers.deleteUser` | ||
* | ||
* @name Acl#readers | ||
* | ||
* @example | ||
* const storage = require('@google-cloud/storage')(); | ||
* const myBucket = storage.bucket('my-bucket'); | ||
* const myFile = myBucket.file('my-file'); | ||
* | ||
* //- | ||
* // Add a user as a reader of a file. | ||
* //- | ||
* myFile.acl.readers.addUser('email@example.com', function(err, aclObject) | ||
* {}); | ||
* | ||
* //- | ||
* // For reference, the above command is the same as running the following. | ||
* //- | ||
* myFile.acl.add({ | ||
* entity: 'user-email@example.com', | ||
* role: gcs.acl.READER_ROLE | ||
* }, function(err, aclObject) {}); | ||
* | ||
* //- | ||
* // If the callback is omitted, we'll return a Promise. | ||
* //- | ||
* myFile.acl.readers.addUser('email@example.com').then(function(data) { | ||
* const aclObject = data[0]; | ||
* const apiResponse = data[1]; | ||
* }); | ||
*/ | ||
this.readers = {}; | ||
/** | ||
* An object of convenience methods to add or delete writer ACL permissions | ||
* for a given entity. | ||
* | ||
* The supported methods include: | ||
* | ||
* - `myFile.acl.writers.addAllAuthenticatedUsers` | ||
* - `myFile.acl.writers.deleteAllAuthenticatedUsers` | ||
* - `myFile.acl.writers.addAllUsers` | ||
* - `myFile.acl.writers.deleteAllUsers` | ||
* - `myFile.acl.writers.addDomain` | ||
* - `myFile.acl.writers.deleteDomain` | ||
* - `myFile.acl.writers.addGroup` | ||
* - `myFile.acl.writers.deleteGroup` | ||
* - `myFile.acl.writers.addProject` | ||
* - `myFile.acl.writers.deleteProject` | ||
* - `myFile.acl.writers.addUser` | ||
* - `myFile.acl.writers.deleteUser` | ||
* | ||
* @name Acl#writers | ||
* | ||
* @example | ||
* const storage = require('@google-cloud/storage')(); | ||
* const myBucket = storage.bucket('my-bucket'); | ||
* const myFile = myBucket.file('my-file'); | ||
* | ||
* //- | ||
* // Add a user as a writer of a file. | ||
* //- | ||
* myFile.acl.writers.addUser('email@example.com', function(err, aclObject) | ||
* {}); | ||
* | ||
* //- | ||
* // For reference, the above command is the same as running the following. | ||
* //- | ||
* myFile.acl.add({ | ||
* entity: 'user-email@example.com', | ||
* role: gcs.acl.WRITER_ROLE | ||
* }, function(err, aclObject) {}); | ||
* | ||
* //- | ||
* // If the callback is omitted, we'll return a Promise. | ||
* //- | ||
* myFile.acl.writers.addUser('email@example.com').then(function(data) { | ||
* const aclObject = data[0]; | ||
* const apiResponse = data[1]; | ||
* }); | ||
*/ | ||
this.writers = {}; | ||
AclRoleAccessorMethods.roles.forEach(this._assignAccessMethods.bind(this)); | ||
} | ||
_assignAccessMethods(role) { | ||
const accessMethods = AclRoleAccessorMethods.accessMethods; | ||
const entities = AclRoleAccessorMethods.entities; | ||
const roleGroup = role.toLowerCase() + 's'; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
this[roleGroup] = entities.reduce((acc, entity) => { | ||
const isPrefix = entity.charAt(entity.length - 1) === '-'; | ||
accessMethods.forEach(accessMethod => { | ||
let method = accessMethod + entity[0].toUpperCase() + entity.substr(1); | ||
if (isPrefix) { | ||
apiEntity = entity + entityId; | ||
method = method.replace('-', ''); | ||
} | ||
else { | ||
// If the entity is not a prefix, it is a special entity group | ||
// that does not require further details. The accessor methods | ||
// only accept a callback. | ||
apiEntity = entity; | ||
callback = entityId; | ||
} | ||
options = Object.assign({ | ||
entity: apiEntity, | ||
role, | ||
}, options); | ||
const args = [options]; | ||
if (typeof callback === 'function') { | ||
args.push(callback); | ||
} | ||
// tslint:disable-next-line:no-any | ||
return this[accessMethod].apply(this, args); | ||
}; | ||
}); | ||
return acc; | ||
}, {}); | ||
// Wrap the parent accessor method (e.g. `add` or `delete`) to avoid the | ||
// more complex API of specifying an `entity` and `role`. | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
acc[method] = (entityId, options, callback) => { | ||
let apiEntity; | ||
if (typeof options === 'function') { | ||
callback = options; | ||
options = {}; | ||
} | ||
if (isPrefix) { | ||
apiEntity = entity + entityId; | ||
} | ||
else { | ||
// If the entity is not a prefix, it is a special entity group | ||
// that does not require further details. The accessor methods | ||
// only accept a callback. | ||
apiEntity = entity; | ||
callback = entityId; | ||
} | ||
options = Object.assign({ | ||
entity: apiEntity, | ||
role, | ||
}, options); | ||
const args = [options]; | ||
if (typeof callback === 'function') { | ||
args.push(callback); | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
return this[accessMethod].apply(this, args); | ||
}; | ||
}); | ||
return acc; | ||
}, {}); | ||
} | ||
} | ||
} | ||
AclRoleAccessorMethods.accessMethods = ['add', 'delete']; | ||
AclRoleAccessorMethods.entities = [ | ||
// Special entity groups that do not require further specification. | ||
'allAuthenticatedUsers', | ||
'allUsers', | ||
// Entity groups that require specification, e.g. `user-email@example.com`. | ||
'domain-', | ||
'group-', | ||
'project-', | ||
'user-', | ||
]; | ||
AclRoleAccessorMethods.roles = ['OWNER', 'READER', 'WRITER']; | ||
return AclRoleAccessorMethods; | ||
})(); | ||
exports.AclRoleAccessorMethods = AclRoleAccessorMethods; | ||
AclRoleAccessorMethods.accessMethods = ['add', 'delete']; | ||
AclRoleAccessorMethods.entities = [ | ||
// Special entity groups that do not require further specification. | ||
'allAuthenticatedUsers', | ||
'allUsers', | ||
// Entity groups that require specification, e.g. `user-email@example.com`. | ||
'domain-', | ||
'group-', | ||
'project-', | ||
'user-', | ||
]; | ||
AclRoleAccessorMethods.roles = ['OWNER', 'READER', 'WRITER']; | ||
/** | ||
@@ -252,0 +256,0 @@ * Cloud Storage uses access control lists (ACLs) to manage object and |
@@ -100,4 +100,3 @@ /// <reference types="node" /> | ||
export declare type DeleteLabelsResponse = [Metadata]; | ||
export interface DeleteLabelsCallback extends SetLabelsCallback { | ||
} | ||
export declare type DeleteLabelsCallback = SetLabelsCallback; | ||
export declare type DisableRequesterPaysResponse = [Metadata]; | ||
@@ -115,4 +114,3 @@ export interface DisableRequesterPaysCallback { | ||
export declare type BucketExistsResponse = [boolean]; | ||
export interface BucketExistsCallback extends ExistsCallback { | ||
} | ||
export declare type BucketExistsCallback = ExistsCallback; | ||
export interface GetBucketOptions extends GetConfig { | ||
@@ -211,2 +209,3 @@ userProject?: string; | ||
resumable?: boolean; | ||
onUploadProgress?: (progressEvent: any) => void; | ||
} | ||
@@ -213,0 +212,0 @@ export interface MakeAllFilesPublicPrivateOptions { |
@@ -16,2 +16,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Channel = void 0; | ||
const common_1 = require("@google-cloud/common"); | ||
@@ -18,0 +19,0 @@ const promisify_1 = require("@google-cloud/promisify"); |
@@ -35,7 +35,5 @@ /// <reference types="node" /> | ||
} | ||
export interface GenerateSignedPostPolicyV2Options extends GetSignedPolicyOptions { | ||
} | ||
export declare type GenerateSignedPostPolicyV2Options = GetSignedPolicyOptions; | ||
export declare type GenerateSignedPostPolicyV2Response = GetSignedPolicyResponse; | ||
export interface GenerateSignedPostPolicyV2Callback extends GetSignedPolicyCallback { | ||
} | ||
export declare type GenerateSignedPostPolicyV2Callback = GetSignedPolicyCallback; | ||
export interface PolicyFields { | ||
@@ -128,4 +126,3 @@ [key: string]: string; | ||
export declare type MakeFilePrivateResponse = [Metadata]; | ||
export interface MakeFilePrivateCallback extends SetFileMetadataCallback { | ||
} | ||
export declare type MakeFilePrivateCallback = SetFileMetadataCallback; | ||
export interface IsPublicCallback { | ||
@@ -151,4 +148,3 @@ (err: Error | null, resp?: boolean): void; | ||
} | ||
export interface RotateEncryptionKeyCallback extends CopyCallback { | ||
} | ||
export declare type RotateEncryptionKeyCallback = CopyCallback; | ||
export declare type RotateEncryptionKeyResponse = CopyResponse; | ||
@@ -174,3 +170,2 @@ export declare enum ActionToHTTPMethod { | ||
destinationKmsKeyName?: string; | ||
keepAcl?: string; | ||
predefinedAcl?: string; | ||
@@ -197,2 +192,3 @@ token?: string; | ||
export interface SaveOptions extends CreateWriteStreamOptions { | ||
onUploadProgress?: (progressEvent: any) => void; | ||
} | ||
@@ -346,3 +342,3 @@ export interface SaveCallback { | ||
* For faster crc32c computation, you must manually install | ||
* [`fast-crc32c`](http://www.gitnpm.com/fast-crc32c): | ||
* [`fast-crc32c`](https://www.npmjs.com/package/fast-crc32c): | ||
* | ||
@@ -480,6 +476,6 @@ * $ npm install --save fast-crc32c | ||
* Resumable uploads require write access to the $HOME directory. Through | ||
* [`config-store`](http://www.gitnpm.com/configstore), some metadata is | ||
* stored. By default, if the directory is not writable, we will fall back to | ||
* a simple upload. However, if you explicitly request a resumable upload, and | ||
* we cannot write to the config directory, we will return a | ||
* [`config-store`](https://www.npmjs.com/package/configstore), some metadata | ||
* is stored. By default, if the directory is not writable, we will fall back | ||
* to a simple upload. However, if you explicitly request a resumable upload, | ||
* and we cannot write to the config directory, we will return a | ||
* `ResumableUploadError`. | ||
@@ -490,8 +486,8 @@ * | ||
* noticeable performance degradation while uploading a series of small | ||
* files. When uploading files less than 10MB, it is recommended that the | ||
* resumable feature is disabled. | ||
* files. When uploading files less than 10MB, it is recommended that the | ||
* resumable feature is disabled. | ||
* </p> | ||
* | ||
* For faster crc32c computation, you must manually install | ||
* [`fast-crc32c`](http://www.gitnpm.com/fast-crc32c): | ||
* [`fast-crc32c`](https://www.npmjs.com/package/fast-crc32c): | ||
* | ||
@@ -721,3 +717,2 @@ * $ npm install --save fast-crc32c | ||
} | ||
export declare function emitWarning(): void; | ||
/** | ||
@@ -724,0 +719,0 @@ * Reference to the {@link File} class. |
@@ -16,2 +16,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.HmacKey = void 0; | ||
const common_1 = require("@google-cloud/common"); | ||
@@ -18,0 +19,0 @@ /** |
@@ -16,2 +16,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Iam = void 0; | ||
const promisify_1 = require("@google-cloud/promisify"); | ||
@@ -131,3 +132,4 @@ const arrify = require("arrify"); | ||
} | ||
if (options.requestedPolicyVersion != null) { | ||
if (options.requestedPolicyVersion !== null && | ||
options.requestedPolicyVersion !== undefined) { | ||
qs.optionsRequestedPolicyVersion = options.requestedPolicyVersion; | ||
@@ -134,0 +136,0 @@ } |
@@ -17,15 +17,15 @@ "use strict"; | ||
var bucket_1 = require("./bucket"); | ||
exports.Bucket = bucket_1.Bucket; | ||
Object.defineProperty(exports, "Bucket", { enumerable: true, get: function () { return bucket_1.Bucket; } }); | ||
var channel_1 = require("./channel"); | ||
exports.Channel = channel_1.Channel; | ||
Object.defineProperty(exports, "Channel", { enumerable: true, get: function () { return channel_1.Channel; } }); | ||
var file_1 = require("./file"); | ||
exports.File = file_1.File; | ||
Object.defineProperty(exports, "File", { enumerable: true, get: function () { return file_1.File; } }); | ||
var hmacKey_1 = require("./hmacKey"); | ||
exports.HmacKey = hmacKey_1.HmacKey; | ||
Object.defineProperty(exports, "HmacKey", { enumerable: true, get: function () { return hmacKey_1.HmacKey; } }); | ||
var iam_1 = require("./iam"); | ||
exports.Iam = iam_1.Iam; | ||
Object.defineProperty(exports, "Iam", { enumerable: true, get: function () { return iam_1.Iam; } }); | ||
var notification_1 = require("./notification"); | ||
exports.Notification = notification_1.Notification; | ||
Object.defineProperty(exports, "Notification", { enumerable: true, get: function () { return notification_1.Notification; } }); | ||
var storage_1 = require("./storage"); | ||
exports.Storage = storage_1.Storage; | ||
Object.defineProperty(exports, "Storage", { enumerable: true, get: function () { return storage_1.Storage; } }); | ||
//# sourceMappingURL=index.js.map |
@@ -16,2 +16,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Notification = void 0; | ||
const common_1 = require("@google-cloud/common"); | ||
@@ -225,3 +226,3 @@ const promisify_1 = require("@google-cloud/promisify"); | ||
args.push(onCreate); | ||
// tslint:disable-next-line no-any | ||
// eslint-disable-next-line | ||
this.create.apply(this, args); | ||
@@ -228,0 +229,0 @@ return; |
@@ -16,2 +16,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SigningError = exports.URLSigner = exports.PATH_STYLED_HOST = void 0; | ||
const crypto = require("crypto"); | ||
@@ -73,3 +74,3 @@ const dateFormat = require("date-and-time"); | ||
signedUrl.pathname = this.getResourcePath(!!config.cname, this.bucket.name, config.file); | ||
// tslint:disable-next-line:no-any | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
signedUrl.search = util_1.qsStringify(query); | ||
@@ -145,4 +146,11 @@ return signedUrl.href; | ||
const dateISO = dateFormat.format(now, 'YYYYMMDD[T]HHmmss[Z]', true); | ||
const queryParams = Object.assign({ 'X-Goog-Algorithm': 'GOOG4-RSA-SHA256', 'X-Goog-Credential': credential, 'X-Goog-Date': dateISO, 'X-Goog-Expires': expiresPeriodInSeconds.toString(10), 'X-Goog-SignedHeaders': signedHeaders }, (config.queryParams || {})); | ||
// tslint:disable-next-line:no-any | ||
const queryParams = { | ||
'X-Goog-Algorithm': 'GOOG4-RSA-SHA256', | ||
'X-Goog-Credential': credential, | ||
'X-Goog-Date': dateISO, | ||
'X-Goog-Expires': expiresPeriodInSeconds.toString(10), | ||
'X-Goog-SignedHeaders': signedHeaders, | ||
...(config.queryParams || {}), | ||
}; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const canonicalQueryParams = this.getCanonicalQueryParams(queryParams); | ||
@@ -199,3 +207,3 @@ const canonicalRequest = this.getCanonicalRequest(config.method, this.getResourcePath(!!config.cname, config.bucket, config.file), canonicalQueryParams, extensionHeadersString, signedHeaders, contentSha256); | ||
return sortedHeaders | ||
.filter(([_, value]) => value !== undefined) | ||
.filter(([, value]) => value !== undefined) | ||
.map(([headerName, value]) => { | ||
@@ -202,0 +210,0 @@ // - Convert Array (multi-valued header) into string, delimited by |
@@ -16,2 +16,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Storage = void 0; | ||
const common_1 = require("@google-cloud/common"); | ||
@@ -47,684 +48,688 @@ const paginator_1 = require("@google-cloud/paginator"); | ||
*/ | ||
class Storage extends common_1.Service { | ||
/** | ||
* @typedef {object} StorageOptions | ||
* @property {string} [projectId] The project ID from the Google Developer's | ||
* Console, e.g. 'grape-spaceship-123'. We will also check the environment | ||
* variable `GCLOUD_PROJECT` for your project ID. If your app is running | ||
* in an environment which supports {@link | ||
* https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application | ||
* Application Default Credentials}, your project ID will be detected | ||
* automatically. | ||
* @property {string} [keyFilename] Full path to the a .json, .pem, or .p12 key | ||
* downloaded from the Google Developers Console. If you provide a path to | ||
* a JSON file, the `projectId` option above is not necessary. NOTE: .pem and | ||
* .p12 require you to specify the `email` option as well. | ||
* @property {string} [email] Account email address. Required when using a .pem | ||
* or .p12 keyFilename. | ||
* @property {object} [credentials] Credentials object. | ||
* @property {string} [credentials.client_email] | ||
* @property {string} [credentials.private_key] | ||
* @property {boolean} [autoRetry=true] Automatically retry requests if the | ||
* response is related to rate limits or certain intermittent server | ||
* errors. We will exponentially backoff subsequent requests by default. | ||
* @property {number} [maxRetries=3] Maximum number of automatic retries | ||
* attempted before returning the error. | ||
* @property {Constructor} [promise] Custom promise module to use instead of | ||
* native Promises. | ||
*/ | ||
/** | ||
* Constructs the Storage client. | ||
* | ||
* @example <caption>Create a client that uses Application Default Credentials | ||
* (ADC)</caption> const {Storage} = require('@google-cloud/storage'); const | ||
* storage = new Storage(); | ||
* | ||
* @example <caption>Create a client with explicit credentials</caption> | ||
* storage');/storage'); | ||
* const storage = new Storage({ | ||
* projectId: 'your-project-id', | ||
* keyFilename: '/path/to/keyfile.json' | ||
* }); | ||
* | ||
* @param {StorageOptions} [options] Configuration options. | ||
*/ | ||
constructor(options = {}) { | ||
options = Object.assign({}, options, { | ||
apiEndpoint: options.apiEndpoint || 'storage.googleapis.com', | ||
}); | ||
const url = process.env.STORAGE_EMULATOR_HOST || | ||
`https://${options.apiEndpoint}/storage/v1`; | ||
const config = { | ||
apiEndpoint: options.apiEndpoint, | ||
baseUrl: url, | ||
projectIdRequired: false, | ||
scopes: [ | ||
'https://www.googleapis.com/auth/iam', | ||
'https://www.googleapis.com/auth/cloud-platform', | ||
'https://www.googleapis.com/auth/devstorage.full_control', | ||
], | ||
packageJson: require('../../package.json'), | ||
}; | ||
super(config, options); | ||
let Storage = /** @class */ (() => { | ||
class Storage extends common_1.Service { | ||
/** | ||
* Reference to {@link Storage.acl}. | ||
* @typedef {object} StorageOptions | ||
* @property {string} [projectId] The project ID from the Google Developer's | ||
* Console, e.g. 'grape-spaceship-123'. We will also check the environment | ||
* variable `GCLOUD_PROJECT` for your project ID. If your app is running | ||
* in an environment which supports {@link | ||
* https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application | ||
* Application Default Credentials}, your project ID will be detected | ||
* automatically. | ||
* @property {string} [keyFilename] Full path to the a .json, .pem, or .p12 key | ||
* downloaded from the Google Developers Console. If you provide a path to | ||
* a JSON file, the `projectId` option above is not necessary. NOTE: .pem and | ||
* .p12 require you to specify the `email` option as well. | ||
* @property {string} [email] Account email address. Required when using a .pem | ||
* or .p12 keyFilename. | ||
* @property {object} [credentials] Credentials object. | ||
* @property {string} [credentials.client_email] | ||
* @property {string} [credentials.private_key] | ||
* @property {boolean} [autoRetry=true] Automatically retry requests if the | ||
* response is related to rate limits or certain intermittent server | ||
* errors. We will exponentially backoff subsequent requests by default. | ||
* @property {number} [maxRetries=3] Maximum number of automatic retries | ||
* attempted before returning the error. | ||
* @property {Constructor} [promise] Custom promise module to use instead of | ||
* native Promises. | ||
*/ | ||
/** | ||
* Constructs the Storage client. | ||
* | ||
* @name Storage#acl | ||
* @see Storage.acl | ||
* @example <caption>Create a client that uses Application Default Credentials | ||
* (ADC)</caption> const {Storage} = require('@google-cloud/storage'); const | ||
* storage = new Storage(); | ||
* | ||
* @example <caption>Create a client with explicit credentials</caption> | ||
* storage');/storage'); | ||
* const storage = new Storage({ | ||
* projectId: 'your-project-id', | ||
* keyFilename: '/path/to/keyfile.json' | ||
* }); | ||
* | ||
* @param {StorageOptions} [options] Configuration options. | ||
*/ | ||
this.acl = Storage.acl; | ||
this.getBucketsStream = paginator_1.paginator.streamify('getBuckets'); | ||
this.getHmacKeysStream = paginator_1.paginator.streamify('getHmacKeys'); | ||
} | ||
/** | ||
* Get a reference to a Cloud Storage bucket. | ||
* | ||
* @param {string} name Name of the bucket. | ||
* @param {object} [options] Configuration object. | ||
* @param {string} [options.kmsKeyName] A Cloud KMS key that will be used to | ||
* encrypt objects inserted into this bucket, if no encryption method is | ||
* specified. | ||
* @param {string} [options.userProject] User project to be billed for all | ||
* requests made from this Bucket object. | ||
* @returns {Bucket} | ||
* @see Bucket | ||
* | ||
* @example | ||
* const {Storage} = require('@google-cloud/storage'); | ||
* const storage = new Storage(); | ||
* const albums = storage.bucket('albums'); | ||
* const photos = storage.bucket('photos'); | ||
*/ | ||
bucket(name, options) { | ||
if (!name) { | ||
throw new Error('A bucket name is needed to use Cloud Storage.'); | ||
constructor(options = {}) { | ||
options = Object.assign({}, options, { | ||
apiEndpoint: options.apiEndpoint || 'storage.googleapis.com', | ||
}); | ||
const url = process.env.STORAGE_EMULATOR_HOST || | ||
`https://${options.apiEndpoint}/storage/v1`; | ||
const config = { | ||
apiEndpoint: options.apiEndpoint, | ||
baseUrl: url, | ||
projectIdRequired: false, | ||
scopes: [ | ||
'https://www.googleapis.com/auth/iam', | ||
'https://www.googleapis.com/auth/cloud-platform', | ||
'https://www.googleapis.com/auth/devstorage.full_control', | ||
], | ||
packageJson: require('../../package.json'), | ||
}; | ||
super(config, options); | ||
/** | ||
* Reference to {@link Storage.acl}. | ||
* | ||
* @name Storage#acl | ||
* @see Storage.acl | ||
*/ | ||
this.acl = Storage.acl; | ||
this.getBucketsStream = paginator_1.paginator.streamify('getBuckets'); | ||
this.getHmacKeysStream = paginator_1.paginator.streamify('getHmacKeys'); | ||
} | ||
return new bucket_1.Bucket(this, name, options); | ||
} | ||
/** | ||
* Reference a channel to receive notifications about changes to your bucket. | ||
* | ||
* @param {string} id The ID of the channel. | ||
* @param {string} resourceId The resource ID of the channel. | ||
* @returns {Channel} | ||
* @see Channel | ||
* | ||
* @example | ||
* const {Storage} = require('@google-cloud/storage'); | ||
* const storage = new Storage(); | ||
* const channel = storage.channel('id', 'resource-id'); | ||
*/ | ||
channel(id, resourceId) { | ||
return new channel_1.Channel(this, id, resourceId); | ||
} | ||
/** | ||
* @typedef {array} CreateBucketResponse | ||
* @property {Bucket} 0 The new {@link Bucket}. | ||
* @property {object} 1 The full API response. | ||
*/ | ||
/** | ||
* @callback CreateBucketCallback | ||
* @param {?Error} err Request error, if any. | ||
* @param {Bucket} bucket The new {@link Bucket}. | ||
* @param {object} apiResponse The full API response. | ||
*/ | ||
/** | ||
* Metadata to set for the bucket. | ||
* | ||
* @typedef {object} CreateBucketRequest | ||
* @property {boolean} [archive=false] Specify the storage class as Archive. | ||
* @property {boolean} [coldline=false] Specify the storage class as Coldline. | ||
* @property {Cors[]} [cors=[]] Specify the CORS configuration to use. | ||
* @property {boolean} [dra=false] Specify the storage class as Durable Reduced | ||
* Availability. | ||
* @property {boolean} [multiRegional=false] Specify the storage class as | ||
* Multi-Regional. | ||
* @property {boolean} [nearline=false] Specify the storage class as Nearline. | ||
* @property {boolean} [regional=false] Specify the storage class as Regional. | ||
* @property {boolean} [requesterPays=false] **Early Access Testers Only** | ||
* Force the use of the User Project metadata field to assign operational | ||
* costs when an operation is made on a Bucket and its objects. | ||
* @property {boolean} [standard=true] Specify the storage class as Standard. | ||
* @property {Versioning} [versioning=undefined] Specify the versioning status. | ||
* @property {string} [userProject] The ID of the project which will be billed | ||
* for the request. | ||
*/ | ||
/** | ||
* Create a bucket. | ||
* | ||
* Cloud Storage uses a flat namespace, so you can't create a bucket with | ||
* a name that is already in use. For more information, see | ||
* [Bucket Naming | ||
* Guidelines](https://cloud.google.com/storage/docs/bucketnaming.html#requirements). | ||
* | ||
* @see [Buckets: insert API Documentation]{@link https://cloud.google.com/storage/docs/json_api/v1/buckets/insert} | ||
* @see [Storage Classes]{@link https://cloud.google.com/storage/docs/storage-classes} | ||
* | ||
* @param {string} name Name of the bucket to create. | ||
* @param {CreateBucketRequest} [metadata] Metadata to set for the bucket. | ||
* @param {CreateBucketCallback} [callback] Callback function. | ||
* @returns {Promise<CreateBucketResponse>} | ||
* @throws {Error} If a name is not provided. | ||
* @see Bucket#create | ||
* | ||
* @example | ||
* const {Storage} = require('@google-cloud/storage'); | ||
* const storage = new Storage(); | ||
* const callback = function(err, bucket, apiResponse) { | ||
* // `bucket` is a Bucket object. | ||
* }; | ||
* | ||
* storage.createBucket('new-bucket', callback); | ||
* | ||
* //- | ||
* // Create a bucket in a specific location and region. <em>See the <a | ||
* // href="https://cloud.google.com/storage/docs/json_api/v1/buckets/insert"> | ||
* // Official JSON API docs</a> for complete details on the `location` | ||
* option. | ||
* // </em> | ||
* //- | ||
* const metadata = { | ||
* location: 'US-CENTRAL1', | ||
* regional: true | ||
* }; | ||
* | ||
* storage.createBucket('new-bucket', metadata, callback); | ||
* | ||
* //- | ||
* // Create a bucket with a retention policy of 6 months. | ||
* //- | ||
* const metadata = { | ||
* retentionPolicy: { | ||
* retentionPeriod: 15780000 // 6 months in seconds. | ||
* } | ||
* }; | ||
* | ||
* storage.createBucket('new-bucket', metadata, callback); | ||
* | ||
* //- | ||
* // Enable versioning on a new bucket. | ||
* //- | ||
* const metadata = { | ||
* versioning: { | ||
* enabled: true | ||
* } | ||
* }; | ||
* | ||
* storage.createBucket('new-bucket', metadata, callback); | ||
* | ||
* //- | ||
* // If the callback is omitted, we'll return a Promise. | ||
* //- | ||
* storage.createBucket('new-bucket').then(function(data) { | ||
* const bucket = data[0]; | ||
* const apiResponse = data[1]; | ||
* }); | ||
* | ||
* @example <caption>include:samples/buckets.js</caption> | ||
* region_tag:storage_create_bucket | ||
* Another example: | ||
*/ | ||
createBucket(name, metadataOrCallback, callback) { | ||
if (!name) { | ||
throw new Error('A name is required to create a bucket.'); | ||
/** | ||
* Get a reference to a Cloud Storage bucket. | ||
* | ||
* @param {string} name Name of the bucket. | ||
* @param {object} [options] Configuration object. | ||
* @param {string} [options.kmsKeyName] A Cloud KMS key that will be used to | ||
* encrypt objects inserted into this bucket, if no encryption method is | ||
* specified. | ||
* @param {string} [options.userProject] User project to be billed for all | ||
* requests made from this Bucket object. | ||
* @returns {Bucket} | ||
* @see Bucket | ||
* | ||
* @example | ||
* const {Storage} = require('@google-cloud/storage'); | ||
* const storage = new Storage(); | ||
* const albums = storage.bucket('albums'); | ||
* const photos = storage.bucket('photos'); | ||
*/ | ||
bucket(name, options) { | ||
if (!name) { | ||
throw new Error('A bucket name is needed to use Cloud Storage.'); | ||
} | ||
return new bucket_1.Bucket(this, name, options); | ||
} | ||
let metadata; | ||
if (!callback) { | ||
callback = metadataOrCallback; | ||
metadata = {}; | ||
/** | ||
* Reference a channel to receive notifications about changes to your bucket. | ||
* | ||
* @param {string} id The ID of the channel. | ||
* @param {string} resourceId The resource ID of the channel. | ||
* @returns {Channel} | ||
* @see Channel | ||
* | ||
* @example | ||
* const {Storage} = require('@google-cloud/storage'); | ||
* const storage = new Storage(); | ||
* const channel = storage.channel('id', 'resource-id'); | ||
*/ | ||
channel(id, resourceId) { | ||
return new channel_1.Channel(this, id, resourceId); | ||
} | ||
else { | ||
metadata = metadataOrCallback; | ||
} | ||
const body = Object.assign({}, metadata, { name }); | ||
const storageClasses = { | ||
archive: 'ARCHIVE', | ||
coldline: 'COLDLINE', | ||
dra: 'DURABLE_REDUCED_AVAILABILITY', | ||
multiRegional: 'MULTI_REGIONAL', | ||
nearline: 'NEARLINE', | ||
regional: 'REGIONAL', | ||
standard: 'STANDARD', | ||
}; | ||
Object.keys(storageClasses).forEach(storageClass => { | ||
if (body[storageClass]) { | ||
body.storageClass = storageClasses[storageClass]; | ||
delete body[storageClass]; | ||
/** | ||
* @typedef {array} CreateBucketResponse | ||
* @property {Bucket} 0 The new {@link Bucket}. | ||
* @property {object} 1 The full API response. | ||
*/ | ||
/** | ||
* @callback CreateBucketCallback | ||
* @param {?Error} err Request error, if any. | ||
* @param {Bucket} bucket The new {@link Bucket}. | ||
* @param {object} apiResponse The full API response. | ||
*/ | ||
/** | ||
* Metadata to set for the bucket. | ||
* | ||
* @typedef {object} CreateBucketRequest | ||
* @property {boolean} [archive=false] Specify the storage class as Archive. | ||
* @property {boolean} [coldline=false] Specify the storage class as Coldline. | ||
* @property {Cors[]} [cors=[]] Specify the CORS configuration to use. | ||
* @property {boolean} [dra=false] Specify the storage class as Durable Reduced | ||
* Availability. | ||
* @property {boolean} [multiRegional=false] Specify the storage class as | ||
* Multi-Regional. | ||
* @property {boolean} [nearline=false] Specify the storage class as Nearline. | ||
* @property {boolean} [regional=false] Specify the storage class as Regional. | ||
* @property {boolean} [requesterPays=false] **Early Access Testers Only** | ||
* Force the use of the User Project metadata field to assign operational | ||
* costs when an operation is made on a Bucket and its objects. | ||
* @property {boolean} [standard=true] Specify the storage class as Standard. | ||
* @property {Versioning} [versioning=undefined] Specify the versioning status. | ||
* @property {string} [userProject] The ID of the project which will be billed | ||
* for the request. | ||
*/ | ||
/** | ||
* Create a bucket. | ||
* | ||
* Cloud Storage uses a flat namespace, so you can't create a bucket with | ||
* a name that is already in use. For more information, see | ||
* [Bucket Naming | ||
* Guidelines](https://cloud.google.com/storage/docs/bucketnaming.html#requirements). | ||
* | ||
* @see [Buckets: insert API Documentation]{@link https://cloud.google.com/storage/docs/json_api/v1/buckets/insert} | ||
* @see [Storage Classes]{@link https://cloud.google.com/storage/docs/storage-classes} | ||
* | ||
* @param {string} name Name of the bucket to create. | ||
* @param {CreateBucketRequest} [metadata] Metadata to set for the bucket. | ||
* @param {CreateBucketCallback} [callback] Callback function. | ||
* @returns {Promise<CreateBucketResponse>} | ||
* @throws {Error} If a name is not provided. | ||
* @see Bucket#create | ||
* | ||
* @example | ||
* const {Storage} = require('@google-cloud/storage'); | ||
* const storage = new Storage(); | ||
* const callback = function(err, bucket, apiResponse) { | ||
* // `bucket` is a Bucket object. | ||
* }; | ||
* | ||
* storage.createBucket('new-bucket', callback); | ||
* | ||
* //- | ||
* // Create a bucket in a specific location and region. <em>See the <a | ||
* // href="https://cloud.google.com/storage/docs/json_api/v1/buckets/insert"> | ||
* // Official JSON API docs</a> for complete details on the `location` | ||
* option. | ||
* // </em> | ||
* //- | ||
* const metadata = { | ||
* location: 'US-CENTRAL1', | ||
* regional: true | ||
* }; | ||
* | ||
* storage.createBucket('new-bucket', metadata, callback); | ||
* | ||
* //- | ||
* // Create a bucket with a retention policy of 6 months. | ||
* //- | ||
* const metadata = { | ||
* retentionPolicy: { | ||
* retentionPeriod: 15780000 // 6 months in seconds. | ||
* } | ||
* }; | ||
* | ||
* storage.createBucket('new-bucket', metadata, callback); | ||
* | ||
* //- | ||
* // Enable versioning on a new bucket. | ||
* //- | ||
* const metadata = { | ||
* versioning: { | ||
* enabled: true | ||
* } | ||
* }; | ||
* | ||
* storage.createBucket('new-bucket', metadata, callback); | ||
* | ||
* //- | ||
* // If the callback is omitted, we'll return a Promise. | ||
* //- | ||
* storage.createBucket('new-bucket').then(function(data) { | ||
* const bucket = data[0]; | ||
* const apiResponse = data[1]; | ||
* }); | ||
* | ||
* @example <caption>include:samples/buckets.js</caption> | ||
* region_tag:storage_create_bucket | ||
* Another example: | ||
*/ | ||
createBucket(name, metadataOrCallback, callback) { | ||
if (!name) { | ||
throw new Error('A name is required to create a bucket.'); | ||
} | ||
}); | ||
if (body.requesterPays) { | ||
body.billing = { | ||
requesterPays: body.requesterPays, | ||
let metadata; | ||
if (!callback) { | ||
callback = metadataOrCallback; | ||
metadata = {}; | ||
} | ||
else { | ||
metadata = metadataOrCallback; | ||
} | ||
const body = Object.assign({}, metadata, { name }); | ||
const storageClasses = { | ||
archive: 'ARCHIVE', | ||
coldline: 'COLDLINE', | ||
dra: 'DURABLE_REDUCED_AVAILABILITY', | ||
multiRegional: 'MULTI_REGIONAL', | ||
nearline: 'NEARLINE', | ||
regional: 'REGIONAL', | ||
standard: 'STANDARD', | ||
}; | ||
delete body.requesterPays; | ||
Object.keys(storageClasses).forEach(storageClass => { | ||
if (body[storageClass]) { | ||
body.storageClass = storageClasses[storageClass]; | ||
delete body[storageClass]; | ||
} | ||
}); | ||
if (body.requesterPays) { | ||
body.billing = { | ||
requesterPays: body.requesterPays, | ||
}; | ||
delete body.requesterPays; | ||
} | ||
const query = { | ||
project: this.projectId, | ||
}; | ||
if (body.userProject) { | ||
query.userProject = body.userProject; | ||
delete body.userProject; | ||
} | ||
this.request({ | ||
method: 'POST', | ||
uri: '/b', | ||
qs: query, | ||
json: body, | ||
}, (err, resp) => { | ||
if (err) { | ||
callback(err, null, resp); | ||
return; | ||
} | ||
const bucket = this.bucket(name); | ||
bucket.metadata = resp; | ||
callback(null, bucket, resp); | ||
}); | ||
} | ||
const query = { | ||
project: this.projectId, | ||
}; | ||
if (body.userProject) { | ||
query.userProject = body.userProject; | ||
delete body.userProject; | ||
/** | ||
* @typedef {object} CreateHmacKeyOptions | ||
* @property {string} [projectId] The project ID of the project that owns | ||
* the service account of the requested HMAC key. If not provided, | ||
* the project ID used to instantiate the Storage client will be used. | ||
* @property {string} [userProject] This parameter is currently ignored. | ||
*/ | ||
/** | ||
* @typedef {object} HmacKeyMetadata | ||
* @property {string} accessId The access id identifies which HMAC key was | ||
* used to sign a request when authenticating with HMAC. | ||
* @property {string} etag Used to perform a read-modify-write of the key. | ||
* @property {string} id The resource name of the HMAC key. | ||
* @property {string} projectId The project ID. | ||
* @property {string} serviceAccountEmail The service account's email this | ||
* HMAC key is created for. | ||
* @property {string} state The state of this HMAC key. One of "ACTIVE", | ||
* "INACTIVE" or "DELETED". | ||
* @property {string} timeCreated The creation time of the HMAC key in | ||
* RFC 3339 format. | ||
* @property {string} [updated] The time this HMAC key was last updated in | ||
* RFC 3339 format. | ||
*/ | ||
/** | ||
* @typedef {array} CreateHmacKeyResponse | ||
* @property {HmacKey} 0 The HmacKey instance created from API response. | ||
* @property {string} 1 The HMAC key's secret used to access the XML API. | ||
* @property {object} 3 The raw API response. | ||
*/ | ||
/** | ||
* @callback CreateHmacKeyCallback Callback function. | ||
* @param {?Error} err Request error, if any. | ||
* @param {HmacKey} hmacKey The HmacKey instance created from API response. | ||
* @param {string} secret The HMAC key's secret used to access the XML API. | ||
* @param {object} apiResponse The raw API response. | ||
*/ | ||
/** | ||
* Create an HMAC key associated with an service account to authenticate | ||
* requests to the Cloud Storage XML API. | ||
* | ||
* @see [HMAC keys documentation]{@link https://cloud.google.com/storage/docs/authentication/hmackeys} | ||
* | ||
* @param {string} serviceAccountEmail The service account's email address | ||
* with which the HMAC key is created for. | ||
* @param {CreateHmacKeyCallback} [callback] Callback function. | ||
* @return {Promise<CreateHmacKeyResponse>} | ||
* | ||
* @example | ||
* const {Storage} = require('google-cloud/storage'); | ||
* const storage = new Storage(); | ||
* | ||
* // Replace with your service account's email address | ||
* const serviceAccountEmail = | ||
* 'my-service-account@appspot.gserviceaccount.com'; | ||
* | ||
* storage.createHmacKey(serviceAccountEmail, function(err, hmacKey, secret) { | ||
* if (!err) { | ||
* // Securely store the secret for use with the XML API. | ||
* } | ||
* }); | ||
* | ||
* //- | ||
* // If the callback is omitted, we'll return a Promise. | ||
* //- | ||
* storage.createHmacKey(serviceAccountEmail) | ||
* .then((response) => { | ||
* const hmacKey = response[0]; | ||
* const secret = response[1]; | ||
* // Securely store the secret for use with the XML API. | ||
* }); | ||
*/ | ||
createHmacKey(serviceAccountEmail, optionsOrCb, cb) { | ||
if (typeof serviceAccountEmail !== 'string') { | ||
throw new Error('The first argument must be a service account email to create an HMAC key.'); | ||
} | ||
const { options, callback } = util_1.normalize(optionsOrCb, cb); | ||
const query = Object.assign({}, options, { serviceAccountEmail }); | ||
const projectId = query.projectId || this.projectId; | ||
delete query.projectId; | ||
this.request({ | ||
method: 'POST', | ||
uri: `/projects/${projectId}/hmacKeys`, | ||
qs: query, | ||
}, (err, resp) => { | ||
if (err) { | ||
callback(err, null, null, resp); | ||
return; | ||
} | ||
const metadata = resp.metadata; | ||
const hmacKey = this.hmacKey(metadata.accessId, { | ||
projectId: metadata.projectId, | ||
}); | ||
hmacKey.metadata = resp.metadata; | ||
callback(null, hmacKey, resp.secret, resp); | ||
}); | ||
} | ||
this.request({ | ||
method: 'POST', | ||
uri: '/b', | ||
qs: query, | ||
json: body, | ||
}, (err, resp) => { | ||
if (err) { | ||
callback(err, null, resp); | ||
return; | ||
/** | ||
* Query object for listing buckets. | ||
* | ||
* @typedef {object} GetBucketsRequest | ||
* @property {boolean} [autoPaginate=true] Have pagination handled | ||
* automatically. | ||
* @property {number} [maxApiCalls] Maximum number of API calls to make. | ||
* @property {number} [maxResults] Maximum number of items plus prefixes to | ||
* return. | ||
* @property {string} [pageToken] A previously-returned page token | ||
* representing part of the larger set of results to view. | ||
* @property {string} [userProject] The ID of the project which will be billed | ||
* for the request. | ||
*/ | ||
/** | ||
* @typedef {array} GetBucketsResponse | ||
* @property {Bucket[]} 0 Array of {@link Bucket} instances. | ||
*/ | ||
/** | ||
* @callback GetBucketsCallback | ||
* @param {?Error} err Request error, if any. | ||
* @param {Bucket[]} buckets Array of {@link Bucket} instances. | ||
*/ | ||
/** | ||
* Get Bucket objects for all of the buckets in your project. | ||
* | ||
* @see [Buckets: list API Documentation]{@link https://cloud.google.com/storage/docs/json_api/v1/buckets/list} | ||
* | ||
* @param {GetBucketsRequest} [query] Query object for listing buckets. | ||
* @param {GetBucketsCallback} [callback] Callback function. | ||
* @returns {Promise<GetBucketsResponse>} | ||
* | ||
* @example | ||
* const {Storage} = require('@google-cloud/storage'); | ||
* const storage = new Storage(); | ||
* storage.getBuckets(function(err, buckets) { | ||
* if (!err) { | ||
* // buckets is an array of Bucket objects. | ||
* } | ||
* }); | ||
* | ||
* //- | ||
* // To control how many API requests are made and page through the results | ||
* // manually, set `autoPaginate` to `false`. | ||
* //- | ||
* const callback = function(err, buckets, nextQuery, apiResponse) { | ||
* if (nextQuery) { | ||
* // More results exist. | ||
* storage.getBuckets(nextQuery, callback); | ||
* } | ||
* | ||
* // The `metadata` property is populated for you with the metadata at the | ||
* // time of fetching. | ||
* buckets[0].metadata; | ||
* | ||
* // However, in cases where you are concerned the metadata could have | ||
* // changed, use the `getMetadata` method. | ||
* buckets[0].getMetadata(function(err, metadata, apiResponse) {}); | ||
* }; | ||
* | ||
* storage.getBuckets({ | ||
* autoPaginate: false | ||
* }, callback); | ||
* | ||
* //- | ||
* // If the callback is omitted, we'll return a Promise. | ||
* //- | ||
* storage.getBuckets().then(function(data) { | ||
* const buckets = data[0]; | ||
* }); | ||
* | ||
* @example <caption>include:samples/buckets.js</caption> | ||
* region_tag:storage_list_buckets | ||
* Another example: | ||
*/ | ||
getBuckets(optionsOrCallback, cb) { | ||
const { options, callback } = util_1.normalize(optionsOrCallback, cb); | ||
options.project = options.project || this.projectId; | ||
this.request({ | ||
uri: '/b', | ||
qs: options, | ||
}, (err, resp) => { | ||
if (err) { | ||
callback(err, null, null, resp); | ||
return; | ||
} | ||
const buckets = arrify(resp.items).map((bucket) => { | ||
const bucketInstance = this.bucket(bucket.id); | ||
bucketInstance.metadata = bucket; | ||
return bucketInstance; | ||
}); | ||
const nextQuery = resp.nextPageToken | ||
? Object.assign({}, options, { pageToken: resp.nextPageToken }) | ||
: null; | ||
callback(null, buckets, nextQuery, resp); | ||
}); | ||
} | ||
getHmacKeys(optionsOrCb, cb) { | ||
const { options, callback } = util_1.normalize(optionsOrCb, cb); | ||
const query = Object.assign({}, options); | ||
const projectId = query.projectId || this.projectId; | ||
delete query.projectId; | ||
this.request({ | ||
uri: `/projects/${projectId}/hmacKeys`, | ||
qs: query, | ||
}, (err, resp) => { | ||
if (err) { | ||
callback(err, null, null, resp); | ||
return; | ||
} | ||
const hmacKeys = arrify(resp.items).map((hmacKey) => { | ||
const hmacKeyInstance = this.hmacKey(hmacKey.accessId, { | ||
projectId: hmacKey.projectId, | ||
}); | ||
hmacKeyInstance.metadata = hmacKey; | ||
return hmacKeyInstance; | ||
}); | ||
const nextQuery = resp.nextPageToken | ||
? Object.assign({}, options, { pageToken: resp.nextPageToken }) | ||
: null; | ||
callback(null, hmacKeys, nextQuery, resp); | ||
}); | ||
} | ||
/** | ||
* @typedef {array} GetServiceAccountResponse | ||
* @property {object} 0 The service account resource. | ||
* @property {object} 1 The full | ||
* [API | ||
* response](https://cloud.google.com/storage/docs/json_api/v1/projects/serviceAccount#resource). | ||
*/ | ||
/** | ||
* @callback GetServiceAccountCallback | ||
* @param {?Error} err Request error, if any. | ||
* @param {object} serviceAccount The serviceAccount resource. | ||
* @param {string} serviceAccount.emailAddress The service account email | ||
* address. | ||
* @param {object} apiResponse The full | ||
* [API | ||
* response](https://cloud.google.com/storage/docs/json_api/v1/projects/serviceAccount#resource). | ||
*/ | ||
/** | ||
* Get the email address of this project's Google Cloud Storage service | ||
* account. | ||
* | ||
* @see [Projects.serviceAccount: get API Documentation]{@link https://cloud.google.com/storage/docs/json_api/v1/projects/serviceAccount/get} | ||
* @see [Projects.serviceAccount Resource]{@link https://cloud.google.com/storage/docs/json_api/v1/projects/serviceAccount#resource} | ||
* | ||
* @param {object} [options] Configuration object. | ||
* @param {string} [options.userProject] User project to be billed for this | ||
* request. | ||
* @param {GetServiceAccountCallback} [callback] Callback function. | ||
* @returns {Promise<GetServiceAccountResponse>} | ||
* | ||
* @example | ||
* const {Storage} = require('@google-cloud/storage'); | ||
* const storage = new Storage(); | ||
* | ||
* storage.getServiceAccount(function(err, serviceAccount, apiResponse) { | ||
* if (!err) { | ||
* const serviceAccountEmail = serviceAccount.emailAddress; | ||
* } | ||
* }); | ||
* | ||
* //- | ||
* // If the callback is omitted, we'll return a Promise. | ||
* //- | ||
* storage.getServiceAccount().then(function(data) { | ||
* const serviceAccountEmail = data[0].emailAddress; | ||
* const apiResponse = data[1]; | ||
* }); | ||
*/ | ||
getServiceAccount(optionsOrCallback, cb) { | ||
const { options, callback } = util_1.normalize(optionsOrCallback, cb); | ||
this.request({ | ||
uri: `/projects/${this.projectId}/serviceAccount`, | ||
qs: options, | ||
}, (err, resp) => { | ||
if (err) { | ||
callback(err, null, resp); | ||
return; | ||
} | ||
const camelCaseResponse = {}; | ||
for (const prop in resp) { | ||
// eslint-disable-next-line no-prototype-builtins | ||
if (resp.hasOwnProperty(prop)) { | ||
const camelCaseProp = prop.replace(/_(\w)/g, (_, match) => match.toUpperCase()); | ||
camelCaseResponse[camelCaseProp] = resp[prop]; | ||
} | ||
} | ||
callback(null, camelCaseResponse, resp); | ||
}); | ||
} | ||
/** | ||
* Get a reference to an HmacKey object. | ||
* Note: this does not fetch the HMAC key's metadata. Use HmacKey#get() to | ||
* retrieve and populate the metadata. | ||
* | ||
* To get a reference to an HMAC key that's not created for a service | ||
* account in the same project used to instantiate the Storage client, | ||
* supply the project's ID as `projectId` in the `options` argument. | ||
* | ||
* @param {string} accessId The HMAC key's access ID. | ||
* @param {HmacKeyOptions} options HmacKey constructor owptions. | ||
* @returns {HmacKey} | ||
* @see HmacKey | ||
* | ||
* @example | ||
* const {Storage} = require('@google-cloud/storage'); | ||
* const storage = new Storage(); | ||
* const hmacKey = storage.hmacKey('ACCESS_ID'); | ||
*/ | ||
hmacKey(accessId, options) { | ||
if (!accessId) { | ||
throw new Error('An access ID is needed to create an HmacKey object.'); | ||
} | ||
const bucket = this.bucket(name); | ||
bucket.metadata = resp; | ||
callback(null, bucket, resp); | ||
}); | ||
return new hmacKey_1.HmacKey(this, accessId, options); | ||
} | ||
} | ||
/** | ||
* @typedef {object} CreateHmacKeyOptions | ||
* @property {string} [projectId] The project ID of the project that owns | ||
* the service account of the requested HMAC key. If not provided, | ||
* the project ID used to instantiate the Storage client will be used. | ||
* @property {string} [userProject] This parameter is currently ignored. | ||
* {@link Bucket} class. | ||
* | ||
* @name Storage.Bucket | ||
* @see Bucket | ||
* @type {Constructor} | ||
*/ | ||
Storage.Bucket = bucket_1.Bucket; | ||
/** | ||
* @typedef {object} HmacKeyMetadata | ||
* @property {string} accessId The access id identifies which HMAC key was | ||
* used to sign a request when authenticating with HMAC. | ||
* @property {string} etag Used to perform a read-modify-write of the key. | ||
* @property {string} id The resource name of the HMAC key. | ||
* @property {string} projectId The project ID. | ||
* @property {string} serviceAccountEmail The service account's email this | ||
* HMAC key is created for. | ||
* @property {string} state The state of this HMAC key. One of "ACTIVE", | ||
* "INACTIVE" or "DELETED". | ||
* @property {string} timeCreated The creation time of the HMAC key in | ||
* RFC 3339 format. | ||
* @property {string} [updated] The time this HMAC key was last updated in | ||
* RFC 3339 format. | ||
* {@link Channel} class. | ||
* | ||
* @name Storage.Channel | ||
* @see Channel | ||
* @type {Constructor} | ||
*/ | ||
Storage.Channel = channel_1.Channel; | ||
/** | ||
* @typedef {array} CreateHmacKeyResponse | ||
* @property {HmacKey} 0 The HmacKey instance created from API response. | ||
* @property {string} 1 The HMAC key's secret used to access the XML API. | ||
* @property {object} 3 The raw API response. | ||
* {@link File} class. | ||
* | ||
* @name Storage.File | ||
* @see File | ||
* @type {Constructor} | ||
*/ | ||
Storage.File = file_1.File; | ||
/** | ||
* @callback CreateHmacKeyCallback Callback function. | ||
* @param {?Error} err Request error, if any. | ||
* @param {HmacKey} hmacKey The HmacKey instance created from API response. | ||
* @param {string} secret The HMAC key's secret used to access the XML API. | ||
* @param {object} apiResponse The raw API response. | ||
* {@link HmacKey} class. | ||
* | ||
* @name Storage.HmacKey | ||
* @see HmacKey | ||
* @type {Constructor} | ||
*/ | ||
Storage.HmacKey = hmacKey_1.HmacKey; | ||
/** | ||
* Create an HMAC key associated with an service account to authenticate | ||
* requests to the Cloud Storage XML API. | ||
* Cloud Storage uses access control lists (ACLs) to manage object and | ||
* bucket access. ACLs are the mechanism you use to share objects with other | ||
* users and allow other users to access your buckets and objects. | ||
* | ||
* @see [HMAC keys documentation]{@link https://cloud.google.com/storage/docs/authentication/hmackeys} | ||
* This object provides constants to refer to the three permission levels that | ||
* can be granted to an entity: | ||
* | ||
* @param {string} serviceAccountEmail The service account's email address | ||
* with which the HMAC key is created for. | ||
* @param {CreateHmacKeyCallback} [callback] Callback function. | ||
* @return {Promise<CreateHmacKeyResponse>} | ||
* - `gcs.acl.OWNER_ROLE` - ("OWNER") | ||
* - `gcs.acl.READER_ROLE` - ("READER") | ||
* - `gcs.acl.WRITER_ROLE` - ("WRITER") | ||
* | ||
* @example | ||
* const {Storage} = require('google-cloud/storage'); | ||
* const storage = new Storage(); | ||
* @see [About Access Control Lists]{@link https://cloud.google.com/storage/docs/access-control/lists} | ||
* | ||
* // Replace with your service account's email address | ||
* const serviceAccountEmail = | ||
* 'my-service-account@appspot.gserviceaccount.com'; | ||
* @name Storage.acl | ||
* @type {object} | ||
* @property {string} OWNER_ROLE | ||
* @property {string} READER_ROLE | ||
* @property {string} WRITER_ROLE | ||
* | ||
* storage.createHmacKey(serviceAccountEmail, function(err, hmacKey, secret) { | ||
* if (!err) { | ||
* // Securely store the secret for use with the XML API. | ||
* } | ||
* }); | ||
* | ||
* //- | ||
* // If the callback is omitted, we'll return a Promise. | ||
* //- | ||
* storage.createHmacKey(serviceAccountEmail) | ||
* .then((response) => { | ||
* const hmacKey = response[0]; | ||
* const secret = response[1]; | ||
* // Securely store the secret for use with the XML API. | ||
* }); | ||
*/ | ||
createHmacKey(serviceAccountEmail, optionsOrCb, cb) { | ||
if (typeof serviceAccountEmail !== 'string') { | ||
throw new Error('The first argument must be a service account email to create an HMAC key.'); | ||
} | ||
const { options, callback } = util_1.normalize(optionsOrCb, cb); | ||
const query = Object.assign({}, options, { serviceAccountEmail }); | ||
const projectId = query.projectId || this.projectId; | ||
delete query.projectId; | ||
this.request({ | ||
method: 'POST', | ||
uri: `/projects/${projectId}/hmacKeys`, | ||
qs: query, | ||
}, (err, resp) => { | ||
if (err) { | ||
callback(err, null, null, resp); | ||
return; | ||
} | ||
const metadata = resp.metadata; | ||
const hmacKey = this.hmacKey(metadata.accessId, { | ||
projectId: metadata.projectId, | ||
}); | ||
hmacKey.metadata = resp.metadata; | ||
callback(null, hmacKey, resp.secret, resp); | ||
}); | ||
} | ||
/** | ||
* Query object for listing buckets. | ||
* | ||
* @typedef {object} GetBucketsRequest | ||
* @property {boolean} [autoPaginate=true] Have pagination handled | ||
* automatically. | ||
* @property {number} [maxApiCalls] Maximum number of API calls to make. | ||
* @property {number} [maxResults] Maximum number of items plus prefixes to | ||
* return. | ||
* @property {string} [pageToken] A previously-returned page token | ||
* representing part of the larger set of results to view. | ||
* @property {string} [userProject] The ID of the project which will be billed | ||
* for the request. | ||
*/ | ||
/** | ||
* @typedef {array} GetBucketsResponse | ||
* @property {Bucket[]} 0 Array of {@link Bucket} instances. | ||
*/ | ||
/** | ||
* @callback GetBucketsCallback | ||
* @param {?Error} err Request error, if any. | ||
* @param {Bucket[]} buckets Array of {@link Bucket} instances. | ||
*/ | ||
/** | ||
* Get Bucket objects for all of the buckets in your project. | ||
* | ||
* @see [Buckets: list API Documentation]{@link https://cloud.google.com/storage/docs/json_api/v1/buckets/list} | ||
* | ||
* @param {GetBucketsRequest} [query] Query object for listing buckets. | ||
* @param {GetBucketsCallback} [callback] Callback function. | ||
* @returns {Promise<GetBucketsResponse>} | ||
* | ||
* @example | ||
* const {Storage} = require('@google-cloud/storage'); | ||
* const storage = new Storage(); | ||
* storage.getBuckets(function(err, buckets) { | ||
* if (!err) { | ||
* // buckets is an array of Bucket objects. | ||
* } | ||
* }); | ||
* const albums = storage.bucket('albums'); | ||
* | ||
* //- | ||
* // To control how many API requests are made and page through the results | ||
* // manually, set `autoPaginate` to `false`. | ||
* // Make all of the files currently in a bucket publicly readable. | ||
* //- | ||
* const callback = function(err, buckets, nextQuery, apiResponse) { | ||
* if (nextQuery) { | ||
* // More results exist. | ||
* storage.getBuckets(nextQuery, callback); | ||
* } | ||
* | ||
* // The `metadata` property is populated for you with the metadata at the | ||
* // time of fetching. | ||
* buckets[0].metadata; | ||
* | ||
* // However, in cases where you are concerned the metadata could have | ||
* // changed, use the `getMetadata` method. | ||
* buckets[0].getMetadata(function(err, metadata, apiResponse) {}); | ||
* const options = { | ||
* entity: 'allUsers', | ||
* role: storage.acl.READER_ROLE | ||
* }; | ||
* | ||
* storage.getBuckets({ | ||
* autoPaginate: false | ||
* }, callback); | ||
* albums.acl.add(options, function(err, aclObject) {}); | ||
* | ||
* //- | ||
* // If the callback is omitted, we'll return a Promise. | ||
* // Make any new objects added to a bucket publicly readable. | ||
* //- | ||
* storage.getBuckets().then(function(data) { | ||
* const buckets = data[0]; | ||
* }); | ||
* albums.acl.default.add(options, function(err, aclObject) {}); | ||
* | ||
* @example <caption>include:samples/buckets.js</caption> | ||
* region_tag:storage_list_buckets | ||
* Another example: | ||
*/ | ||
getBuckets(optionsOrCallback, cb) { | ||
const { options, callback } = util_1.normalize(optionsOrCallback, cb); | ||
options.project = options.project || this.projectId; | ||
this.request({ | ||
uri: '/b', | ||
qs: options, | ||
}, (err, resp) => { | ||
if (err) { | ||
callback(err, null, null, resp); | ||
return; | ||
} | ||
const buckets = arrify(resp.items).map((bucket) => { | ||
const bucketInstance = this.bucket(bucket.id); | ||
bucketInstance.metadata = bucket; | ||
return bucketInstance; | ||
}); | ||
const nextQuery = resp.nextPageToken | ||
? Object.assign({}, options, { pageToken: resp.nextPageToken }) | ||
: null; | ||
callback(null, buckets, nextQuery, resp); | ||
}); | ||
} | ||
getHmacKeys(optionsOrCb, cb) { | ||
const { options, callback } = util_1.normalize(optionsOrCb, cb); | ||
const query = Object.assign({}, options); | ||
const projectId = query.projectId || this.projectId; | ||
delete query.projectId; | ||
this.request({ | ||
uri: `/projects/${projectId}/hmacKeys`, | ||
qs: query, | ||
}, (err, resp) => { | ||
if (err) { | ||
callback(err, null, null, resp); | ||
return; | ||
} | ||
const hmacKeys = arrify(resp.items).map((hmacKey) => { | ||
const hmacKeyInstance = this.hmacKey(hmacKey.accessId, { | ||
projectId: hmacKey.projectId, | ||
}); | ||
hmacKeyInstance.metadata = hmacKey; | ||
return hmacKeyInstance; | ||
}); | ||
const nextQuery = resp.nextPageToken | ||
? Object.assign({}, options, { pageToken: resp.nextPageToken }) | ||
: null; | ||
callback(null, hmacKeys, nextQuery, resp); | ||
}); | ||
} | ||
/** | ||
* @typedef {array} GetServiceAccountResponse | ||
* @property {object} 0 The service account resource. | ||
* @property {object} 1 The full | ||
* [API | ||
* response](https://cloud.google.com/storage/docs/json_api/v1/projects/serviceAccount#resource). | ||
*/ | ||
/** | ||
* @callback GetServiceAccountCallback | ||
* @param {?Error} err Request error, if any. | ||
* @param {object} serviceAccount The serviceAccount resource. | ||
* @param {string} serviceAccount.emailAddress The service account email | ||
* address. | ||
* @param {object} apiResponse The full | ||
* [API | ||
* response](https://cloud.google.com/storage/docs/json_api/v1/projects/serviceAccount#resource). | ||
*/ | ||
/** | ||
* Get the email address of this project's Google Cloud Storage service | ||
* account. | ||
* //- | ||
* // Grant a user ownership permissions to a bucket. | ||
* //- | ||
* albums.acl.add({ | ||
* entity: 'user-useremail@example.com', | ||
* role: storage.acl.OWNER_ROLE | ||
* }, function(err, aclObject) {}); | ||
* | ||
* @see [Projects.serviceAccount: get API Documentation]{@link https://cloud.google.com/storage/docs/json_api/v1/projects/serviceAccount/get} | ||
* @see [Projects.serviceAccount Resource]{@link https://cloud.google.com/storage/docs/json_api/v1/projects/serviceAccount#resource} | ||
* | ||
* @param {object} [options] Configuration object. | ||
* @param {string} [options.userProject] User project to be billed for this | ||
* request. | ||
* @param {GetServiceAccountCallback} [callback] Callback function. | ||
* @returns {Promise<GetServiceAccountResponse>} | ||
* | ||
* @example | ||
* const {Storage} = require('@google-cloud/storage'); | ||
* const storage = new Storage(); | ||
* | ||
* storage.getServiceAccount(function(err, serviceAccount, apiResponse) { | ||
* if (!err) { | ||
* const serviceAccountEmail = serviceAccount.emailAddress; | ||
* } | ||
* }); | ||
* | ||
* //- | ||
* // If the callback is omitted, we'll return a Promise. | ||
* //- | ||
* storage.getServiceAccount().then(function(data) { | ||
* const serviceAccountEmail = data[0].emailAddress; | ||
* albums.acl.add(options).then(function(data) { | ||
* const aclObject = data[0]; | ||
* const apiResponse = data[1]; | ||
* }); | ||
*/ | ||
getServiceAccount(optionsOrCallback, cb) { | ||
const { options, callback } = util_1.normalize(optionsOrCallback, cb); | ||
this.request({ | ||
uri: `/projects/${this.projectId}/serviceAccount`, | ||
qs: options, | ||
}, (err, resp) => { | ||
if (err) { | ||
callback(err, null, resp); | ||
return; | ||
} | ||
const camelCaseResponse = {}; | ||
for (const prop in resp) { | ||
if (resp.hasOwnProperty(prop)) { | ||
const camelCaseProp = prop.replace(/_(\w)/g, (_, match) => match.toUpperCase()); | ||
camelCaseResponse[camelCaseProp] = resp[prop]; | ||
} | ||
} | ||
callback(null, camelCaseResponse, resp); | ||
}); | ||
} | ||
/** | ||
* Get a reference to an HmacKey object. | ||
* Note: this does not fetch the HMAC key's metadata. Use HmacKey#get() to | ||
* retrieve and populate the metadata. | ||
* | ||
* To get a reference to an HMAC key that's not created for a service | ||
* account in the same project used to instantiate the Storage client, | ||
* supply the project's ID as `projectId` in the `options` argument. | ||
* | ||
* @param {string} accessId The HMAC key's access ID. | ||
* @param {HmacKeyOptions} options HmacKey constructor owptions. | ||
* @returns {HmacKey} | ||
* @see HmacKey | ||
* | ||
* @example | ||
* const {Storage} = require('@google-cloud/storage'); | ||
* const storage = new Storage(); | ||
* const hmacKey = storage.hmacKey('ACCESS_ID'); | ||
*/ | ||
hmacKey(accessId, options) { | ||
if (!accessId) { | ||
throw new Error('An access ID is needed to create an HmacKey object.'); | ||
} | ||
return new hmacKey_1.HmacKey(this, accessId, options); | ||
} | ||
} | ||
Storage.acl = { | ||
OWNER_ROLE: 'OWNER', | ||
READER_ROLE: 'READER', | ||
WRITER_ROLE: 'WRITER', | ||
}; | ||
return Storage; | ||
})(); | ||
exports.Storage = Storage; | ||
/** | ||
* {@link Bucket} class. | ||
* | ||
* @name Storage.Bucket | ||
* @see Bucket | ||
* @type {Constructor} | ||
*/ | ||
Storage.Bucket = bucket_1.Bucket; | ||
/** | ||
* {@link Channel} class. | ||
* | ||
* @name Storage.Channel | ||
* @see Channel | ||
* @type {Constructor} | ||
*/ | ||
Storage.Channel = channel_1.Channel; | ||
/** | ||
* {@link File} class. | ||
* | ||
* @name Storage.File | ||
* @see File | ||
* @type {Constructor} | ||
*/ | ||
Storage.File = file_1.File; | ||
/** | ||
* {@link HmacKey} class. | ||
* | ||
* @name Storage.HmacKey | ||
* @see HmacKey | ||
* @type {Constructor} | ||
*/ | ||
Storage.HmacKey = hmacKey_1.HmacKey; | ||
/** | ||
* Cloud Storage uses access control lists (ACLs) to manage object and | ||
* bucket access. ACLs are the mechanism you use to share objects with other | ||
* users and allow other users to access your buckets and objects. | ||
* | ||
* This object provides constants to refer to the three permission levels that | ||
* can be granted to an entity: | ||
* | ||
* - `gcs.acl.OWNER_ROLE` - ("OWNER") | ||
* - `gcs.acl.READER_ROLE` - ("READER") | ||
* - `gcs.acl.WRITER_ROLE` - ("WRITER") | ||
* | ||
* @see [About Access Control Lists]{@link https://cloud.google.com/storage/docs/access-control/lists} | ||
* | ||
* @name Storage.acl | ||
* @type {object} | ||
* @property {string} OWNER_ROLE | ||
* @property {string} READER_ROLE | ||
* @property {string} WRITER_ROLE | ||
* | ||
* @example | ||
* const {Storage} = require('@google-cloud/storage'); | ||
* const storage = new Storage(); | ||
* const albums = storage.bucket('albums'); | ||
* | ||
* //- | ||
* // Make all of the files currently in a bucket publicly readable. | ||
* //- | ||
* const options = { | ||
* entity: 'allUsers', | ||
* role: storage.acl.READER_ROLE | ||
* }; | ||
* | ||
* albums.acl.add(options, function(err, aclObject) {}); | ||
* | ||
* //- | ||
* // Make any new objects added to a bucket publicly readable. | ||
* //- | ||
* albums.acl.default.add(options, function(err, aclObject) {}); | ||
* | ||
* //- | ||
* // Grant a user ownership permissions to a bucket. | ||
* //- | ||
* albums.acl.add({ | ||
* entity: 'user-useremail@example.com', | ||
* role: storage.acl.OWNER_ROLE | ||
* }, function(err, aclObject) {}); | ||
* | ||
* //- | ||
* // If the callback is omitted, we'll return a Promise. | ||
* //- | ||
* albums.acl.add(options).then(function(data) { | ||
* const aclObject = data[0]; | ||
* const apiResponse = data[1]; | ||
* }); | ||
*/ | ||
Storage.acl = { | ||
OWNER_ROLE: 'OWNER', | ||
READER_ROLE: 'READER', | ||
WRITER_ROLE: 'WRITER', | ||
}; | ||
/*! Developer Documentation | ||
@@ -731,0 +736,0 @@ * |
@@ -46,1 +46,7 @@ /// <reference types="node" /> | ||
}; | ||
/** | ||
* JSON encode str, with unicode \u+ representation. | ||
* @param {object} obj The object to encode. | ||
* @return {string} Serialized string. | ||
*/ | ||
export declare function unicodeJSONStringify(obj: object): string; |
@@ -16,2 +16,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.unicodeJSONStringify = exports.objectKeyToLowercase = exports.qsStringify = exports.encodeURI = exports.fixedEncodeURIComponent = exports.objectEntries = exports.normalize = void 0; | ||
const querystring = require("querystring"); | ||
@@ -47,7 +48,3 @@ function normalize(optionsOrCallback, cb) { | ||
function fixedEncodeURIComponent(str) { | ||
return encodeURIComponent(str).replace(/[!'()*]/g, c => '%' + | ||
c | ||
.charCodeAt(0) | ||
.toString(16) | ||
.toUpperCase()); | ||
return encodeURIComponent(str).replace(/[!'()*]/g, c => '%' + c.charCodeAt(0).toString(16).toUpperCase()); | ||
} | ||
@@ -94,2 +91,11 @@ exports.fixedEncodeURIComponent = fixedEncodeURIComponent; | ||
exports.objectKeyToLowercase = objectKeyToLowercase; | ||
/** | ||
* JSON encode str, with unicode \u+ representation. | ||
* @param {object} obj The object to encode. | ||
* @return {string} Serialized string. | ||
*/ | ||
function unicodeJSONStringify(obj) { | ||
return JSON.stringify(obj).replace(/[\u0080-\uFFFF]/g, (char) => '\\u' + ('0000' + char.charCodeAt(0).toString(16)).slice(-4)); | ||
} | ||
exports.unicodeJSONStringify = unicodeJSONStringify; | ||
//# sourceMappingURL=util.js.map |
@@ -7,2 +7,41 @@ # Changelog | ||
## [5.0.0](https://www.github.com/googleapis/nodejs-storage/compare/v4.7.0...v5.0.0) (2020-05-13) | ||
### ⚠ BREAKING CHANGES | ||
* automatically detect contentType if not provided (#1190) | ||
* drop keepAcl parameter in file copy (#1166) | ||
* drop support for node.js 8.x | ||
### Features | ||
* automatically detect contentType if not provided ([#1190](https://www.github.com/googleapis/nodejs-storage/issues/1190)) ([b31ba4a](https://www.github.com/googleapis/nodejs-storage/commit/b31ba4a11399b57538ddf0d6ca2e10b2aa3fbc3a)) | ||
* enable bytes read tracking ([#1074](https://www.github.com/googleapis/nodejs-storage/issues/1074)) ([0776a04](https://www.github.com/googleapis/nodejs-storage/commit/0776a044f3b2149b485e114369e952688df75645)) | ||
### Bug Fixes | ||
* **bucket:** Only disable resumable uploads for bucket.upload (fixes [#1133](https://www.github.com/googleapis/nodejs-storage/issues/1133)) ([#1135](https://www.github.com/googleapis/nodejs-storage/issues/1135)) ([2c20148](https://www.github.com/googleapis/nodejs-storage/commit/2c201486b7b2d3146846ac96c877a904c4a674b0)), closes [/github.com/googleapis/nodejs-storage/pull/1135#issuecomment-620070038](https://www.github.com/googleapis//github.com/googleapis/nodejs-storage/pull/1135/issues/issuecomment-620070038) | ||
* add whitespace to generateV4SignedPolicy ([#1136](https://www.github.com/googleapis/nodejs-storage/issues/1136)) ([dcee78b](https://www.github.com/googleapis/nodejs-storage/commit/dcee78b98da23b02fe7d2f13a9270546bc07bba8)) | ||
* apache license URL ([#468](https://www.github.com/googleapis/nodejs-storage/issues/468)) ([#1151](https://www.github.com/googleapis/nodejs-storage/issues/1151)) ([e8116d3](https://www.github.com/googleapis/nodejs-storage/commit/e8116d3c6fa7412858692e67745b514eef78850e)) | ||
* Point to team in correct org ([#1185](https://www.github.com/googleapis/nodejs-storage/issues/1185)) ([0bb1909](https://www.github.com/googleapis/nodejs-storage/commit/0bb19098013acf71cc3842f78ff333a8e356331a)) | ||
* **deps:** update dependency @google-cloud/common to v3 ([#1134](https://www.github.com/googleapis/nodejs-storage/issues/1134)) ([774ac5c](https://www.github.com/googleapis/nodejs-storage/commit/774ac5c75f02238418cc8ed7242297ea573ca9cb)) | ||
* **deps:** update dependency @google-cloud/paginator to v3 ([#1131](https://www.github.com/googleapis/nodejs-storage/issues/1131)) ([c1614d9](https://www.github.com/googleapis/nodejs-storage/commit/c1614d98e3047db379e09299b1014e80d73ed52f)) | ||
* **deps:** update dependency @google-cloud/promisify to v2 ([#1127](https://www.github.com/googleapis/nodejs-storage/issues/1127)) ([06624a5](https://www.github.com/googleapis/nodejs-storage/commit/06624a534cd1fdbc38455eee8d89f9f60ba75758)) | ||
* **deps:** update dependency uuid to v8 ([#1170](https://www.github.com/googleapis/nodejs-storage/issues/1170)) ([6a98d64](https://www.github.com/googleapis/nodejs-storage/commit/6a98d64831baf1ca1ec2f03ecc4914745cba1c86)) | ||
* **deps:** update gcs-resumable-upload, remove gitnpm usage ([#1186](https://www.github.com/googleapis/nodejs-storage/issues/1186)) ([c78c9cd](https://www.github.com/googleapis/nodejs-storage/commit/c78c9cde49dccb2fcd4ce10e4e9f8299d65f6838)) | ||
* **v4-policy:** encode special characters ([#1169](https://www.github.com/googleapis/nodejs-storage/issues/1169)) ([6e48539](https://www.github.com/googleapis/nodejs-storage/commit/6e48539d76ca27e6f4c6cf2ac0872970f7391fed)) | ||
* sync to googleapis/conformance-tests@fa559a1 ([#1167](https://www.github.com/googleapis/nodejs-storage/issues/1167)) ([5500446](https://www.github.com/googleapis/nodejs-storage/commit/550044619d2f17a1977c83bce5df915c6dc9578c)), closes [#1168](https://www.github.com/googleapis/nodejs-storage/issues/1168) | ||
### Miscellaneous Chores | ||
* drop keepAcl parameter in file copy ([#1166](https://www.github.com/googleapis/nodejs-storage/issues/1166)) ([5a4044a](https://www.github.com/googleapis/nodejs-storage/commit/5a4044a8ba13f248fc4f791248f797eb0f1f3c16)) | ||
### Build System | ||
* drop support for node.js 8.x ([b80c025](https://www.github.com/googleapis/nodejs-storage/commit/b80c025f106052fd25554c64314b3b3520e829b5)) | ||
## [4.7.0](https://www.github.com/googleapis/nodejs-storage/compare/v4.6.0...v4.7.0) (2020-03-26) | ||
@@ -9,0 +48,0 @@ |
{ | ||
"name": "@google-cloud/storage", | ||
"description": "Cloud Storage Client Library for Node.js", | ||
"version": "4.7.0", | ||
"version": "5.0.0", | ||
"license": "Apache-2.0", | ||
"author": "Google Inc.", | ||
"engines": { | ||
"node": ">=8.10.0" | ||
"node": ">=10" | ||
}, | ||
@@ -15,6 +15,3 @@ "repository": "googleapis/nodejs-storage", | ||
"build/src", | ||
"!build/src/**/*.map", | ||
"AUTHORS", | ||
"CONTRIBUTORS", | ||
"COPYING" | ||
"!build/src/**/*.map" | ||
], | ||
@@ -42,3 +39,3 @@ "keywords": [ | ||
"pretest": "npm run compile", | ||
"lint": "eslint samples/ && gts check", | ||
"lint": "gts check", | ||
"samples-test": "npm link && cd samples/ && npm link ../ && npm test && cd ../", | ||
@@ -49,3 +46,3 @@ "all-test": "npm test && npm run system-test && npm run samples-test", | ||
"compile": "tsc -p .", | ||
"fix": "gts fix && eslint --fix '**/*.js'", | ||
"fix": "gts fix", | ||
"prepare": "npm run compile", | ||
@@ -55,8 +52,9 @@ "docs-test": "linkinator docs", | ||
"benchwrapper": "node bin/benchwrapper.js", | ||
"prelint": "cd samples; npm link ../; npm i" | ||
"prelint": "cd samples; npm link ../; npm install", | ||
"precompile": "gts clean" | ||
}, | ||
"dependencies": { | ||
"@google-cloud/common": "^2.1.1", | ||
"@google-cloud/paginator": "^2.0.0", | ||
"@google-cloud/promisify": "^1.0.0", | ||
"@google-cloud/common": "^3.0.0", | ||
"@google-cloud/paginator": "^3.0.0", | ||
"@google-cloud/promisify": "^2.0.0", | ||
"arrify": "^2.0.0", | ||
@@ -69,3 +67,3 @@ "compressible": "^2.0.12", | ||
"gaxios": "^3.0.0", | ||
"gcs-resumable-upload": "^2.2.4", | ||
"gcs-resumable-upload": "^3.0.0", | ||
"hash-stream-validation": "^0.2.2", | ||
@@ -85,2 +83,3 @@ "mime": "^2.2.0", | ||
"@google-cloud/pubsub": "^1.0.0", | ||
"@grpc/grpc-js": "^1.0.3", | ||
"@grpc/proto-loader": "^0.5.1", | ||
@@ -100,5 +99,5 @@ "@types/compressible": "^2.0.0", | ||
"@types/pumpify": "^1.4.1", | ||
"@types/sinon": "^7.0.10", | ||
"@types/sinon": "^9.0.0", | ||
"@types/through2": "^2.0.33", | ||
"@types/tmp": "0.1.0", | ||
"@types/tmp": "0.2.0", | ||
"@types/uuid": "^7.0.0", | ||
@@ -108,9 +107,4 @@ "@types/xdg-basedir": "^2.0.0", | ||
"codecov": "^3.0.0", | ||
"eslint": "^6.0.0", | ||
"eslint-config-prettier": "^6.0.0", | ||
"eslint-plugin-node": "^11.0.0", | ||
"eslint-plugin-prettier": "^3.0.0", | ||
"form-data": "^3.0.0", | ||
"grpc": "^1.22.2", | ||
"gts": "^1.0.0", | ||
"gts": "^2.0.0", | ||
"jsdoc": "^3.6.2", | ||
@@ -124,10 +118,9 @@ "jsdoc-fresh": "^1.0.1", | ||
"normalize-newline": "^3.0.0", | ||
"prettier": "^1.7.0", | ||
"proxyquire": "^2.1.3", | ||
"sinon": "^9.0.0", | ||
"tmp": "^0.1.0", | ||
"typescript": "3.6.4", | ||
"uuid": "^7.0.0", | ||
"tmp": "^0.2.0", | ||
"typescript": "^3.8.3", | ||
"uuid": "^8.0.0", | ||
"yargs": "^15.0.0" | ||
} | ||
} |
@@ -122,2 +122,3 @@ [//]: # "This README.md file is auto-generated, all changes to this file will be lost." | ||
| Generate V4 Read Signed Url | [source code](https://github.com/googleapis/nodejs-storage/blob/master/samples/generateV4ReadSignedUrl.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-storage&page=editor&open_in_editor=samples/generateV4ReadSignedUrl.js,samples/README.md) | | ||
| Generate V4 Signed Policy | [source code](https://github.com/googleapis/nodejs-storage/blob/master/samples/generateV4SignedPolicy.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-storage&page=editor&open_in_editor=samples/generateV4SignedPolicy.js,samples/README.md) | | ||
| Generate V4 Upload Signed Url | [source code](https://github.com/googleapis/nodejs-storage/blob/master/samples/generateV4UploadSignedUrl.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-storage&page=editor&open_in_editor=samples/generateV4UploadSignedUrl.js,samples/README.md) | | ||
@@ -124,0 +125,0 @@ | Get Default Event Based Hold | [source code](https://github.com/googleapis/nodejs-storage/blob/master/samples/getDefaultEventBasedHold.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-storage&page=editor&open_in_editor=samples/getDefaultEventBasedHold.js,samples/README.md) | |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
517057
39
10643
235
+ Added@google-cloud/common@3.10.0(transitive)
+ Added@google-cloud/paginator@3.0.7(transitive)
+ Added@google-cloud/projectify@2.1.1(transitive)
+ Added@google-cloud/promisify@2.0.4(transitive)
+ Added@tootallnate/once@2.0.0(transitive)
+ Addedasync-retry@1.3.3(transitive)
+ Addedgaxios@4.3.3(transitive)
+ Addedgcp-metadata@4.3.1(transitive)
+ Addedgcs-resumable-upload@3.6.0(transitive)
+ Addedgoogle-auth-library@7.14.1(transitive)
+ Addedgoogle-p12-pem@3.1.4(transitive)
+ Addedgtoken@5.3.2(transitive)
+ Addedhttp-proxy-agent@5.0.0(transitive)
+ Addedjson-bigint@1.0.0(transitive)
+ Addedlru-cache@6.0.0(transitive)
+ Addednode-forge@1.3.1(transitive)
+ Addedretry@0.13.1(transitive)
+ Addedteeny-request@7.2.0(transitive)
+ Addeduuid@8.3.2(transitive)
+ Addedyallist@4.0.0(transitive)
- Removed@google-cloud/common@2.4.0(transitive)
- Removed@google-cloud/paginator@2.0.3(transitive)
- Removed@google-cloud/projectify@1.0.4(transitive)
- Removed@google-cloud/promisify@1.0.4(transitive)
- Removed@tootallnate/once@1.1.2(transitive)
- Removedgaxios@2.3.4(transitive)
- Removedgcp-metadata@3.5.0(transitive)
- Removedgcs-resumable-upload@2.3.3(transitive)
- Removedgoogle-auth-library@5.10.1(transitive)
- Removedgoogle-p12-pem@2.0.5(transitive)
- Removedgtoken@4.1.4(transitive)
- Removedhttp-proxy-agent@4.0.1(transitive)
- Removedjson-bigint@0.3.1(transitive)
- Removedlru-cache@5.1.1(transitive)
- Removednode-forge@0.10.0(transitive)
- Removedteeny-request@6.0.3(transitive)
- Removeduuid@7.0.3(transitive)
- Removedyallist@3.1.1(transitive)
Updated@google-cloud/common@^3.0.0
Updatedgcs-resumable-upload@^3.0.0