Skip to content

Commit

Permalink
Merge branch 'master' into eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
fhinkel committed Nov 13, 2018
2 parents b5db94d + 170d18f commit 73861ac
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 59 deletions.
29 changes: 10 additions & 19 deletions kms/keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -1438,26 +1438,17 @@ function buildAndAuthorizeService(callback) {
const {google} = require('googleapis');

// Acquires credentials
google.auth.getApplicationDefault((err, authClient) => {
if (err) {
callback(err);
return;
}

if (authClient.createScopedRequired && authClient.createScopedRequired()) {
authClient = authClient.createScoped([
'https://www.googleapis.com/auth/cloud-platform',
]);
}

// Instantiates an authorized client
const cloudkms = google.cloudkms({
version: 'v1',
auth: authClient,
google.auth
.getClient({scopes: ['https://www.googleapis.com/auth/cloud-platform']})
.then(auth => {
// Instantiates an authorized client
const cloudkms = google.cloudkms({
version: 'v1',
auth,
});

callback(null, cloudkms);
});

callback(null, cloudkms);
});
}
// [END kms_create_keyring]
// [END kms_list_keyrings]
Expand Down
6 changes: 3 additions & 3 deletions kms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
"test": "repo-tools test run --cmd ava -- -T 20s --verbose system-test/*.test.js"
},
"dependencies": {
"googleapis": "27.0.0",
"googleapis": "^35.0.0",
"safe-buffer": "5.1.1",
"uuid": "^3.2.1",
"yargs": "11.0.0"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "^3.0.0",
"ava": "0.25.0",
"proxyquire": "2.0.1"
"proxyquire": "2.0.1",
"uuid": "^3.3.2"
},
"cloud-repo-tools": {
"requiresKeyFile": true,
Expand Down
65 changes: 28 additions & 37 deletions kms/quickstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,42 +26,33 @@ const projectId = process.env.GCLOUD_PROJECT;
const location = 'global';

// Acquires credentials
google.auth.getApplicationDefault((err, authClient) => {
if (err) {
console.error('Failed to acquire credentials');
return;
}

if (authClient.createScopedRequired && authClient.createScopedRequired()) {
authClient = authClient.createScoped([
'https://www.googleapis.com/auth/cloud-platform',
]);
}

// Instantiates an authorized client
const cloudkms = google.cloudkms({
version: 'v1',
auth: authClient,
});
const request = {
parent: `projects/${projectId}/locations/${location}`,
};

// Lists key rings
cloudkms.projects.locations.keyRings.list(request, (err, result) => {
if (err) {
console.error(err);
return;
}

const keyRings = result.data.keyRings || [];

if (keyRings.length) {
console.log('Key rings:');
keyRings.forEach(keyRing => console.log(keyRing.name));
} else {
console.log(`No key rings found.`);
}
google.auth
.getClient({scopes: ['https://www.googleapis.com/auth/cloud-platform']})
.then(auth => {
// Instantiates an authorized client
const cloudkms = google.cloudkms({
version: 'v1',
auth,
});
const request = {
parent: `projects/${projectId}/locations/${location}`,
};

// Lists key rings
cloudkms.projects.locations.keyRings.list(request, (err, result) => {
if (err) {
console.error(err);
return;
}

const keyRings = result.data.keyRings || [];

if (keyRings.length) {
console.log('Key rings:');
keyRings.forEach(keyRing => console.log(keyRing.name));
} else {
console.log(`No key rings found.`);
}
});
});
});
// [END kms_quickstart]

0 comments on commit 73861ac

Please sign in to comment.