1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
package workloadapi_test
import (
"context"
"github.com/spiffe/go-spiffe/v2/spiffeid"
"github.com/spiffe/go-spiffe/v2/svid/jwtsvid"
"github.com/spiffe/go-spiffe/v2/workloadapi"
)
func ExampleFetchX509SVID() {
svid, err := workloadapi.FetchX509SVID(context.TODO())
if err != nil {
// TODO: error handling
}
// TODO: use the X509-SVID
svid = svid
}
func ExampleFetchJWTSVID() {
serverID, err := spiffeid.FromString("spiffe://example.org/server")
if err != nil {
// TODO: error handling
}
svid, err := workloadapi.FetchJWTSVID(context.TODO(), jwtsvid.Params{
Audience: serverID.String(),
})
if err != nil {
// TODO: error handling
}
// TODO: use the JWT-SVID
svid = svid
}
func ExampleValidateJWTSVID() {
serverID, err := spiffeid.FromString("spiffe://example.org/server")
if err != nil {
// TODO: error handling
}
token := "TODO"
svid, err := workloadapi.ValidateJWTSVID(context.TODO(), token, serverID.String())
if err != nil {
// TODO: error handling
}
// TODO: use the JWT-SVID
svid = svid
}
|