Skip to content

Commit

Permalink
feat!: drop node8 support, support for async iterators (#300)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The library now supports Node.js v10+. The last version to support Node.js v8 is tagged legacy-8 on NPM.

New feature: methods with pagination now support async iteration.
  • Loading branch information
alexander-fenster authored and Ace Nassri committed Nov 11, 2022
1 parent 089edee commit 5493b9d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 43 deletions.
2 changes: 1 addition & 1 deletion kms/quickstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async function quickstart(
console.log('Key rings:');
keyRings.forEach(keyRing => console.log(keyRing.name));
} else {
console.log(`No key rings found.`);
console.log('No key rings found.');
}
}
// [END kms_quickstart]
Expand Down
84 changes: 42 additions & 42 deletions kms/system-test/kms.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@

'use strict';

const fs = require(`fs`);
const path = require(`path`);
const fs = require('fs');
const path = require('path');
const {assert} = require('chai');
const {describe, it, before, after} = require('mocha');
const cp = require('child_process');
const {promisify} = require('util');
const {v4} = require(`uuid`);
const {v4} = require('uuid');
const unlink = promisify(fs.unlink);

const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});

const keyRingName = `test-ring-${v4()}`;
const keyNameOne = `test-key-${v4()}`;
const member = `allAuthenticatedUsers`;
const role = `roles/viewer`;
const member = 'allAuthenticatedUsers';
const role = 'roles/viewer';
const projectId = process.env.GCLOUD_PROJECT;
const plaintext = path.join(__dirname, `../resources/plaintext.txt`);
const ciphertext = path.join(__dirname, `../resources/plaintext.txt.encrypted`);
const decrypted = path.join(__dirname, `../resources/plaintext.txt.decrypted`);
const plaintext = path.join(__dirname, '../resources/plaintext.txt');
const ciphertext = path.join(__dirname, '../resources/plaintext.txt.encrypted');
const decrypted = path.join(__dirname, '../resources/plaintext.txt.decrypted');

const unspecifiedKeyRingName = `projects/${projectId}/locations/global/keyRings/`;
const formattedKeyRingName = `projects/${projectId}/locations/global/keyRings/${keyRingName}`;
Expand Down Expand Up @@ -65,7 +65,7 @@ describe('kms sample tests', () => {
assert.match(output, /\/locations\/global\/keyRings\//);
});

it(`should create a key ring`, async () => {
it('should create a key ring', async () => {
const output = execSync(
`node createKeyring.js "${projectId}" "${keyRingName}"`
);
Expand All @@ -77,18 +77,18 @@ describe('kms sample tests', () => {
}
});

it(`should list key rings`, async () => {
it('should list key rings', async () => {
const output = execSync(`node listKeyrings.js ${projectId}`);
assert.match(output, new RegExp(unspecifiedKeyRingName));
});

it(`should get a key ring`, async () => {
it('should get a key ring', async () => {
const output = execSync(`node getKeyring ${projectId} ${keyRingName}`);
assert.match(output, new RegExp(`Name: ${formattedKeyRingName}`));
assert.match(output, /Created: /);
});

it(`should get a key ring's empty IAM policy`, async () => {
it("should get a key ring's empty IAM policy", async () => {
const output = execSync(
`node getKeyringIamPolicy.js ${projectId} ${keyRingName}`
);
Expand All @@ -98,7 +98,7 @@ describe('kms sample tests', () => {
);
});

it(`should grant access to a key ring`, async () => {
it('should grant access to a key ring', async () => {
const output = execSync(
`node addMemberToKeyRingPolicy.js ${projectId} ${keyRingName} ${member} ${role}`
);
Expand All @@ -110,15 +110,15 @@ describe('kms sample tests', () => {
);
});

it(`should get a key ring's updated IAM policy`, async () => {
it("should get a key ring's updated IAM policy", async () => {
const output = execSync(
`node getKeyringIamPolicy.js ${projectId} ${keyRingName}`
);
assert.match(output, new RegExp(`${role}:`));
assert.match(output, new RegExp(` ${member}`));
});

it(`should revoke access to a key ring`, async () => {
it('should revoke access to a key ring', async () => {
const output = execSync(
`node removeMemberFromKeyRingPolicy.js ${projectId} ${keyRingName} ${member} ${role}`
);
Expand All @@ -130,7 +130,7 @@ describe('kms sample tests', () => {
);
});

it(`should create a key`, async () => {
it('should create a key', async () => {
const output = execSync(
`node createCryptoKey.js ${projectId} ${keyRingName} ${keyNameOne}`
);
Expand All @@ -139,22 +139,22 @@ describe('kms sample tests', () => {
}
});

it(`should list keys`, async () => {
it('should list keys', async () => {
const output = execSync(
`node listCryptoKeys.js ${projectId} ${keyRingName}`
);
assert.match(output, new RegExp(formattedKeyName));
});

it(`should get a key`, async () => {
it('should get a key', async () => {
const output = execSync(
`node getCryptoKey.js ${projectId} ${keyRingName} ${keyNameOne}`
);
assert.match(output, new RegExp(`Name: ${formattedKeyName}`));
assert.match(output, new RegExp(`Created: `));
assert.match(output, new RegExp('Created: '));
});

it(`should set a crypto key's primary version`, async () => {
it("should set a crypto key's primary version", async () => {
const output = execSync(
`node setPrimaryCryptoKeyVersion.js ${projectId} ${keyRingName} ${keyNameOne} 1`
);
Expand All @@ -164,7 +164,7 @@ describe('kms sample tests', () => {
);
});

it(`should encrypt a file`, async () => {
it('should encrypt a file', async () => {
const output = execSync(
`node encrypt.js ${projectId} ${keyRingName} ${keyNameOne} "${plaintext}" "${ciphertext}"`
);
Expand All @@ -177,7 +177,7 @@ describe('kms sample tests', () => {
assert.match(output, new RegExp(`Result saved to ${ciphertext}.`));
});

it(`should decrypt a file`, async () => {
it('should decrypt a file', async () => {
const output = execSync(
`node decrypt.js ${projectId} "${keyRingName}" "${keyNameOne}" "${ciphertext}" "${decrypted}"`
);
Expand All @@ -192,25 +192,25 @@ describe('kms sample tests', () => {
);
});

it(`should create a crypto key version`, async () => {
it('should create a crypto key version', async () => {
const output = execSync(
`node createCryptoKeyVersion ${projectId} "${keyRingName}" "${keyNameOne}"`
);
assert.match(
output,
new RegExp(`Crypto key version ${formattedKeyName}/cryptoKeyVersions/`)
);
assert.match(output, new RegExp(` created.`));
assert.match(output, new RegExp(' created.'));
});

it(`should list crypto key versions`, async () => {
it('should list crypto key versions', async () => {
const output = execSync(
`node listCryptoKeyVersions.js ${projectId} "${keyRingName}" "${keyNameOne}"`
);
assert.match(output, new RegExp(`${formattedKeyName}/cryptoKeyVersions/1`));
});

it(`should destroy a crypto key version`, async () => {
it('should destroy a crypto key version', async () => {
const output = execSync(
`node destroyCryptoKeyVersion ${projectId} "${keyRingName}" "${keyNameOne}" 2`
);
Expand All @@ -222,7 +222,7 @@ describe('kms sample tests', () => {
);
});

it(`should restore a crypto key version`, async () => {
it('should restore a crypto key version', async () => {
const output = execSync(
`node restoreCryptoKeyVersion ${projectId} "${keyRingName}" "${keyNameOne}" 2`
);
Expand All @@ -234,7 +234,7 @@ describe('kms sample tests', () => {
);
});

it(`should enable a crypto key version`, async () => {
it('should enable a crypto key version', async () => {
const output = execSync(
`node enableCryptoKeyVersion ${projectId} "${keyRingName}" "${keyNameOne}" 2`
);
Expand All @@ -246,7 +246,7 @@ describe('kms sample tests', () => {
);
});

it(`should disable a crypto key version`, async () => {
it('should disable a crypto key version', async () => {
const output = execSync(
`node disableCryptoKeyVersion ${projectId} "${keyRingName}" "${keyNameOne}" 2`
);
Expand All @@ -258,7 +258,7 @@ describe('kms sample tests', () => {
);
});

it(`should get a crypto key's empty IAM policy`, async () => {
it("should get a crypto key's empty IAM policy", async () => {
const output = execSync(
`node getCryptoKeyIamPolicy ${projectId} "${keyRingName}" "${keyNameOne}"`
);
Expand All @@ -268,7 +268,7 @@ describe('kms sample tests', () => {
);
});

it(`should grant access to a crypto key`, async () => {
it('should grant access to a crypto key', async () => {
const output = execSync(
`node addMemberToCryptoKeyPolicy ${projectId} "${keyRingName}" "${keyNameOne}" "${member}" "${role}"`
);
Expand All @@ -280,15 +280,15 @@ describe('kms sample tests', () => {
);
});

it(`should get a crypto key's updated IAM policy`, async () => {
it("should get a crypto key's updated IAM policy", async () => {
const output = execSync(
`node getCryptoKeyIamPolicy ${projectId} "${keyRingName}" "${keyNameOne}"`
);
assert.match(output, new RegExp(`${role}:`));
assert.match(output, new RegExp(` ${member}`));
});

it(`should revoke access to a crypto key`, async () => {
it('should revoke access to a crypto key', async () => {
const output = execSync(
`node removeMemberCryptoKeyPolicy ${projectId} "${keyRingName}" "${keyNameOne}" ${member} ${role}`
);
Expand All @@ -304,7 +304,7 @@ describe('kms sample tests', () => {
const kms = require('@google-cloud/kms');
const client = new kms.KeyManagementServiceClient();

const locationId = `global`;
const locationId = 'global';
const keyRingId = `test-asymmetric-ring-${v4()}`;
const keyAsymmetricDecryptName = `test-asymmetric-decrypt-${v4()}`;

Expand Down Expand Up @@ -380,7 +380,7 @@ describe('kms sample tests', () => {
await client.destroyCryptoKeyVersion({name: signKeyVersionId});
});

it(`should perform asymmetric encryption`, async function() {
it('should perform asymmetric encryption', async function() {
// Only run this test on Node 12+
if (nodeMajorVersion < 12) {
this.skip();
Expand All @@ -395,14 +395,14 @@ describe('kms sample tests', () => {
"${dataToEncrypt}"
`);

const re = new RegExp(`Encrypted ciphertext: (.+)`);
const re = new RegExp('Encrypted ciphertext: (.+)');
assert.match(out, re);

const match = re.exec(out);
ciphertext = match[1];
});

it(`should perform asymmetric decryption`, async function() {
it('should perform asymmetric decryption', async function() {
// Only run this test on Node 12+
if (nodeMajorVersion < 12) {
this.skip();
Expand All @@ -417,7 +417,7 @@ describe('kms sample tests', () => {
"${ciphertext}"
`);

const re = new RegExp(`Decrypted plaintext: (.+)`);
const re = new RegExp('Decrypted plaintext: (.+)');
assert.match(out, re);

const match = re.exec(out);
Expand All @@ -426,7 +426,7 @@ describe('kms sample tests', () => {
assert.equal(dataToEncrypt, plaintext);
});

it(`should perform asymmetric signing`, async function() {
it('should perform asymmetric signing', async () => {
const out = execSync(`
node asymmetricSign.js \
"${projectId}" \
Expand All @@ -436,14 +436,14 @@ describe('kms sample tests', () => {
"${dataToSign}"
`);

const re = new RegExp(`Signature: (.+)`);
const re = new RegExp('Signature: (.+)');
assert.match(out, re);

const match = re.exec(out);
signature = match[1];
});

it(`should perform asymmetric verification`, async function() {
it('should perform asymmetric verification', async () => {
const out = execSync(`
node asymmetricVerify.js \
"${projectId}" \
Expand All @@ -454,7 +454,7 @@ describe('kms sample tests', () => {
"${signature}"
`);

const re = new RegExp(`Signature verified: (.+)`);
const re = new RegExp('Signature verified: (.+)');
assert.match(out, re);

const match = re.exec(out);
Expand Down

0 comments on commit 5493b9d

Please sign in to comment.