borgocli/generate/authorized_keys/generate_authorized_keys.go

41 lines
724 B
Go
Raw Normal View History

2017-04-13 09:47:13 +00:00
package authorized_keys
import (
"encoding/json"
"fmt"
)
type Host struct {
Name string
SSHKey string
AppendOnly bool
}
type HostList struct {
Folder string
Hosts []Host
}
func Run(data []byte) {
var hosts HostList
err := json.Unmarshal(data, &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)
if (hosts.Hosts[i].AppendOnly) {
fmt.Print(" --append only")
}
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)
}
}