Skip to content

Commit

Permalink
feat: Adding implementation of startWithEncryptionKey api call (#539)
Browse files Browse the repository at this point in the history
* feat[vm]: Adding implementation of startWithEncryptionKey api call

* feat: Adding implementation of startWithEncryptionKey api call

Co-authored-by: Benjamin E. Coe <[email protected]>
Co-authored-by: Jeffrey Rennie <[email protected]>
Co-authored-by: sofisl <[email protected]>
  • Loading branch information
4 people authored Jun 29, 2021
1 parent a655ddf commit 275191a
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
52 changes: 52 additions & 0 deletions packages/google-cloud-compute/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 packages/google-cloud-compute/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

0 comments on commit 275191a

Please sign in to comment.