()
| 5 | import { dataform } from "df/protos/ts"; |
| 6 | |
| 7 | export function getBigQueryCredentials(): dataform.IBigQuery { |
| 8 | const locationIndex = selectionQuestion("Enter the location of your datasets:", [ |
| 9 | "US (default)", |
| 10 | "EU", |
| 11 | "other" |
| 12 | ]); |
| 13 | let location = locationIndex === 0 ? "US" : "EU"; |
| 14 | if (locationIndex === 2) { |
| 15 | location = question("Enter the location's region name (e.g. 'asia-south1'):"); |
| 16 | } |
| 17 | const isApplicationDefaultOrJSONKeyIndex = selectionQuestion( |
| 18 | "Do you wish to use Application Default Credentials or JSON Key:", |
| 19 | ["ADC (default)", "JSON Key"] |
| 20 | ); |
| 21 | if (isApplicationDefaultOrJSONKeyIndex === 0) { |
| 22 | const projectId = question("Enter your billing project ID:"); |
| 23 | return { |
| 24 | projectId, |
| 25 | location |
| 26 | }; |
| 27 | } |
| 28 | const cloudCredentialsPath = actuallyResolve( |
| 29 | question( |
| 30 | "Please follow the instructions at https://docs.dataform.co/dataform-cli#create-a-credentials-file/\n" + |
| 31 | "to create and download a private key from the Google Cloud Console in JSON format.\n" + |
| 32 | "(You can delete this file after credential initialization is complete.)\n\n" + |
| 33 | "Enter the path to your Google Cloud private key file:" |
| 34 | ) |
| 35 | ); |
| 36 | if (!fs.existsSync(cloudCredentialsPath)) { |
| 37 | throw new Error(`Google Cloud private key file "${cloudCredentialsPath}" does not exist!`); |
| 38 | } |
| 39 | const cloudCredentials = JSON.parse(fs.readFileSync(cloudCredentialsPath, "utf8")); |
| 40 | return { |
| 41 | projectId: cloudCredentials.project_id, |
| 42 | credentials: fs.readFileSync(cloudCredentialsPath, "utf8"), |
| 43 | location |
| 44 | }; |
| 45 | } |
no test coverage detected