git » chasquid » commit 4753565

chasquid-util: Remove `aliases-add` subcommand

author Alberto Bertogli
2023-08-09 23:12:56 UTC
committer Alberto Bertogli
2023-08-09 23:12:56 UTC
parent 57ee3733f4b59f73da65a6c4378dab7c21053b1b

chasquid-util: Remove `aliases-add` subcommand

The aliases-add subcommand was added before aliases hooks were
implemented and polished, it is undocumented, and the implementation is
nowadays a bit brittle, has some rough edges, and adds significant code
complexity to chasquid-util.

AFAIK nobody is using it either (checked with some specific folks
directly, and it's not very discoverable either).

For all those reasons, this patch removes it.

cmd/chasquid-util/chasquid-util.go +0 -60
cmd/chasquid-util/test.sh +0 -24

diff --git a/cmd/chasquid-util/chasquid-util.go b/cmd/chasquid-util/chasquid-util.go
index 75d9cce..2a48986 100644
--- a/cmd/chasquid-util/chasquid-util.go
+++ b/cmd/chasquid-util/chasquid-util.go
@@ -16,7 +16,6 @@ import (
 	"strings"
 	"syscall"
 
-	"blitiri.com.ar/go/chasquid/internal/aliases"
 	"blitiri.com.ar/go/chasquid/internal/config"
 	"blitiri.com.ar/go/chasquid/internal/envelope"
 	"blitiri.com.ar/go/chasquid/internal/localrpc"
@@ -37,7 +36,6 @@ Usage:
   chasquid-util [options] aliases-resolve <address>
   chasquid-util [options] domaininfo-remove <domain>
   chasquid-util [options] print-config
-  chasquid-util [options] aliases-add <source> <target>
 
 Options:
   -C=<path>, --configdir=<path>  Configuration directory
@@ -80,7 +78,6 @@ func main() {
 		"aliases-resolve":   aliasesResolve,
 		"print-config":      printConfig,
 		"domaininfo-remove": domaininfoRemove,
-		"aliases-add":       aliasesAdd,
 	}
 
 	cmd := args["$1"]
@@ -274,63 +271,6 @@ func allUsersExist(tr *trace.Trace, user, domain string) (bool, error) {
 	return true, nil
 }
 
-// chasquid-util aliases-add <source> <target>
-func aliasesAdd() {
-	source := args["$2"]
-	target := args["$3"]
-
-	user, domain := envelope.Split(source)
-	if domain == "" {
-		Fatalf("Domain required in source address")
-	}
-
-	if target == "" {
-		Fatalf("Target must be present")
-	}
-
-	// Ensure the domain exists.
-	if _, err := os.Stat(filepath.Join(configDir, "domains", domain)); os.IsNotExist(err) {
-		Fatalf("Domain doesn't exist")
-	}
-
-	conf, err := config.Load(configDir+"/chasquid.conf", "")
-	if err != nil {
-		Fatalf("Error loading config: %v", err)
-	}
-	_ = os.Chdir(configDir)
-
-	// Setup alias resolver.
-	r := aliases.NewResolver(allUsersExist)
-	r.SuffixSep = *conf.SuffixSeparators
-	r.DropChars = *conf.DropCharacters
-
-	r.AddDomain(domain)
-	aliasesFilePath := filepath.Join("domains", domain, "aliases")
-	if err := r.AddAliasesFile(domain, aliasesFilePath); err != nil {
-		Fatalf("%s: error loading %q: %v", domain, aliasesFilePath, err)
-	}
-
-	tr := trace.New("chasquid-util", "aliasesAdd")
-	defer tr.Finish()
-
-	// Check for existing entry.
-	if _, ok := r.Exists(tr, source); ok {
-		Fatalf("There's already an entry for %v", source)
-	}
-
-	// Append the new entry.
-	aliasesFile, err := os.OpenFile(aliasesFilePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
-	if err != nil {
-		Fatalf("Couldn't open %s: %v", aliasesFilePath, err)
-	}
-	_, err = fmt.Fprintf(aliasesFile, "%s: %s\n", user, target)
-	if err != nil {
-		Fatalf("Couldn't write to %s: %v", aliasesFilePath, err)
-	}
-	aliasesFile.Close()
-	fmt.Println("Added alias")
-}
-
 // parseArgs parses the command line arguments, and returns a map.
 //
 // Arguments starting with "-" will be parsed as key-value pairs, and
diff --git a/cmd/chasquid-util/test.sh b/cmd/chasquid-util/test.sh
index 65cda22..c659435 100755
--- a/cmd/chasquid-util/test.sh
+++ b/cmd/chasquid-util/test.sh
@@ -78,30 +78,6 @@ if ! ( echo "$C" | grep -E -q "hostname:.*\"$HOSTNAME\"" ); then
 	exit 1
 fi
 
-if r aliases-add alias2@domain target > /dev/null; then
-	A=$(grep alias2 .config/domains/domain/aliases)
-	if [ "$A" != "alias2: target" ]; then
-		echo aliases-add failed
-		echo output: "$A"
-		exit 1
-	fi
-fi
-
-if r aliases-add alias2@domain target > /dev/null; then
-	echo aliases-add on existing alias worked
-	exit 1
-fi
-
-if r aliases-add alias3@notexist target > /dev/null; then
-	echo aliases-add on non-existing domain worked
-	exit 1
-fi
-
-if r aliases-add alias4@domain > /dev/null; then
-	echo aliases-add without target worked
-	exit 1
-fi
-
 # Run all the chamuyero tests.
 for i in *.cmy; do
 	if ! chamuyero "$i" > "$i.log" 2>&1 ; then