+11
-11
keyfetch/keyfetch.go
+11
-11
keyfetch/keyfetch.go
···
31
Value: "http://localhost:5444",
32
},
33
&cli.StringFlag{
34
-
Name: "repoguard-path",
35
-
Usage: "path to the repoguard binary",
36
-
Value: "/home/git/repoguard",
37
-
},
38
-
&cli.StringFlag{
39
Name: "git-dir",
40
Usage: "base directory for git repos",
41
Value: "/home/git",
···
50
}
51
52
func Run(ctx context.Context, cmd *cli.Command) error {
53
internalApi := cmd.String("internal-api")
54
-
repoguardPath := cmd.String("repoguard-path")
55
gitDir := cmd.String("git-dir")
56
logPath := cmd.String("log-path")
57
output := cmd.String("output")
58
59
-
l := log.FromContext(ctx)
60
61
resp, err := http.Get(internalApi + "/keys")
62
if err != nil {
···
91
return err
92
}
93
case "authorized-keys":
94
-
formatted := formatKeyData(repoguardPath, gitDir, logPath, internalApi, data)
95
_, err := os.Stdout.Write([]byte(formatted))
96
if err != nil {
97
l.Error("error writing to stdout", "error", err)
···
110
return nil
111
}
112
113
-
func formatKeyData(repoguardPath, gitDir, logPath, endpoint string, data []map[string]any) string {
114
var result string
115
for _, entry := range data {
116
result += fmt.Sprintf(
117
-
`command="%s -base-dir %s -user %s -log-path %s -internal-api %s",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty %s`+"\n",
118
-
repoguardPath, gitDir, entry["did"], logPath, endpoint, entry["key"])
119
}
120
return result
121
}
···
31
Value: "http://localhost:5444",
32
},
33
&cli.StringFlag{
34
Name: "git-dir",
35
Usage: "base directory for git repos",
36
Value: "/home/git",
···
45
}
46
47
func Run(ctx context.Context, cmd *cli.Command) error {
48
+
l := log.FromContext(ctx)
49
+
50
internalApi := cmd.String("internal-api")
51
gitDir := cmd.String("git-dir")
52
logPath := cmd.String("log-path")
53
output := cmd.String("output")
54
55
+
executablePath, err := os.Executable()
56
+
if err != nil {
57
+
l.Error("error getting path of executable", "error", err)
58
+
return err
59
+
}
60
61
resp, err := http.Get(internalApi + "/keys")
62
if err != nil {
···
91
return err
92
}
93
case "authorized-keys":
94
+
formatted := formatKeyData(executablePath, gitDir, logPath, internalApi, data)
95
_, err := os.Stdout.Write([]byte(formatted))
96
if err != nil {
97
l.Error("error writing to stdout", "error", err)
···
110
return nil
111
}
112
113
+
func formatKeyData(executablePath, gitDir, logPath, endpoint string, data []map[string]any) string {
114
var result string
115
for _, entry := range data {
116
result += fmt.Sprintf(
117
+
`command="%s guard -git-dir %s -user %s -log-path %s -internal-api %s",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty %s`+"\n",
118
+
executablePath, gitDir, entry["did"], logPath, endpoint, entry["key"])
119
}
120
return result
121
}