validate plugin and module ids

Signed-off-by: Juan Pablo Garcia Ripa <sarabadu@gmail.com>
This commit is contained in:
Juan Pablo Garcia Ripa
2025-07-09 21:33:23 +02:00
parent 4ad63b8d9f
commit 5766fc71c6
9 changed files with 109 additions and 10 deletions
@@ -14,6 +14,7 @@
* limitations under the License.
*/
import { CONFIG_KEY_PART_PATTERN } from '@backstage/config';
import { BackendFeature } from '../types';
import {
BackendModuleRegistrationPoints,
@@ -55,6 +56,12 @@ export function createBackendModule(
options: CreateBackendModuleOptions,
): BackendFeature {
function getRegistrations() {
if (!CONFIG_KEY_PART_PATTERN.test(options.moduleId)) {
throw new Error(
`Invalid moduleId '${options.moduleId}' for plugin '${options.pluginId}', must match the pattern ${CONFIG_KEY_PART_PATTERN} (letters, digits, dashes, and underscores only, starting with a letter)`,
);
}
const extensionPoints: InternalBackendPluginRegistration['extensionPoints'] =
[];
let init: InternalBackendModuleRegistration['init'] | undefined = undefined;
@@ -14,6 +14,7 @@
* limitations under the License.
*/
import { CONFIG_KEY_PART_PATTERN } from '@backstage/config';
import { BackendFeature } from '../types';
import {
BackendPluginRegistrationPoints,
@@ -49,6 +50,12 @@ export function createBackendPlugin(
options: CreateBackendPluginOptions,
): BackendFeature {
function getRegistrations() {
if (!CONFIG_KEY_PART_PATTERN.test(options.pluginId)) {
throw new Error(
`Invalid pluginId '${options.pluginId}', must match the pattern ${CONFIG_KEY_PART_PATTERN} (letters, digits, dashes, and underscores only, starting with a letter)`,
);
}
const extensionPoints: InternalBackendPluginRegistration['extensionPoints'] =
[];
let init: InternalBackendPluginRegistration['init'] | undefined = undefined;