Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/zizmor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
persist-credentials: false

- name: Install the latest version of uv
uses: astral-sh/setup-uv@5a095e7a2014a4212f075830d4f7277575a9d098 # v7.3.1
uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7.6.0

- name: Run zizmor 🌈
run: uvx zizmor --pedantic --format sarif . > results.sarif
Expand Down
80 changes: 63 additions & 17 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
package cmd

import (
"bytes"
"fmt"
"net/url"
"os"
"os/exec"
"path/filepath"
"slices"
"strconv"
Expand Down Expand Up @@ -929,13 +931,10 @@ func (tui *appContext) buildCachingPage() tview.Primitive {
tui.showCacheConfirmationModal(cacheSizeText,
// Callback function if the user selects Finish
func() {
if err := tui.createYAMLConfig(); err != nil {
tui.showErrorModal(
"[red::b]ERROR:[-::-] Failed to create YAML config:\n"+err.Error(),
func() {
tui.pages.SwitchToPage("page5")
},
)
if err := tui.exitConfig(); err != nil {
tui.showErrorModal("[red::b]ERROR:[-::-]\n"+err.Error(), func() {
tui.pages.SwitchToPage("page5")
})
return
}
tui.showExitModal(func() {
Expand All @@ -949,13 +948,10 @@ func (tui *appContext) buildCachingPage() tview.Primitive {

} else {
// If caching is disabled, just finish the configuration
if err := tui.createYAMLConfig(); err != nil {
tui.showErrorModal(
"[red::b]ERROR:[-::-] Failed to create YAML config:\n"+err.Error(),
func() {
tui.pages.SwitchToPage("page5")
},
)
if err := tui.exitConfig(); err != nil {
tui.showErrorModal("[red::b]ERROR:[-::-]\n"+err.Error(), func() {
tui.pages.SwitchToPage("page5")
})
return
}
tui.showExitModal(func() {
Expand Down Expand Up @@ -1218,6 +1214,56 @@ func (tui *appContext) showExitModal(onConfirm func()) {
}()
}

// Function to handle exiting the configuration process.
// Creates the YAML config file and executes a dry run.
func (tui *appContext) exitConfig() error {
if err := tui.createYAMLConfig(); err != nil {
return fmt.Errorf("Failed to create YAML config:\n%v", err)
}
if err := tui.dryRun(); err != nil {
return fmt.Errorf("Configuration validation failed:\n%v", err)
}
return nil
}

// Function to perform a dry run of cloudfuse with the generated config file.
func (tui *appContext) dryRun() error {
// Create /tmp/mnt-test directory if it doesn't exist. Needs to be empty for dry run.
mountPoint := filepath.Join(os.TempDir(), "mnt-test")
if _, err := os.Stat(mountPoint); os.IsNotExist(err) {
if err := os.MkdirAll(mountPoint, 0700); err != nil {
return fmt.Errorf(
"Failed to create test mount point '%s' for dry run: %v",
mountPoint,
err,
)
}
}

// Spawn child process to run cloudfuse with the generated config file and --dry-run flag
cmd := exec.Command(
"cloudfuse",
"mount",
mountPoint,
"--config-file",
tui.config.configFilePath,
"--dry-run",
"--passphrase",
tui.config.configEncryptionPassphrase,
)

// Capture stdout and stderr
var outBuf, errBuf bytes.Buffer
cmd.Stdout = &outBuf
cmd.Stderr = &errBuf
err := cmd.Run()
if err != nil {
return fmt.Errorf("Dry run failed: %v\n%s", err, errBuf.String())
}

return nil
}

// Helper function to center lines of text within a specified width.
// It is used to format text views and other UI elements in the TUI.
func centerText(text string, width int) string {
Expand Down Expand Up @@ -1498,8 +1544,8 @@ func (tui *appContext) createYAMLConfig() error {
}

// Write the encrypted YAML config data to a file
if err := os.WriteFile("config.aes", cipherText, 0600); err != nil {
return fmt.Errorf("Failed to create encrypted config.aes file: %v", err)
if err := os.WriteFile("config.yaml.aes", cipherText, 0600); err != nil {
return fmt.Errorf("Failed to create encrypted config.yaml.aes file: %v", err)
}

// Update configFilePath member to point to the created config file
Expand All @@ -1508,7 +1554,7 @@ func (tui *appContext) createYAMLConfig() error {
return fmt.Errorf("Failed to get current working directory: %v", err)
}

tui.config.configFilePath = filepath.Join(currDir, "config.aes")
tui.config.configFilePath = filepath.Join(currDir, "config.yaml.aes")

return nil
}
Binary file added config.yaml.aes
Binary file not shown.
Loading