Skip to content

Commit

Permalink
improve examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mandelsoft committed Nov 3, 2023
1 parent 7158463 commit 50fe294
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions examples/lib/comparison-scenario/00-consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down
7 changes: 7 additions & 0 deletions examples/lib/comparison-scenario/07-getref.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
11 changes: 11 additions & 0 deletions examples/lib/comparison-scenario/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 50fe294

Please sign in to comment.