From b37b53d59420c3971e07527d9fcacf1492cec3ac Mon Sep 17 00:00:00 2001 From: amanjpro Date: Tue, 3 Dec 2024 16:07:16 -0500 Subject: [PATCH 1/2] Support system path systems everywhere --- pkg/cmd/cli/key.go | 6 +++++- pkg/cmd/main.go | 3 ++- pkg/pair/match.go | 5 +++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/pkg/cmd/cli/key.go b/pkg/cmd/cli/key.go index 6cebbd4..2b1e9dc 100644 --- a/pkg/cmd/cli/key.go +++ b/pkg/cmd/cli/key.go @@ -30,7 +30,11 @@ func (c *CreateCmd) Run(cli *CmdContext) error { fmt.Println("The following key has been generated and saved to: ", cli.config.configPath) } else { - fmt.Printf("Key already exists at: %s. Use --force to overwrite.\n", cli.config.configPath) + fmt.Printf(`Key already exists at: %s. + +!!CAUTION!! +You may overwrite this existing key but this action is irreversible and may invalidate any PAIR clean rooms that are currently in progress. Use --force to proceed with overwriting. +`, cli.config.configPath) } return nil diff --git a/pkg/cmd/main.go b/pkg/cmd/main.go index f9afa40..4bef136 100644 --- a/pkg/cmd/main.go +++ b/pkg/cmd/main.go @@ -2,6 +2,7 @@ package main import ( "optable-pair-cli/pkg/cmd/cli" + "path/filepath" "github.com/adrg/xdg" "github.com/alecthomas/kong" @@ -24,7 +25,7 @@ https://github.com/Optable/match/blob/main/pkg/pair/README.md and https://iabtechlab.com/pair/ ` -const keyConfigPath = "opair/key/key.json" +var keyConfigPath = filepath.Join("opair", "key", "key.json") func main() { var c cli.Cli diff --git a/pkg/pair/match.go b/pkg/pair/match.go index e63ae95..9c5168c 100644 --- a/pkg/pair/match.go +++ b/pkg/pair/match.go @@ -8,6 +8,7 @@ import ( "optable-pair-cli/pkg/io" "optable-pair-cli/pkg/keys" "os" + "path/filepath" "runtime" "strings" "sync/atomic" @@ -104,8 +105,8 @@ func (w *writer) NewWriter(index int) (*csv.Writer, error) { return csv.NewWriter(os.Stdout), nil } - p := strings.TrimRight(w.path, "/") - f, err := os.Create(fmt.Sprintf("%s/result_%d.csv", p, index)) + p := strings.TrimRight(w.path, string(filepath.Separator)) + f, err := os.Create(filepath.Join(p, fmt.Sprintf("result_%d.csv", index))) if err != nil { return nil, err } From 61ab746efa6a71d943f0893e7e21953ff6aebe16 Mon Sep 17 00:00:00 2001 From: amanjpro Date: Thu, 5 Dec 2024 13:30:10 -0500 Subject: [PATCH 2/2] Fix the key config panic, when it is missing --- pkg/cmd/cli/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/cmd/cli/config.go b/pkg/cmd/cli/config.go index 27d94a5..067e71d 100644 --- a/pkg/cmd/cli/config.go +++ b/pkg/cmd/cli/config.go @@ -96,7 +96,7 @@ func ReadKeyConfig(context string, config *Config) (string, error) { if err != nil { return "", err } - if config.keyConfig.Key == "" { + if config.keyConfig == nil || config.keyConfig.Key == "" { return "", errors.New("malformed key configuration file, please regenerate the key") }