borgocli/generate/authorized_keys/generate_authorized_keys.go
2017-05-31 00:03:10 +02:00

43 lines
810 B
Go

package authorized_keys
import (
"fmt"
"gopkg.in/yaml.v2"
)
type Host struct {
Name string
SSHKey string
AppendOnly bool
}
type HostList struct {
Folder string
Hosts []Host
}
func Run(data []byte) {
var hosts HostList
err := yaml.Unmarshal(data, &hosts)
check(err)
for i := 0; i < len(hosts.Hosts); i++ {
fmt.Print("command=\"borg serve --restrict-to-path ")
fmt.Print(hosts.TotalPath(i))
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 (hostList *HostList) TotalPath(index int) string {
return hostList.Folder + "/" + hostList.Hosts[index].Name
}
func check(e error) {
if e != nil {
panic(e)
}
}