Skip to content

Commit

Permalink
docs: add one more example
Browse files Browse the repository at this point in the history
Signed-off-by: Shiwei Zhang <[email protected]>
  • Loading branch information
shizhMSFT committed Feb 5, 2025
1 parent 4d4c80e commit 50e7772
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ package ratify_test

import (
"context"
"crypto/tls"
"net/http"
"testing/fstest"

"github.com/ratify-project/ratify-go"
Expand Down Expand Up @@ -84,3 +86,70 @@ func ExampleStoreMux() {
}
// Output:
}

// ExampleStoreMux_mixRegistryStore demonstrates how to access different
// registries with different network configurations using a single store by
// multiplexing.
func ExampleStoreMux_mixRegistryStore() {
// Create a new store multiplexer
mux := ratify.NewStoreMux("multiplexer")

// Create a global registry store with default options.
// Developers should replace the default options with actual configuration.
store, err := ratify.NewRegistryStore("registry", ratify.RegistryStoreOptions{})
if err != nil {
panic(err)
}
if err := mux.RegisterFallback(store); err != nil {
panic(err)
}

// Create a registry store for local registry.
// A local registry is accessed over plain HTTP unlike the global registry.
store, err = ratify.NewRegistryStore("local", ratify.RegistryStoreOptions{
PlainHTTP: true,
})
if err != nil {
panic(err)
}
if err := mux.Register("localhost:5000", store); err != nil {
panic(err)
}

// Create a registry store with client certificate authentication.
store, err = ratify.NewRegistryStore("cert", ratify.RegistryStoreOptions{
HTTPClient: &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
Certificates: []tls.Certificate{
// add client certificate with private key
},
},
},
},
})
if err != nil {
panic(err)
}
if err := mux.Register("private.registry.example", store); err != nil {
panic(err)
}

// Create a registry store for an insecure registry.
store, err = ratify.NewRegistryStore("insecure", ratify.RegistryStoreOptions{
HTTPClient: &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
},
},
})
if err != nil {
panic(err)
}
if err := mux.Register("insecure.registry.example", store); err != nil {
panic(err)
}
// Output:
}

0 comments on commit 50e7772

Please sign in to comment.