4
0

main.go 744 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package main
  2. import (
  3. "context"
  4. "fmt"
  5. "io/ioutil"
  6. "os"
  7. "time"
  8. "github.com/smallstep/certificates/ca"
  9. )
  10. func main() {
  11. if len(os.Args) != 2 {
  12. fmt.Fprintf(os.Stderr, "Usage: %s <token>\n", os.Args[0])
  13. os.Exit(1)
  14. }
  15. token := os.Args[1]
  16. // make sure to cancel the renew goroutine
  17. ctx, cancel := context.WithCancel(context.Background())
  18. defer cancel()
  19. client, err := ca.BootstrapClient(ctx, token, ca.AddFederationToRootCAs())
  20. if err != nil {
  21. panic(err)
  22. }
  23. for {
  24. resp, err := client.Get("https://127.0.0.1:8443")
  25. if err != nil {
  26. panic(err)
  27. }
  28. b, err := ioutil.ReadAll(resp.Body)
  29. resp.Body.Close()
  30. if err != nil {
  31. panic(err)
  32. }
  33. fmt.Printf("Server responded: %s\n", b)
  34. time.Sleep(5 * time.Second)
  35. }
  36. }