|
18 | 18 | const google = require('googleapis'); |
19 | 19 | const cloudtasks = google.cloudtasks('v2beta2'); |
20 | 20 |
|
21 | | -function authorize (callback) { |
22 | | - google.auth.getApplicationDefault(function (err, authClient) { |
23 | | - if (err) { |
24 | | - console.error('authentication failed: ', err); |
25 | | - return; |
26 | | - } |
27 | | - if (authClient.createScopedRequired && authClient.createScopedRequired()) { |
28 | | - var scopes = ['https://www.googleapis.com/auth/cloud-platform']; |
29 | | - authClient = authClient.createScoped(scopes); |
30 | | - } |
31 | | - callback(authClient); |
32 | | - }); |
33 | | -} |
34 | | - |
35 | 21 | /** |
36 | 22 | * Create a task for a given queue with an arbitrary payload. |
37 | 23 | */ |
38 | 24 | function createTask (project, location, queue, options) { |
| 25 | + // [START cloud_tasks_appengine_create_task] |
39 | 26 | authorize((authClient) => { |
40 | 27 | const task = { |
41 | 28 | app_engine_http_request: { |
@@ -72,6 +59,21 @@ function createTask (project, location, queue, options) { |
72 | 59 | console.log(JSON.stringify(response, null, 2)); |
73 | 60 | }); |
74 | 61 | }); |
| 62 | + |
| 63 | + function authorize (callback) { |
| 64 | + google.auth.getApplicationDefault(function (err, authClient) { |
| 65 | + if (err) { |
| 66 | + console.error('authentication failed: ', err); |
| 67 | + return; |
| 68 | + } |
| 69 | + if (authClient.createScopedRequired && authClient.createScopedRequired()) { |
| 70 | + var scopes = ['https://www.googleapis.com/auth/cloud-platform']; |
| 71 | + authClient = authClient.createScoped(scopes); |
| 72 | + } |
| 73 | + callback(authClient); |
| 74 | + }); |
| 75 | + } |
| 76 | + // [END cloud_tasks_appengine_create_task] |
75 | 77 | } |
76 | 78 |
|
77 | 79 | const cli = require(`yargs`) |
|
0 commit comments