-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathexample.go
49 lines (38 loc) · 1.12 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
package main
import (
"fmt"
"io/ioutil"
"github.com/mandelsoft/goutils/errors"
"ocm.software/ocm/api/credentials"
"ocm.software/ocm/api/ocm"
ociid "ocm.software/ocm/api/tech/oci/identity"
"ocm.software/ocm/api/utils/runtime"
)
const CFGFILE = "examples/lib/config2/config.yaml"
func UsingConfigs() error {
data, err := ioutil.ReadFile(CFGFILE)
if err != nil {
return errors.Wrapf(err, "cannot read configuration file %s", CFGFILE)
}
octx := ocm.DefaultContext()
cctx := octx.ConfigContext()
_, err = cctx.ApplyData(data, runtime.DefaultYAMLEncoding, CFGFILE)
if err != nil {
return errors.Wrapf(err, "cannot apply config data")
}
cid := credentials.NewConsumerIdentity(ociid.CONSUMER_TYPE,
ociid.ID_HOSTNAME, "ghcr.io",
ociid.ID_PATHPREFIX, "mandelsoft",
)
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
}