Added authorized_keys generation
This commit is contained in:
parent
10a2672953
commit
ebde757e5b
14
generate/authorized_keys/example.json
Normal file
14
generate/authorized_keys/example.json
Normal 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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
41
generate/authorized_keys/generate_authorized_keys.go
Normal file
41
generate/authorized_keys/generate_authorized_keys.go
Normal 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
30
main.go
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue