add feature license management

This commit is contained in:
Warp Agent
2026-01-04 12:54:25 +07:00
parent 7543b3a850
commit 2bb64620d4
29 changed files with 5447 additions and 22 deletions

View File

@@ -1830,6 +1830,59 @@ func (s *Service) WriteConfig(ctx context.Context, configPath string) error {
return nil
}
// ReadConfigFile reads the SCST configuration file content
func (s *Service) ReadConfigFile(ctx context.Context, configPath string) (string, error) {
// First, write current config to temp file to get the actual config
tempPath := "/tmp/scst_config_read.conf"
cmd := exec.CommandContext(ctx, "sudo", "scstadmin", "-write_config", tempPath)
output, err := cmd.CombinedOutput()
if err != nil {
return "", fmt.Errorf("failed to write SCST config: %s: %w", string(output), err)
}
// Read the config file
configData, err := os.ReadFile(tempPath)
if err != nil {
return "", fmt.Errorf("failed to read config file: %w", err)
}
return string(configData), nil
}
// WriteConfigFile writes content to SCST configuration file
func (s *Service) WriteConfigFile(ctx context.Context, configPath string, content string) error {
// Write content to temp file first
tempPath := "/tmp/scst_config_write.conf"
if err := os.WriteFile(tempPath, []byte(content), 0644); err != nil {
return fmt.Errorf("failed to write temp config file: %w", err)
}
// Use scstadmin to load the config (this validates and applies it)
cmd := exec.CommandContext(ctx, "sudo", "scstadmin", "-config", tempPath)
output, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("failed to load SCST config: %s: %w", string(output), err)
}
// Write to the actual config path using sudo
if configPath != tempPath {
// Use sudo cp to copy temp file to actual config path
cpCmd := exec.CommandContext(ctx, "sudo", "cp", tempPath, configPath)
cpOutput, cpErr := cpCmd.CombinedOutput()
if cpErr != nil {
return fmt.Errorf("failed to copy config file: %s: %w", string(cpOutput), cpErr)
}
// Set proper permissions
chmodCmd := exec.CommandContext(ctx, "sudo", "chmod", "644", configPath)
if chmodErr := chmodCmd.Run(); chmodErr != nil {
s.logger.Warn("Failed to set config file permissions", "error", chmodErr)
}
}
s.logger.Info("SCST configuration file written", "path", configPath)
return nil
}
// HandlerInfo represents SCST handler information
type HandlerInfo struct {
Name string `json:"name"`