Initial commit - test client
This commit is contained in:
commit
c099930cf3
8 changed files with 137 additions and 0 deletions
56
main.go
Normal file
56
main.go
Normal file
|
@ -0,0 +1,56 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"crispbyte.dev/sig-auth/client"
|
||||
"golang.org/x/crypto/ssh"
|
||||
)
|
||||
|
||||
func main() {
|
||||
testData := map[string]string{"hello": "world"}
|
||||
json_data, _ := json.Marshal(testData)
|
||||
|
||||
keyFile := "testkey"
|
||||
|
||||
key, err := loadPrivateKey(keyFile)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
client, err := client.GetSigningClient(key, "test-id")
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
resp, err := client.Post("http://localhost:8080/post", "application/json", bytes.NewBuffer(json_data))
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
var res map[string]interface{}
|
||||
|
||||
json.NewDecoder(resp.Body).Decode(&res)
|
||||
|
||||
fmt.Println(res)
|
||||
}
|
||||
|
||||
func loadPrivateKey(keyFile string) (crypto.PrivateKey, error) {
|
||||
keyBytes, err := os.ReadFile(keyFile)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ssh.ParseRawPrivateKey(keyBytes)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue