UNPKG

@google/dscc-gen

Version:

Create component & connector projects with sane defaults.

54 lines 2.33 kB
"use strict"; /** * @license * Copyright 2018 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.hasBucketPermissions = exports.parseBucketName = exports.checkGsutilInstalled = exports.addBucketPrefix = void 0; const execa = require("execa"); const shelljs = require("shelljs"); const terminal_link_1 = require("terminal-link"); const analytics = require("../analytics"); const analytics_1 = require("../analytics"); const util_1 = require("../util"); exports.addBucketPrefix = (bucket) => bucket.startsWith('gs://') ? bucket : `gs://${bucket}`; exports.checkGsutilInstalled = () => { if (shelljs.which('gsutil') === null) { analytics.trackEvent(analytics_1.Category.EXECUTION, analytics_1.Action.GSUTIL_NOT_INSTALLED); const error = util_1.format.red.bold('ERROR'); const gsutil = util_1.format.blue('gsutil'); const gsutilInstall = util_1.format.yellow(terminal_link_1.default('Install gsutil', 'https://cloud.google.com/storage/docs/gsutil_install')); const errorString = `\ ${error}: ${gsutil} is not installed, but is needed for the viz template.\n\ ${gsutilInstall}, then re-run this command to continue.\n\ No files have been created. `; throw new Error(errorString); } return true; }; exports.parseBucketName = (bucketPath) => { const matches = bucketPath.match(/^(gs:\/\/[-\w]+)(?:\/[\w-]+)*\/?$/); if (matches === null) { throw new Error(`${bucketPath} is an invalid gcs bucket name.`); } return matches[1]; }; exports.hasBucketPermissions = async (gcsPath) => { const gcsRootBucket = exports.parseBucketName(gcsPath); await execa(`gsutil`, ['acl', 'get', gcsRootBucket]); return true; }; //# sourceMappingURL=validation.js.map