diff --git a/examples/lib/comparison-scenario/00-consumer.go b/examples/lib/comparison-scenario/00-consumer.go index f154184eef..5a54fb965a 100644 --- a/examples/lib/comparison-scenario/00-consumer.go +++ b/examples/lib/comparison-scenario/00-consumer.go @@ -34,6 +34,7 @@ func TransportTo(target ocm.Repository, src string) error { return errors.Wrapf(err, "cannot get repository access for %s", src) } defer repo.Close() + PrintConsumerId(repo, "source repository") // lookup component version to be transported cv, err := repo.LookupComponentVersion(COMPONENT_NAME, COMPONENT_VERSION) @@ -69,6 +70,7 @@ func Consumer(cfg *helper.Config) error { return errors.Wrapf(err, "cannot open local repository") } defer repo.Close() + PrintConsumerId(repo, "local repository") //////////////////////////////////////////////////////////////////////////// fmt.Printf("*** transfer compoment version\n") diff --git a/examples/lib/comparison-scenario/07-getref.go b/examples/lib/comparison-scenario/07-getref.go index 9f3e8c78ef..e12968671c 100644 --- a/examples/lib/comparison-scenario/07-getref.go +++ b/examples/lib/comparison-scenario/07-getref.go @@ -69,5 +69,12 @@ func GetOCIReference(ctx ocm.Context, cfg *helper.Config) error { } else { fmt.Printf("no OCI reference found\n") } + + meth, err := res.AccessMethod() + if err != nil { + return err + } + defer meth.Close() + PrintConsumerId(meth, "OCI image") return nil } diff --git a/examples/lib/comparison-scenario/utils.go b/examples/lib/comparison-scenario/utils.go index d0b10b26fc..bf8a6cb09f 100644 --- a/examples/lib/comparison-scenario/utils.go +++ b/examples/lib/comparison-scenario/utils.go @@ -10,6 +10,7 @@ import ( "io" "os" + "github.com/open-component-model/ocm/pkg/contexts/credentials" "github.com/open-component-model/ocm/pkg/contexts/ocm" "github.com/open-component-model/ocm/pkg/contexts/ocm/attrs/signingattr" "github.com/open-component-model/ocm/pkg/signing/handlers/rsa" @@ -49,6 +50,16 @@ func PrintSignatures(cv ocm.ComponentVersionAccess) { } } +func PrintConsumerId(o interface{}, msg string) { + // register credentials for given OCI registry in context. + id := credentials.GetProvidedConsumerId(o) + if id == nil { + fmt.Printf("no consumer id for %s\n", msg) + } else { + fmt.Printf("consumer id for %s: %s\n", msg, id) + } +} + func InstallChart(chart *chart.Chart, release, namespace string) error { settings := cli.New() settings.SetNamespace(namespace)