Implements privacy-preserving synchronization of production audit logs to development for comprehensive governance research analysis. Backend Components: - SyncMetadata.model.js: Track sync state and statistics - audit-sanitizer.util.js: Privacy sanitization utility - Redacts credentials, API keys, user identities - Sanitizes file paths and violation content - Preserves statistical patterns for research - sync-prod-audit-logs.js: CLI sync script - Incremental sync with deduplication - Dry-run mode for testing - Configurable date range - AuditLog.model.js: Enhanced schema with environment tracking - environment field (development/production/staging) - sync_metadata tracking (original_id, synced_from, etc.) - New indexes for cross-environment queries - audit.controller.js: New /api/admin/audit-export endpoint - Privacy-sanitized export for cross-environment sync - Environment filter support in getAuditLogs - MemoryProxy.service.js: Environment tagging in auditDecision() - Tags new logs with NODE_ENV or override - Sets is_local flag for tracking Frontend Components: - audit-analytics.html: Environment filter dropdown - audit-analytics.js: Environment filter query parameter handling Research Benefits: - Combine dev and prod governance statistics - Longitudinal analysis across environments - Validate framework consistency - Privacy-preserving data sharing Security: - API-based export (not direct DB access) - Admin-only endpoints with JWT authentication - Comprehensive credential redaction - One-way sync (production → development) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
65 lines
1.6 KiB
JavaScript
65 lines
1.6 KiB
JavaScript
/*
|
|
* Copyright 2025 John G Stroh
|
|
*
|
|
* 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.
|
|
*/
|
|
|
|
/**
|
|
* Sync Metadata Model
|
|
* Tracks cross-environment data synchronization state
|
|
*/
|
|
|
|
const mongoose = require('mongoose');
|
|
|
|
const syncMetadataSchema = new mongoose.Schema({
|
|
// Sync type identifier
|
|
type: {
|
|
type: String,
|
|
required: true,
|
|
unique: true,
|
|
enum: ['prod_audit', 'prod_blog', 'prod_documents']
|
|
},
|
|
|
|
// Last successful sync timestamp
|
|
last_sync_time: {
|
|
type: Date,
|
|
required: true
|
|
},
|
|
|
|
// Source environment
|
|
source_environment: {
|
|
type: String,
|
|
required: true,
|
|
enum: ['production', 'staging']
|
|
},
|
|
|
|
// Sync statistics
|
|
stats: {
|
|
total_synced: { type: Number, default: 0 },
|
|
last_batch_size: { type: Number, default: 0 },
|
|
last_batch_duration_ms: { type: Number, default: 0 },
|
|
errors_count: { type: Number, default: 0 }
|
|
},
|
|
|
|
// Last sync result
|
|
last_result: {
|
|
success: Boolean,
|
|
error_message: String,
|
|
synced_count: Number,
|
|
timestamp: Date
|
|
}
|
|
}, {
|
|
timestamps: true
|
|
});
|
|
|
|
module.exports = mongoose.model('SyncMetadata', syncMetadataSchema);
|