Skip to content

Commit 275191a

Browse files
akowalskbcoeSurferJeffAtGooglesofisl
authored
feat: Adding implementation of startWithEncryptionKey api call (#539)
* 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]>
1 parent a655ddf commit 275191a

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

packages/google-cloud-compute/src/vm.js

+52
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,58 @@ class VM extends common.ServiceObject {
985985
callback || common.util.noop
986986
);
987987
}
988+
/**
989+
* Start an instance with customer encrypted disks.
990+
*
991+
* @see [Instances: start API Documentation]{@link https://cloud.google.com/compute/docs/reference/rest/v1/instances/startWithEncryptionKey}
992+
*
993+
* @param {object[]} disks - An array of the encrypted disks and their keys.
994+
* @param {function=} callback - The callback function.
995+
* @param {?error} callback.err - An error returned while making this request.
996+
* @param {Operation} callback.operation - An operation object
997+
* that can be used to check the status of the request.
998+
* @param {object} callback.apiResponse - The full API response.
999+
*
1000+
* @example
1001+
* const Compute = require('@google-cloud/compute');
1002+
* const compute = new Compute();
1003+
* const zone = compute.zone('zone-name');
1004+
* const vm = zone.vm('vm-name');
1005+
*
1006+
* var disks = [
1007+
* {
1008+
* source: 'disk_name',
1009+
* diskEncryptionKey: {
1010+
* rawKey: '...'
1011+
* }
1012+
* }
1013+
* ]
1014+
*
1015+
* vm.startWithEncryptionKey(disks, function(err, operation, apiResponse) {
1016+
* // `operation` is an Operation object that can be used to check the status
1017+
* // of the request.
1018+
* });
1019+
*
1020+
* //-
1021+
* // If the callback is omitted, we'll return a Promise.
1022+
* //-
1023+
* vm.startWithEncryptionKey(disks).then(function(data) {
1024+
* const operation = data[0];
1025+
* const apiResponse = data[1];
1026+
* });
1027+
*/
1028+
startWithEncryptionKey(disks, callback) {
1029+
this.request(
1030+
{
1031+
method: 'POST',
1032+
uri: '/startWithEncryptionKey',
1033+
json: {
1034+
disks,
1035+
},
1036+
},
1037+
callback || common.util.noop
1038+
);
1039+
}
9881040
/**
9891041
* Stop the instance.
9901042
*

packages/google-cloud-compute/test/vm.js

+27
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,33 @@ describe('VM', () => {
941941
});
942942
});
943943

944+
describe('startWithEncryptionKey', () => {
945+
const DISKS = [];
946+
947+
it('should make the correct API request', done => {
948+
vm.request = function (reqOpts, callback) {
949+
assert.strictEqual(reqOpts.method, 'POST');
950+
assert.strictEqual(reqOpts.uri, '/startWithEncryptionKey');
951+
assert.strictEqual(reqOpts.json.disks, DISKS);
952+
953+
callback();
954+
};
955+
956+
vm.startWithEncryptionKey(DISKS, done);
957+
});
958+
959+
it('should not require a callback', done => {
960+
vm.request = function (reqOpts, callback) {
961+
assert.doesNotThrow(() => {
962+
callback();
963+
done();
964+
});
965+
};
966+
967+
vm.start();
968+
});
969+
});
970+
944971
describe('stop', () => {
945972
it('should make the correct API request', done => {
946973
vm.request = function (reqOpts, callback) {

0 commit comments

Comments
 (0)