Add basic federation example (#26)

Add basic federation example
This commit is contained in:
Sebastian Tiedtke 2019-01-28 17:31:06 -06:00 committed by GitHub
parent 025e36bf10
commit 754670ad12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 481 additions and 0 deletions

View file

@ -0,0 +1,44 @@
package main
import (
"context"
"fmt"
"io/ioutil"
"os"
"time"
"github.com/smallstep/certificates/ca"
)
func main() {
if len(os.Args) != 2 {
fmt.Fprintf(os.Stderr, "Usage: %s <token>\n", os.Args[0])
os.Exit(1)
}
token := os.Args[1]
// make sure to cancel the renew goroutine
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
client, err := ca.BootstrapClient(ctx, token, ca.AddFederationToRootCAs())
if err != nil {
panic(err)
}
for {
resp, err := client.Get("https://127.0.0.1:8443")
if err != nil {
panic(err)
}
b, err := ioutil.ReadAll(resp.Body)
resp.Body.Close()
if err != nil {
panic(err)
}
fmt.Printf("Server responded: %s\n", b)
time.Sleep(5 * time.Second)
}
}