-
Notifications
You must be signed in to change notification settings - Fork 248
/
interpreter.go
54 lines (44 loc) · 1.23 KB
/
interpreter.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
package bundle
import (
"fmt"
"path"
"sort"
"github.com/operator-framework/operator-registry/pkg/registry"
)
type bundleDirInterpreter struct {
bundleCsvName string
pkg *registry.Package
}
func NewBundleDirInterperter(bundleDir string) (*bundleDirInterpreter, error) {
csv, err := registry.ReadCSVFromBundleDirectory(bundleDir)
if err != nil {
return nil, fmt.Errorf("error loading CSV from bundle directory, %v", err)
}
pkgDir, err := registry.NewPackageGraphLoaderFromDir(path.Join(bundleDir, ".."))
if err != nil {
return nil, fmt.Errorf("error loading package from directory, %v", err)
}
p, err := pkgDir.Generate()
if err != nil {
return nil, err
}
return &bundleDirInterpreter{bundleCsvName: csv.GetName(), pkg: p}, nil
}
func (b *bundleDirInterpreter) GetBundleChannels() (channelNames []string) {
for channelName, channel := range b.pkg.Channels {
for bundle, _ := range channel.Nodes {
if bundle.CsvName == b.bundleCsvName {
channelNames = append(channelNames, channelName)
break
}
}
}
sort.Strings(channelNames)
return
}
func (b *bundleDirInterpreter) GetDefaultChannel() string {
return b.pkg.DefaultChannel
}
func (b *bundleDirInterpreter) GetPackageName() string {
return b.pkg.Name
}