Added authorized_keys generation

This commit is contained in:
Jan Christian Grünhage 2017-04-13 11:47:13 +02:00
parent 10a2672953
commit ebde757e5b
Signed by: jcgruenhage
GPG key ID: 321A67D9EE8BC3E1
3 changed files with 85 additions and 0 deletions

View file

@ -0,0 +1,14 @@
{
"Folder": "/mnt/backupmount",
"Hosts":[
{
"Name": "host1",
"SSHKey": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQC7ZvLoWZgh5eMDQXLEdWobkt/B8mnM2osEynF0boorifRNwztQHY3bKXTHjUlMnnWH+UvZ3aXH16M1QmyuNi4kLUTSMu4GSVsXMfknHRjgJ927Y/j5TCGXfOcfB0B4pcgHS3fVi1VMXXiZ1S/X8cbt1llXHfEC5eKutDeJkRer3w== SSH_KEY"
},
{
"Name": "host2",
"AppendOnly": true,
"SSHKey": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDIgm31x6ETn4HwxBthe3m14s1Bp9p8sT5kC/XSijN6uPpUmuF2ciRGc5QLzsBJR6MAD45zg6Q9nLBZGBnSIZDNfSGA5sqAeoZVHm4vjQWxenqG7dlNFXlC1DIHzMxxDsDUPneyXGBemAvVwL9h4HEC4xhMQIAJfaZqSWuNzzqYWw== SSH_KEY"
}
]
}

View file

@ -0,0 +1,41 @@
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)
}
}

30
main.go Normal file
View file

@ -0,0 +1,30 @@
package main
import (
"os"
"git.jcg.re/jcgruenhage/borgocli/generate/authorized_keys"
"io/ioutil"
)
func main() {
switch os.Args[1] {
case "generate":
switch os.Args[2] {
case "authorized_keys":
authorized_keys.Run(readFile(os.Args[3]))
}
}
}
func readFile(path string) []byte {
data, err := ioutil.ReadFile(path)
check(err)
return data
}
func check(e error) {
if e != nil {
panic(e)
}
}