UNPKG

@backstage-community/plugin-rbac-backend

Version:
46 lines (42 loc) 1.47 kB
'use strict'; var errors = require('@backstage/errors'); const MAX_PLUGIN_IDS = 100; const MAX_PLUGIN_ID_LENGTH = 64; function validatePermissionDependentPlugin(plugin) { if (!plugin || typeof plugin !== "object") { throw new errors.InputError( `'ids' must be specified in the permission dependent plugin` ); } const list = plugin; if (!list.ids) { throw new errors.InputError( `'ids' must be specified in the permission dependent plugin` ); } if (!Array.isArray(list.ids) || !list.ids.every((id) => typeof id === "string")) { throw new errors.InputError(`'ids' must be an array of string plugin ID values`); } if (list.ids.length === 0) { throw new errors.InputError(`'ids' must contain at least one plugin ID`); } if (list.ids.length > MAX_PLUGIN_IDS) { throw new errors.InputError( `'ids' can include at most ${MAX_PLUGIN_IDS} plugin IDs` ); } const uniqueIds = /* @__PURE__ */ new Set(); for (const id of list.ids) { if (id.length === 0 || id.length > MAX_PLUGIN_ID_LENGTH) { throw new errors.InputError( `plugin ID '${id}' must be between 1 and ${MAX_PLUGIN_ID_LENGTH} characters` ); } if (uniqueIds.has(id)) { throw new errors.InputError(`'ids' contains duplicate plugin ID '${id}'`); } uniqueIds.add(id); } } exports.validatePermissionDependentPlugin = validatePermissionDependentPlugin; //# sourceMappingURL=plugin-validation.cjs.js.map