Generate a random key ID on registration
This commit is contained in:
parent
949d1fc2ad
commit
09417b5147
5 changed files with 47 additions and 10 deletions
31
main.go
31
main.go
|
@ -21,6 +21,8 @@ import (
|
|||
func main() {
|
||||
useClient := flag.Bool("c", false, "Run client")
|
||||
|
||||
keyId := flag.String("id", "", "The key id to pass")
|
||||
|
||||
register := flag.Bool("r", false, "Register a key")
|
||||
|
||||
user := flag.String("user", "", "Username to register")
|
||||
|
@ -32,12 +34,12 @@ func main() {
|
|||
flag.Parse()
|
||||
|
||||
if *useClient {
|
||||
if *keyPath == "" || *user == "" {
|
||||
if *keyPath == "" || *keyId == "" {
|
||||
flag.PrintDefaults()
|
||||
return
|
||||
}
|
||||
|
||||
runClient(*keyPath, *user, *simulateCaddy)
|
||||
runClient(*keyPath, *keyId, *simulateCaddy)
|
||||
} else if *register {
|
||||
if *keyPath == "" || *user == "" {
|
||||
flag.PrintDefaults()
|
||||
|
@ -50,7 +52,7 @@ func main() {
|
|||
}
|
||||
}
|
||||
|
||||
func runClient(keyFile string, user string, simulateCaddy bool) {
|
||||
func runClient(keyFile string, keyId string, simulateCaddy bool) {
|
||||
testData := map[string]string{"hello": "world"}
|
||||
json_data, _ := json.Marshal(testData)
|
||||
|
||||
|
@ -60,7 +62,7 @@ func runClient(keyFile string, user string, simulateCaddy bool) {
|
|||
log.Fatal(err)
|
||||
}
|
||||
|
||||
client, err := client.GetSigningClient(key, user)
|
||||
client, err := client.GetSigningClient(key, keyId)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
@ -135,5 +137,24 @@ func registerKey(keyFile string, userId string) {
|
|||
|
||||
json_data, _ := json.Marshal(request)
|
||||
|
||||
http.DefaultClient.Post("http://localhost:8080/register", "application/json", bytes.NewBuffer(json_data))
|
||||
resp, err := http.DefaultClient.Post(
|
||||
"http://localhost:8080/register",
|
||||
"application/json",
|
||||
bytes.NewBuffer(json_data))
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
out, err := io.ReadAll(resp.Body)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
fmt.Println(resp.StatusCode)
|
||||
fmt.Println(resp.Header)
|
||||
fmt.Println(string(out[:]))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue