UNPKG

@splunk/rum-cli

Version:

Tools for handling symbol and mapping files for symbolication

66 lines (65 loc) 3.17 kB
"use strict"; /* * Copyright Splunk Inc. * * 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 * * http://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. */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.isValidSplunkBuildId = exports.isValidVersionCode = exports.isValidAppId = exports.hasValidExtension = exports.isValidFile = exports.COMMON_ERROR_MESSAGES = void 0; exports.validateAndPrepareToken = validateAndPrepareToken; const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); const userFriendlyErrors_1 = require("./userFriendlyErrors"); exports.COMMON_ERROR_MESSAGES = { TOKEN_NOT_SPECIFIED: 'Error: API access token is required. Please pass it into the command as the --token option, or set using the environment variable SPLUNK_ACCESS_TOKEN', REALM_NOT_SPECIFIED: 'Error: Realm is required and cannot be empty. Please pass it into the command as the --realm option, or set using the environment variable SPLUNK_REALM', HELP_MESSAGE_AFTER_ERROR: `\nRun the command with '--help' for more information` }; // Check if a file exists const isValidFile = (filePath) => { return fs_1.default.existsSync(filePath); }; exports.isValidFile = isValidFile; // Check if a file has correct extension type const hasValidExtension = (filePath, ...expectedExtensions) => { const ext = path_1.default.extname(filePath); return expectedExtensions.includes(ext); }; exports.hasValidExtension = hasValidExtension; // Validate applicationID (should be a non-empty string) const isValidAppId = (appId) => { return typeof appId === 'string' && appId.length > 0; }; exports.isValidAppId = isValidAppId; // Validate app versionCode (should be an integer or a string representation of a integer) const isValidVersionCode = (versionCode) => { return typeof versionCode === 'number' && Number.isInteger(versionCode) || (typeof versionCode === 'string' && Number.isInteger(Number(versionCode))); }; exports.isValidVersionCode = isValidVersionCode; // Validate Splunk Build ID (should be a string) const isValidSplunkBuildId = (splunkBuildId) => { return splunkBuildId !== undefined && typeof splunkBuildId === 'string' && splunkBuildId.length > 0; }; exports.isValidSplunkBuildId = isValidSplunkBuildId; // Validate token function validateAndPrepareToken(options) { const token = options.token || process.env.SPLUNK_ACCESS_TOKEN; if (!token) { throw new userFriendlyErrors_1.UserFriendlyError(null, exports.COMMON_ERROR_MESSAGES.TOKEN_NOT_SPECIFIED); } return token; }