| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "bufio" |
| 5 | "fmt" |
| 6 | "os" |
| 7 | "strings" |
| 8 | "syscall" |
| 9 | |
| 10 | "github.com/stevedylandev/andromeda/apps/sipp/tui" |
| 11 | "golang.org/x/term" |
| 12 | ) |
| 13 | |
| 14 | func runAuth(_ []string) { |
| 15 | cfg, _ := tui.LoadConfig() |
| 16 | reader := bufio.NewReader(os.Stdin) |
| 17 | |
| 18 | defaultURL := cfg.RemoteURL |
| 19 | if defaultURL == "" { |
| 20 | defaultURL = "http://localhost:3000" |
| 21 | } |
| 22 | fmt.Printf("Remote URL [%s]: ", defaultURL) |
| 23 | line, _ := reader.ReadString('\n') |
| 24 | line = strings.TrimSpace(line) |
| 25 | if line != "" { |
| 26 | cfg.RemoteURL = line |
| 27 | } else { |
| 28 | cfg.RemoteURL = defaultURL |
| 29 | } |
| 30 | |
| 31 | fmt.Print("API key (hidden): ") |
| 32 | keyBytes, err := term.ReadPassword(int(syscall.Stdin)) |
| 33 | fmt.Println() |
| 34 | if err != nil { |
| 35 | fmt.Fprintln(os.Stderr, "read api key:", err) |
| 36 | os.Exit(1) |
| 37 | } |
| 38 | if k := strings.TrimSpace(string(keyBytes)); k != "" { |
| 39 | cfg.APIKey = k |
| 40 | } |
| 41 | |
| 42 | if err := tui.SaveConfig(cfg); err != nil { |
| 43 | fmt.Fprintln(os.Stderr, "save config:", err) |
| 44 | os.Exit(1) |
| 45 | } |
| 46 | path, _ := tui.ConfigPath() |
| 47 | fmt.Println("Saved", path) |
| 48 | } |