mirror of
https://github.com/StarFleetCPTN/GoMFT.git
synced 2026-10-27 07:20:27 +01:00
feat: Implement storage provider management functionality
- Added new routes and handlers for managing storage providers, including creation, editing, and deletion. - Introduced a new StorageProvider form component for user input. - Enhanced the database schema to support storage provider references in transfer configurations. - Implemented encryption for sensitive fields in storage provider data. - Added tests for storage provider API endpoints and integration with the database. - Updated frontend components to support storage provider selection and testing.
This commit is contained in:
1 parent
88d0ac815a
commit
31871bd16e
59 files changed
+15842
-594
No files matched your search
+62
-2
@@ -6,12 +6,14 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/glebarez/sqlite"
|
||||
"github.com/starfleetcptn/gomft/internal/db/middleware"
|
||||
"github.com/starfleetcptn/gomft/internal/db/migrations"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type DB struct {
|
||||
*gorm.DB
|
||||
encryptionMiddleware *middleware.EncryptionMiddleware
|
||||
}
|
||||
|
||||
func Initialize(dbPath string) (*DB, error) {
|
||||
@@ -48,7 +50,17 @@ func Initialize(dbPath string) (*DB, error) {
|
||||
return nil, fmt.Errorf("failed to reconnect to database after migrations: %v", err)
|
||||
}
|
||||
|
||||
return &DB{DB: db}, nil
|
||||
// Initialize and register the encryption middleware
|
||||
encryptionMiddleware, err := middleware.NewEncryptionMiddleware()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to initialize encryption middleware: %v", err)
|
||||
}
|
||||
encryptionMiddleware.RegisterHooks(db)
|
||||
|
||||
return &DB{
|
||||
DB: db,
|
||||
encryptionMiddleware: encryptionMiddleware,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ReopenWithoutMigrations reopens the database connection without running migrations
|
||||
@@ -60,7 +72,17 @@ func ReopenWithoutMigrations(dbPath string) (*DB, error) {
|
||||
return nil, fmt.Errorf("failed to connect to database: %v", err)
|
||||
}
|
||||
|
||||
return &DB{DB: db}, nil
|
||||
// Initialize and register the encryption middleware
|
||||
encryptionMiddleware, err := middleware.NewEncryptionMiddleware()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to initialize encryption middleware: %v", err)
|
||||
}
|
||||
encryptionMiddleware.RegisterHooks(db)
|
||||
|
||||
return &DB{
|
||||
DB: db,
|
||||
encryptionMiddleware: encryptionMiddleware,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (db *DB) Close() error {
|
||||
@@ -70,3 +92,41 @@ func (db *DB) Close() error {
|
||||
}
|
||||
return sqlDB.Close()
|
||||
}
|
||||
|
||||
// EnableEncryption enables the encryption middleware
|
||||
func (db *DB) EnableEncryption() {
|
||||
if db.encryptionMiddleware != nil {
|
||||
db.encryptionMiddleware.Enable()
|
||||
}
|
||||
}
|
||||
|
||||
// DisableEncryption disables the encryption middleware
|
||||
func (db *DB) DisableEncryption() {
|
||||
if db.encryptionMiddleware != nil {
|
||||
db.encryptionMiddleware.Disable()
|
||||
}
|
||||
}
|
||||
|
||||
// IsEncryptionEnabled returns whether the encryption middleware is enabled
|
||||
func (db *DB) IsEncryptionEnabled() bool {
|
||||
if db.encryptionMiddleware != nil {
|
||||
return db.encryptionMiddleware.IsEnabled()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Connect initializes a database connection using the default path
|
||||
// This is used by CLI commands to connect to the database
|
||||
func Connect() (*DB, error) {
|
||||
// Get data directory from environment or use default
|
||||
dataDir := os.Getenv("DATA_DIR")
|
||||
if dataDir == "" {
|
||||
dataDir = "./data"
|
||||
}
|
||||
|
||||
// Use default database path
|
||||
dbPath := filepath.Join(dataDir, "gomft.db")
|
||||
|
||||
// Initialize the database
|
||||
return Initialize(dbPath)
|
||||
}
|
||||
Reference in new issue
Block a user