borg-gen-auth-keys/main.go

43 lines
719 B
Go

package main
import (
"os"
"io/ioutil"
"encoding/json"
"fmt"
)
type Host struct {
Name string
SSHKey string
}
type HostList struct {
Folder string
Hosts []Host
}
func main() {
inputFilePath := os.Args[1]
dat, err := ioutil.ReadFile(inputFilePath)
check(err)
var hosts HostList
err = json.Unmarshal(dat, &hosts)
check(err)
for i := 0; i < len(hosts.Hosts); i++ {
fmt.Print("command=\"borg serve --restrict-to-path ")
fmt.Print(hosts.Folder)
fmt.Print("/")
fmt.Print(hosts.Hosts[i].Name)
fmt.Print("\",no-pty,no-agent-forwarding,no-port-forwarding,no-X11-forwarding,no-user-rc ")
fmt.Print(hosts.Hosts[i].SSHKey)
fmt.Print("\n")
}
}
func check(e error) {
if e != nil {
panic(e)
}
}