mirror of
https://github.com/fosrl/pangolin.git
synced 2025-07-15 16:34:52 +02:00
Indent 2
This commit is contained in:
parent
d3d523b2b8
commit
e6c42e9610
2 changed files with 40 additions and 22 deletions
|
@ -4,6 +4,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
@ -139,7 +140,8 @@ func copyEntryPoints(sourceFile, destFile string) error {
|
||||||
destYAML["entryPoints"] = entryPoints
|
destYAML["entryPoints"] = entryPoints
|
||||||
|
|
||||||
// Marshal updated destination YAML
|
// Marshal updated destination YAML
|
||||||
updatedData, err := yaml.Marshal(destYAML)
|
// updatedData, err := yaml.Marshal(destYAML)
|
||||||
|
updatedData, err := MarshalYAMLWithIndent(destYAML, 2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error marshaling updated YAML: %w", err)
|
return fmt.Errorf("error marshaling updated YAML: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -201,7 +203,8 @@ func copyWebsecureEntryPoint(sourceFile, destFile string) error {
|
||||||
destEntryPoints["websecure"] = websecure
|
destEntryPoints["websecure"] = websecure
|
||||||
|
|
||||||
// Marshal updated destination YAML
|
// Marshal updated destination YAML
|
||||||
updatedData, err := yaml.Marshal(destYAML)
|
// updatedData, err := yaml.Marshal(destYAML)
|
||||||
|
updatedData, err := MarshalYAMLWithIndent(destYAML, 2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error marshaling updated YAML: %w", err)
|
return fmt.Errorf("error marshaling updated YAML: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -264,7 +267,8 @@ func copyDockerService(sourceFile, destFile, serviceName string) error {
|
||||||
|
|
||||||
// Marshal updated destination YAML
|
// Marshal updated destination YAML
|
||||||
// Use yaml.v3 encoder to preserve formatting and comments
|
// Use yaml.v3 encoder to preserve formatting and comments
|
||||||
updatedData, err := yaml.Marshal(destCompose)
|
// updatedData, err := yaml.Marshal(destCompose)
|
||||||
|
updatedData, err := MarshalYAMLWithIndent(destCompose, 2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error marshaling updated Docker Compose file: %w", err)
|
return fmt.Errorf("error marshaling updated Docker Compose file: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -276,3 +280,36 @@ func copyDockerService(sourceFile, destFile, serviceName string) error {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func backupConfig() error {
|
||||||
|
// Backup docker-compose.yml
|
||||||
|
if _, err := os.Stat("docker-compose.yml"); err == nil {
|
||||||
|
if err := copyFile("docker-compose.yml", "docker-compose.yml.backup"); err != nil {
|
||||||
|
return fmt.Errorf("failed to backup docker-compose.yml: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Backup config directory
|
||||||
|
if _, err := os.Stat("config"); err == nil {
|
||||||
|
cmd := exec.Command("tar", "-czvf", "config.tar.gz", "config")
|
||||||
|
if err := cmd.Run(); err != nil {
|
||||||
|
return fmt.Errorf("failed to backup config directory: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func MarshalYAMLWithIndent(data interface{}, indent int) ([]byte, error) {
|
||||||
|
buffer := new(bytes.Buffer)
|
||||||
|
encoder := yaml.NewEncoder(buffer)
|
||||||
|
encoder.SetIndent(indent)
|
||||||
|
|
||||||
|
err := encoder.Encode(data)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer encoder.Close()
|
||||||
|
return buffer.Bytes(), nil
|
||||||
|
}
|
||||||
|
|
|
@ -57,25 +57,6 @@ func installCrowdsec(config Config) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func backupConfig() error {
|
|
||||||
// Backup docker-compose.yml
|
|
||||||
if _, err := os.Stat("docker-compose.yml"); err == nil {
|
|
||||||
if err := copyFile("docker-compose.yml", "docker-compose.yml.backup"); err != nil {
|
|
||||||
return fmt.Errorf("failed to backup docker-compose.yml: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Backup config directory
|
|
||||||
if _, err := os.Stat("config"); err == nil {
|
|
||||||
cmd := exec.Command("tar", "-czvf", "config.tar.gz", "config")
|
|
||||||
if err := cmd.Run(); err != nil {
|
|
||||||
return fmt.Errorf("failed to backup config directory: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func retrieveBouncerKey(config Config) error {
|
func retrieveBouncerKey(config Config) error {
|
||||||
// Start crowdsec container
|
// Start crowdsec container
|
||||||
cmd := exec.Command("docker", "compose", "up", "-d", "crowdsec")
|
cmd := exec.Command("docker", "compose", "up", "-d", "crowdsec")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue