-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdryrun_darwin.go
More file actions
66 lines (56 loc) · 1.61 KB
/
dryrun_darwin.go
File metadata and controls
66 lines (56 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//go:build darwin
package main
import (
"fmt"
"path/filepath"
"strings"
)
// showDryRun displays the sandbox profile that would be generated for the given configuration
func showDryRun(config *SandboxConfig) error {
fmt.Println("Sandbox Profile (dry-run):")
fmt.Println("========================================")
fmt.Println("Version: macOS Sandbox v1")
fmt.Println("Base profile: system.sb")
fmt.Println()
fmt.Println("Rules:")
if config.AllowAll {
fmt.Println("- Allow all operations (-allow-all flag)")
} else {
fmt.Println("- Allow all operations by default")
fmt.Println("- Deny all file writes")
fmt.Println("- Allow writes to:")
fmt.Println(" * System temporary directories")
if config.AllowKeychain {
fmt.Println(" * Keychain directories (-allow-keychain)")
}
// Process allowed paths
for _, path := range config.AllowedPaths {
absPath, err := filepath.Abs(path)
if err != nil {
absPath = path
}
source := "user specified"
if config.AllowGit && strings.Contains(path, ".git") {
source = "-allow-git"
}
fmt.Printf(" * %s (%s)\n", absPath, source)
}
}
fmt.Println()
fmt.Println("Raw profile:")
fmt.Println("----------------------------------------")
// Generate and display the actual profile
profile, err := generateSandboxProfile(config)
if err != nil {
return fmt.Errorf("generate sandbox profile: %w", err)
}
fmt.Print(profile)
fmt.Println("----------------------------------------")
fmt.Println()
fmt.Printf("Command: %s", config.Command)
if len(config.Args) > 0 {
fmt.Printf(" %s", strings.Join(config.Args, " "))
}
fmt.Println()
return nil
}