Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

feat: Adding implementation of startWithEncryptionKey api call #539

Merged
merged 7 commits into from
Jun 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions src/vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,58 @@ class VM extends common.ServiceObject {
callback || common.util.noop
);
}
/**
* Start an instance with customer encrypted disks.
*
* @see [Instances: start API Documentation]{@link https://cloud.google.com/compute/docs/reference/rest/v1/instances/startWithEncryptionKey}
*
* @param {object[]} disks - An array of the encrypted disks and their keys.
* @param {function=} callback - The callback function.
* @param {?error} callback.err - An error returned while making this request.
* @param {Operation} callback.operation - An operation object
* that can be used to check the status of the request.
* @param {object} callback.apiResponse - The full API response.
*
* @example
* const Compute = require('@google-cloud/compute');
* const compute = new Compute();
* const zone = compute.zone('zone-name');
* const vm = zone.vm('vm-name');
*
* var disks = [
* {
* source: 'disk_name',
* diskEncryptionKey: {
* rawKey: '...'
* }
* }
* ]
*
* vm.startWithEncryptionKey(disks, function(err, operation, apiResponse) {
* // `operation` is an Operation object that can be used to check the status
* // of the request.
* });
*
* //-
* // If the callback is omitted, we'll return a Promise.
* //-
* vm.startWithEncryptionKey(disks).then(function(data) {
* const operation = data[0];
* const apiResponse = data[1];
* });
*/
startWithEncryptionKey(disks, callback) {
this.request(
{
method: 'POST',
uri: '/startWithEncryptionKey',
json: {
disks,
},
},
callback || common.util.noop
);
}
/**
* Stop the instance.
*
Expand Down
27 changes: 27 additions & 0 deletions test/vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,33 @@ describe('VM', () => {
});
});

describe('startWithEncryptionKey', () => {
const DISKS = [];

it('should make the correct API request', done => {
vm.request = function (reqOpts, callback) {
assert.strictEqual(reqOpts.method, 'POST');
assert.strictEqual(reqOpts.uri, '/startWithEncryptionKey');
assert.strictEqual(reqOpts.json.disks, DISKS);

callback();
};

vm.startWithEncryptionKey(DISKS, done);
});

it('should not require a callback', done => {
vm.request = function (reqOpts, callback) {
assert.doesNotThrow(() => {
callback();
done();
});
};

vm.start();
});
});

describe('stop', () => {
it('should make the correct API request', done => {
vm.request = function (reqOpts, callback) {
Expand Down