mirror of
https://github.com/DeBrosOfficial/network.git
synced 2025-12-12 23:18:49 +00:00
- Updated `select_data_dir_check` to handle both absolute and relative config paths, improving flexibility in configuration file management. - Enhanced `DefaultPath` to check for config files in both legacy and production directories, ensuring backward compatibility. - Modified `InitializeIPFSClusterConfig` to include cluster secret management and improve error handling during initialization. - Added functionality to update the cluster secret in the service.json configuration file, enhancing security and configurability.
55 lines
1.5 KiB
Go
55 lines
1.5 KiB
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
// ConfigDir returns the path to the DeBros config directory (~/.debros).
|
|
func ConfigDir() (string, error) {
|
|
home, err := os.UserHomeDir()
|
|
if err != nil {
|
|
return "", fmt.Errorf("failed to determine home directory: %w", err)
|
|
}
|
|
return filepath.Join(home, ".debros"), nil
|
|
}
|
|
|
|
// EnsureConfigDir creates the config directory if it does not exist.
|
|
func EnsureConfigDir() (string, error) {
|
|
dir, err := ConfigDir()
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
if err := os.MkdirAll(dir, 0700); err != nil {
|
|
return "", fmt.Errorf("failed to create config directory %s: %w", dir, err)
|
|
}
|
|
return dir, nil
|
|
}
|
|
|
|
// DefaultPath returns the path to the config file for the given component name.
|
|
// component should be e.g., "node.yaml", "bootstrap.yaml", "gateway.yaml"
|
|
// It checks both ~/.debros/ and ~/.debros/configs/ for backward compatibility.
|
|
func DefaultPath(component string) (string, error) {
|
|
dir, err := ConfigDir()
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
// First check in ~/.debros/configs/ (production installer location)
|
|
configsPath := filepath.Join(dir, "configs", component)
|
|
if _, err := os.Stat(configsPath); err == nil {
|
|
return configsPath, nil
|
|
}
|
|
|
|
// Fallback to ~/.debros/ (legacy/development location)
|
|
legacyPath := filepath.Join(dir, component)
|
|
if _, err := os.Stat(legacyPath); err == nil {
|
|
return legacyPath, nil
|
|
}
|
|
|
|
// Return configs path as default (even if it doesn't exist yet)
|
|
// This allows the error message to show the expected production location
|
|
return configsPath, nil
|
|
}
|