-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathexample.go
56 lines (45 loc) · 1.31 KB
/
example.go
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
53
54
55
56
package main
import (
"fmt"
"github.com/mandelsoft/goutils/errors"
"ocm.software/ocm/api/credentials"
ccfg "ocm.software/ocm/api/credentials/config"
"ocm.software/ocm/api/credentials/extensions/repositories/directcreds"
"ocm.software/ocm/api/ocm"
ociid "ocm.software/ocm/api/tech/oci/identity"
"ocm.software/ocm/examples/lib/helper"
)
func UsingConfigs() error {
cfg, err := helper.ReadConfig(CFG)
if err != nil {
return err
}
cid := credentials.NewConsumerIdentity(ociid.CONSUMER_TYPE,
ociid.ID_HOSTNAME, "ghcr.io",
ociid.ID_PATHPREFIX, "mandelsoft",
)
octx := ocm.DefaultContext()
cctx := octx.ConfigContext()
// create a credential configuration object
// and configure it to provide some direct consumer credentials.
creds := ccfg.New()
creds.AddConsumer(
cid,
directcreds.NewRepositorySpec(cfg.GetCredentials().Properties()),
)
err = cctx.ApplyConfig(creds, "explicit")
if err != nil {
return errors.Wrapf(err, "cannot apply config")
}
credctx := octx.CredentialsContext()
found, err := credctx.GetCredentialsForConsumer(cid, ociid.IdentityMatcher)
if err != nil {
return errors.Wrapf(err, "cannot extract credentials")
}
got, err := found.Credentials(credctx)
if err != nil {
return errors.Wrapf(err, "cannot evaluate credentials")
}
fmt.Printf("found: %s\n", got)
return nil
}