cec0d92c25
Generalize the half-built discovery plugins into a real plugin system: plugin TYPES (the plugins/<category>/<type>.js modules with manifests) and loadable, configurable, multi-copy plugin INSTANCES (PluginInstance ORM model) managed from a dedicated /plugins page and /api/plugins API, with per-instance secrets in OpenBao at secret/plugins/<id>/conf. - plugin_registry.js: getTypes/getModule/splitConfig/mask + required-field helpers - PluginInstance model (Sequelize): id/pluginType/category/name/slug(unique)/ enabled/cron/config(json, non-secret)/lastRun*; registered in models/index.js - plugin_secrets.js: read/write/remove/mergeForRun over @simpleworkjs/bao-conf - scheduler.js: schedules from the DB registry; per-instance stable BullMQ JobScheduler ids (plugin:<id>) for load/unload; legacy migration from conf.discovery.plugins on first boot (idempotent, empty-table-guarded) - api_plugins.js (replaces routes/plugins.js): types/list/get/create/update/ secrets/test/load/unload/run/delete/runs; admin-gated; secrets always masked - /plugins page (plugins.ejs) + nav; Agents & Scheduler tab removed from /directory; /docs/agents aliased to /docs/plugins - proxmox/unifi/nmap gained manifests (configSchema/validate/run alias) - tests/plugins.test.js: registry unit + plugin_secrets (mocked bao-conf) + PluginInstance model round-trip/unique-slug - docs (plugins.md, vault.md, _config.yml, API.md) + 1.16.1 -> 1.17.0 Requires theta-suite >= v1.30.1 for the sso-broker secret/plugins/* grant; fails-soft with a clear error if absent. Co-Authored-By: Claude <noreply@anthropic.com>
46 lines
1.5 KiB
JavaScript
46 lines
1.5 KiB
JavaScript
'use strict';
|
|
|
|
const conf = require('@simpleworkjs/conf');
|
|
const { setUpTable } = require('model-redis');
|
|
|
|
// Keep model-redis for the ones not yet ported
|
|
const Table = setUpTable(conf.redis);
|
|
module.exports = Table;
|
|
|
|
const { Token, AuthToken, InviteToken, ImpersonationToken, PasswordResetToken, OtpToken, ServiceToken } = require('./token');
|
|
require('./verification');
|
|
require('./oauth_code');
|
|
require('./api_token');
|
|
|
|
const { init } = require('@simpleworkjs/orm');
|
|
const { Resource, ResourceEdge, ResourceGroup } = require('./resource');
|
|
const { AccessRequest } = require('./access_request');
|
|
const { Webhook } = require('./webhook');
|
|
const { PluginInstance } = require('./plugin_instance');
|
|
async function initORM() {
|
|
const ormConf = conf.orm || {
|
|
dialect: 'sqlite',
|
|
storage: './config/inventory.sqlite',
|
|
logging: false
|
|
};
|
|
ormConf.redis = conf.redis;
|
|
|
|
console.log('[initORM] Starting ORM initialization...');
|
|
try {
|
|
await init({
|
|
conf: { orm: ormConf },
|
|
models: [
|
|
Resource, ResourceEdge, ResourceGroup, AccessRequest, Webhook, PluginInstance,
|
|
Token, AuthToken, InviteToken, ImpersonationToken, PasswordResetToken, OtpToken, ServiceToken
|
|
]
|
|
});
|
|
console.log('[initORM] ORM initialized successfully');
|
|
console.log('[initORM] Resource.orm =', !!Resource.orm, 'Token.orm =', !!Token.orm);
|
|
} catch (err) {
|
|
console.error('[initORM] ORM initialization failed:', err.message);
|
|
throw err;
|
|
}
|
|
}
|
|
|
|
module.exports.initORM = initORM;
|