in ingestion/batch/configurationManager.js [31:138]
async function validateOptions(options, validateStorage) {
let info = [];
let warn = [];
let errors = [];
if (!options.eventId) {
errors.push("options.eventId must be provided");
}
if (!options.bucketName) {
errors.push("options.bucketName must be provided");
}
let attributes;
if (!options.fileName) {
errors.push("options.fileName must be provided");
}
else {
attributes = parseDerivedFileAttributes(options);
console.log(`File attributes: ${JSON.stringify(attributes)}`);
// If file is archived, skip checks.
if (attributes && attributes.isDataFile) {
// options.fileName is defined
const pathParts = path.dirname(options.fileName).split("/").filter(Boolean);
console.log(`Path parts: ${pathParts}`);
if (pathParts.length !== 4) {
errors.push(`Path must contain 4 components for data files. Provided: '${pathParts}'. Path must start with '${cfg.pathPrefix}' and the data file must be in a directory named 'data'.`);
}
else {
// Path parts should contain n. IE: /${cfg.pathPrefix}/dataset/table/data, /${cfg.pathPrefix}/dataset/table/config
const first = underscore.first(pathParts);
const last = underscore.last(pathParts);
if (first !== cfg.pathPrefix) {
errors.push(`First level directory must be named '${cfg.pathPrefix}', current is '${first}'`);
}
if (last !== "data") {
errors.push(`Last level directory must be named 'data', current is '${last}'`);
}
}
if (!pathCheck(pathParts, 0, cfg.pathPrefix)) {
errors.push(`The first path component must be '${cfg.pathPrefix}' only`);
}
if (!pathCheck(pathParts, 3, "data")) {
errors.push("The fourth path component must be 'data' only");
}
if (!pathCheck(pathParts, 3, "config", false)) {
errors.push("The fourth path component must be 'config' only");
}
if (!pathCheck(pathParts, 4, "archive", false)) {
errors.push("The fifth path component must be 'archive' only");
}
const extensionSupported = commonUtil.isExtensionSupported(options.fileName, acceptable);
if (!extensionSupported) {
errors.push(`File extension '${path.extname(options.fileName)}' in fileName '${options.fileName}' is not supported`);
}
if (validateStorage) {
if (options.bucketName && extensionSupported) {
// Check for existence of a schema.json transform.sql file. If they don't exist, return warnings
const schemaConfig = attributes.schemaPath;
const transformConfig = attributes.transformPath;
const schemaConfigExists = await storageUtil.fileExists(options.bucketName, attributes.schemaPath);
const transformConfigExists = await storageUtil.fileExists(options.bucketName, attributes.transformPath);
if (schemaConfigExists) {
info.push(`Schema configuration found at '${schemaConfig}' in bucket: ${options.bucketName}`);
}
else {
warn.push(`Schema configuration not found at '${schemaConfig}' in bucket: ${options.bucketName}`);
}
if (transformConfigExists) {
info.push(`Transform configuration found at '${transformConfig}' in bucket: ${options.bucketName}`);
}
else {
warn.push(`Transform configuration not found at '${transformConfig}' in bucket: ${options.bucketName}`);
}
}
if (options.bucketName) {
const exists = await storageUtil.fileExists(options.bucketName, options.fileName);
if (!exists) {
errors.push(`File '${options.fileName}' not found in bucket: ${options.bucketName}`);
}
}
}
if (attributes.datasetId) {
if (attributes.datasetId.length > 1024) {
errors.push(`DatasetId '${attributes.datasetId}' exceeds maximum allowable length of 1024: ${attributes.datasetId.length}}`);
}
if (!attributes.datasetId.match(/^[A-Za-z0-9_]+$/g)) {
errors.push(`DatasetId '${attributes.datasetId}' name is invalid. See https://cloud.google.com/bigquery/docs/datasets for further information.`);
}
}
if (attributes.destinationTableId) {
if (attributes.destinationTableId.length > 1024) {
errors.push(`Destination tableId '${attributes.destinationTableId}' exceeds maximum allowable length of 1024: ${attributes.destinationTableId.length}}`);
}
if (!attributes.destinationTableId.match(/^[A-Za-z0-9_]+$/g)) {
errors.push(`Destination tableId '${attributes.destinationTableId}' name is invalid. See https://cloud.google.com/bigquery/docs/tables for further information.`);
}
}
}