-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathconfig.go
More file actions
56 lines (44 loc) · 1.1 KB
/
config.go
File metadata and controls
56 lines (44 loc) · 1.1 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
package cmd
import (
"fmt"
"strings"
"github.com/chatwoot/cli/internal/config"
"github.com/chatwoot/cli/internal/output"
)
type ConfigCmd struct {
Path ConfigPathCmd `cmd:"" help:"Print the config file path."`
View ConfigViewCmd `cmd:"" help:"Print current configuration."`
}
type ConfigPathCmd struct{}
func (c *ConfigPathCmd) Run(app *App) error {
path, err := config.ConfigPath()
if err != nil {
return err
}
fmt.Println(path)
return nil
}
type ConfigViewCmd struct{}
func (c *ConfigViewCmd) Run(app *App) error {
cfg, err := config.Load()
if err != nil {
return err
}
if cfg == nil {
fmt.Println("No configuration found. Run 'chatwoot auth login' to set up.")
return nil
}
maskedKey := maskAPIKey(cfg.APIKey)
app.Printer.PrintDetail([]output.KeyValue{
{Key: "Base URL", Value: cfg.BaseURL},
{Key: "API Key", Value: maskedKey},
{Key: "Account ID", Value: fmt.Sprintf("%d", cfg.AccountID)},
})
return nil
}
func maskAPIKey(key string) string {
if len(key) <= 8 {
return strings.Repeat("*", len(key))
}
return key[:4] + strings.Repeat("*", len(key)-8) + key[len(key)-4:]
}