|
| 1 | +// Copyright 2021 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +'use strict'; |
| 16 | + |
| 17 | +function main(parent, transferConfig) { |
| 18 | + // [START bigquerydatatransfer_v1_generated_DataTransferService_CreateTransferConfig_async] |
| 19 | + /** |
| 20 | + * TODO(developer): Uncomment these variables before running the sample. |
| 21 | + */ |
| 22 | + /** |
| 23 | + * Required. The BigQuery project id where the transfer configuration should be created. |
| 24 | + * Must be in the format projects/{project_id}/locations/{location_id} or |
| 25 | + * projects/{project_id}. If specified location and location of the |
| 26 | + * destination bigquery dataset do not match - the request will fail. |
| 27 | + */ |
| 28 | + // const parent = 'abc123' |
| 29 | + /** |
| 30 | + * Required. Data transfer configuration to create. |
| 31 | + */ |
| 32 | + // const transferConfig = '' |
| 33 | + /** |
| 34 | + * Optional OAuth2 authorization code to use with this transfer configuration. |
| 35 | + * This is required if new credentials are needed, as indicated by |
| 36 | + * `CheckValidCreds`. |
| 37 | + * In order to obtain authorization_code, please make a |
| 38 | + * request to |
| 39 | + * https://www.gstatic.com/bigquerydatatransfer/oauthz/auth?client_id=<datatransferapiclientid>&scope=<data_source_scopes>&redirect_uri=<redirect_uri> |
| 40 | + * * client_id should be OAuth client_id of BigQuery DTS API for the given |
| 41 | + * data source returned by ListDataSources method. |
| 42 | + * * data_source_scopes are the scopes returned by ListDataSources method. |
| 43 | + * * redirect_uri is an optional parameter. If not specified, then |
| 44 | + * authorization code is posted to the opener of authorization flow window. |
| 45 | + * Otherwise it will be sent to the redirect uri. A special value of |
| 46 | + * urn:ietf:wg:oauth:2.0:oob means that authorization code should be |
| 47 | + * returned in the title bar of the browser, with the page text prompting |
| 48 | + * the user to copy the code and paste it in the application. |
| 49 | + */ |
| 50 | + // const authorizationCode = 'abc123' |
| 51 | + /** |
| 52 | + * Optional version info. If users want to find a very recent access token, |
| 53 | + * that is, immediately after approving access, users have to set the |
| 54 | + * version_info claim in the token request. To obtain the version_info, users |
| 55 | + * must use the "none+gsession" response type. which be return a |
| 56 | + * version_info back in the authorization response which be be put in a JWT |
| 57 | + * claim in the token request. |
| 58 | + */ |
| 59 | + // const versionInfo = 'abc123' |
| 60 | + /** |
| 61 | + * Optional service account name. If this field is set, transfer config will |
| 62 | + * be created with this service account credentials. It requires that |
| 63 | + * requesting user calling this API has permissions to act as this service |
| 64 | + * account. |
| 65 | + */ |
| 66 | + // const serviceAccountName = 'abc123' |
| 67 | + |
| 68 | + // Imports the Datatransfer library |
| 69 | + const {DataTransferServiceClient} = |
| 70 | + require('@google-cloud/bigquery-data-transfer').v1; |
| 71 | + |
| 72 | + // Instantiates a client |
| 73 | + const datatransferClient = new DataTransferServiceClient(); |
| 74 | + |
| 75 | + async function createTransferConfig() { |
| 76 | + // Construct request |
| 77 | + const request = { |
| 78 | + parent, |
| 79 | + transferConfig, |
| 80 | + }; |
| 81 | + |
| 82 | + // Run request |
| 83 | + const response = await datatransferClient.createTransferConfig(request); |
| 84 | + console.log(response); |
| 85 | + } |
| 86 | + |
| 87 | + createTransferConfig(); |
| 88 | + // [END bigquerydatatransfer_v1_generated_DataTransferService_CreateTransferConfig_async] |
| 89 | +} |
| 90 | + |
| 91 | +process.on('unhandledRejection', err => { |
| 92 | + console.error(err.message); |
| 93 | + process.exitCode = 1; |
| 94 | +}); |
| 95 | +main(...process.argv.slice(2)); |
0 commit comments