Skip to content

Commit

Permalink
return the cleanup func to be optionally called and explain why.
Browse files Browse the repository at this point in the history
  • Loading branch information
nonrational committed Aug 12, 2020
1 parent 9e7d7d6 commit 3e9e519
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
8 changes: 7 additions & 1 deletion cmd/puma-dev/main_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,13 @@ func main() {
}

if *fUninstall {
dev.Uninstall(LaunchAgentDirPath, domains)
onlyDeleteNowUntrustedCertAndKeyInProductionPathFunc := dev.Uninstall(LaunchAgentDirPath, domains)
// FIXME: As part of running tests interactively on macOS, we can't delete .cert/.key
// generated as part of test runs. But, we don't want to leave untrusted .cert/.key's
// hanging around post-uninstall. So, we delete them as part of the main codepath but
// ignore this returned func during testing. Eventually, when the cert/key can be
// stored in the macOS keychain, we can rely on that to avoid this.
onlyDeleteNowUntrustedCertAndKeyInProductionPathFunc()
return
}

Expand Down
17 changes: 10 additions & 7 deletions dev/setup_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func InstallIntoSystem(config *InstallIntoSystemArgs) error {
return nil
}

func Uninstall(launchAgentDirPath string, domains []string) {
func Uninstall(launchAgentDirPath string, domains []string) func() {
// Default: ~/Library/LaunchAgents/
plistDir := homedir.MustExpand(launchAgentDirPath)
plist := filepath.Join(plistDir, "io.puma.dev.plist")
Expand All @@ -212,17 +212,20 @@ func Uninstall(launchAgentDirPath string, domains []string) {
os.Remove(plist)
fmt.Printf("* Removed puma-dev from automatically running\n")

for _, d := range domains {
os.Remove(filepath.Join("/etc/resolver", d))
fmt.Printf("* Removed domain '%s'\n", d)
}

// Remove all `Puma-dev CA` certificate entries from macOS keychain
if err := DeleteAllPumaDevCAFromDefaultKeychain(); err != nil {
fmt.Printf("! Unable to remove all Puma-dev CA certs from macOS keychain: %s\n", err)
return func() {}
} else {
expandedSupportDir := homedir.MustExpand(SupportDir)
fmt.Printf("* Removed all Puma-dev CA certs from macOS keychain.\n")
fmt.Printf("! Before re-installing, please delete %s\n", expandedSupportDir)
}

for _, d := range domains {
os.Remove(filepath.Join("/etc/resolver", d))
fmt.Printf("* Removed domain '%s'\n", d)
return func() {
os.RemoveAll(homedir.MustExpand(SupportDir))
}
}
}

0 comments on commit 3e9e519

Please sign in to comment.