39054-vm/backend/src/db/models/data_sources.js
2026-03-08 20:32:56 +00:00

226 lines
2.3 KiB
JavaScript

const config = require('../../config');
const providers = config.providers;
const crypto = require('crypto');
const bcrypt = require('bcrypt');
const moment = require('moment');
module.exports = function(sequelize, DataTypes) {
const data_sources = sequelize.define(
'data_sources',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
name: {
type: DataTypes.TEXT,
},
source_type: {
type: DataTypes.ENUM,
values: [
"siem",
"edr",
"ids_ips",
"firewall",
"proxy",
"dns",
"cloud_logs",
"kubernetes_audit",
"endpoint",
"threat_feed",
"dark_web",
"vulnerability_scanner",
"email_gateway",
"web_gateway",
"custom_api"
],
},
status: {
type: DataTypes.ENUM,
values: [
"active",
"paused",
"error",
"onboarding"
],
},
connector_type: {
type: DataTypes.TEXT,
},
endpoint_url: {
type: DataTypes.TEXT,
},
auth_method: {
type: DataTypes.TEXT,
},
poll_interval_seconds: {
type: DataTypes.INTEGER,
},
last_ingested_at: {
type: DataTypes.DATE,
},
notes: {
type: DataTypes.TEXT,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
data_sources.associate = (db) => {
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
db.data_sources.hasMany(db.telemetry_events, {
as: 'telemetry_events_data_source',
foreignKey: {
name: 'data_sourceId',
},
constraints: false,
});
//end loop
db.data_sources.belongsTo(db.organizations, {
as: 'organization',
foreignKey: {
name: 'organizationId',
},
constraints: false,
});
db.data_sources.belongsTo(db.users, {
as: 'createdBy',
});
db.data_sources.belongsTo(db.users, {
as: 'updatedBy',
});
};
return data_sources;
};