@google/dscc-gen
Version:
Create component & connector projects with sane defaults.
56 lines (55 loc) • 1.92 kB
JavaScript
;
/**
* @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 });
const analytics = require("../analytics");
const analytics_1 = require("../analytics");
const util = require("../util");
exports.addBucketPrefix = (bucket) => `gs://${bucket}`;
exports.checkGsutilInstalled = async () => {
try {
await util.exec('which gsutil', {}, false);
}
catch (e) {
analytics.trackEvent(analytics_1.Category.EXECUTION, analytics_1.Action.GSUTIL_NOT_INSTALLED);
throw new Error('\nERROR: gsutil is not installed, but is needed for the viz template. \
Please follow installation instructions at\n\
https://cloud.google.com/storage/docs/gsutil_install\nExiting template \
creation, no files have been created.');
}
return true;
};
exports.parseBucketName = (bucketPath) => {
const matches = bucketPath.match(/(gs:\/\/[^/\s]+)/);
if (matches === null) {
return undefined;
}
return matches[0];
};
exports.hasBucketPermissions = async (gcsPath) => {
const gcsRootBucket = exports.parseBucketName(gcsPath);
if (!gcsRootBucket) {
return `${gcsPath} is an invalid gcs bucket name.`;
}
try {
await util.exec(`gsutil acl get ${gcsRootBucket}`, {}, false);
return true;
}
catch (e) {
return e.message;
}
};