2020-05-30 09:52:27 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
2020-06-03 06:17:30 +00:00
|
|
|
"strings"
|
2020-05-30 09:52:27 +00:00
|
|
|
|
2020-11-13 11:53:01 +00:00
|
|
|
"git.rootprojects.org/root/telebit/internal/mgmt/authstore"
|
2020-05-30 09:52:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2020-06-03 06:17:30 +00:00
|
|
|
connStr := "postgres://postgres:postgres@localhost:5432/postgres"
|
2021-10-12 17:36:19 +00:00
|
|
|
|
|
|
|
if !strings.Contains(connStr, "sslmode=") {
|
|
|
|
sep := "?"
|
|
|
|
if strings.Contains(connStr, sep) {
|
|
|
|
sep = "&"
|
|
|
|
}
|
|
|
|
if strings.Contains(connStr, "@localhost/") ||
|
|
|
|
strings.Contains(connStr, "@localhost:") {
|
|
|
|
connStr += sep + "sslmode=disable"
|
|
|
|
} else {
|
|
|
|
connStr += sep + "sslmode=required"
|
|
|
|
}
|
2020-06-03 06:17:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
store, err := authstore.NewStore(connStr, initSQL)
|
2020-05-30 09:52:27 +00:00
|
|
|
if nil != err {
|
|
|
|
log.Fatal("connection error", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
num := "8"
|
|
|
|
slug := num + "-xxx-client"
|
|
|
|
pubkey := num + "-somehash"
|
|
|
|
auth1 := &authstore.Authorization{
|
|
|
|
Slug: slug,
|
|
|
|
SharedKey: "3-xxxx-zzzz-yyyy",
|
|
|
|
PublicKey: pubkey,
|
|
|
|
}
|
|
|
|
err = store.Add(auth1)
|
|
|
|
if nil != err {
|
|
|
|
log.Fatal("add error", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
auth, err := store.Get(slug)
|
|
|
|
if nil != err {
|
|
|
|
log.Fatal("get by slug error", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
auth, err = store.Get(pubkey)
|
|
|
|
if nil != err {
|
|
|
|
log.Fatal("get by pub error", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
auth1.MachinePPID = "a-secretish-id"
|
|
|
|
err = store.Set(auth1)
|
|
|
|
if nil != err {
|
|
|
|
log.Fatal("set machine id", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
err = store.Delete(auth1)
|
|
|
|
if nil != err {
|
|
|
|
log.Fatal("set machine id", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
store.Close()
|
|
|
|
|
|
|
|
fmt.Printf("%#v\n", auth)
|
|
|
|
}
|