/
module_proxy.go
116 lines (93 loc) · 3.01 KB
/
module_proxy.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package plugin
import (
"context"
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
"github.com/vmware/octant/internal/module"
"github.com/vmware/octant/internal/octant"
"github.com/vmware/octant/pkg/navigation"
"github.com/vmware/octant/pkg/view/component"
)
// ModuleProxy is a proxy that satisfies Octant module requirements. It allows plugins to behave as if they
// are internal modules.
type ModuleProxy struct {
Metadata *Metadata
PluginName string
Service ModuleService
}
var _ module.Module = (*ModuleProxy)(nil)
// NewModuleProxy creates a ModuleProxy instance.
func NewModuleProxy(pluginName string, metadata *Metadata, service ModuleService) (*ModuleProxy, error) {
if metadata == nil {
return nil, errors.New("metadata is nil")
}
return &ModuleProxy{
PluginName: pluginName,
Metadata: metadata,
Service: service,
}, nil
}
// Name returns the module's name. It is the same as the plugin's metadata name.
func (m *ModuleProxy) Name() string {
return m.Metadata.Name
}
func (m *ModuleProxy) ClientRequestHandlers() []octant.ClientRequestHandler {
return nil
}
// Content returns content from the plugin. Plugins are expected to handle paths appropriately.
func (m *ModuleProxy) Content(ctx context.Context, contentPath string, opts module.ContentOptions) (component.ContentResponse, error) {
return m.Service.Content(ctx, contentPath)
}
func (m *ModuleProxy) ContentPath() string {
return m.Name()
}
// Navigation returns navigation from the plugin.
func (m *ModuleProxy) Navigation(ctx context.Context, namespace, root string) ([]navigation.Navigation, error) {
topLevel, err := m.Service.Navigation(ctx)
if err != nil {
return nil, err
}
return []navigation.Navigation{topLevel}, nil
}
// SetNamespace is a no-op
func (ModuleProxy) SetNamespace(namespace string) error {
return nil
}
// Start is a no-op
func (ModuleProxy) Start() error {
return nil
}
// Stop is a no-op
func (ModuleProxy) Stop() {
}
// SetContext is a no-op
func (ModuleProxy) SetContext(ctx context.Context, contextName string) error {
return nil
}
// Generators is a no-op
func (ModuleProxy) Generators() []octant.Generator {
return []octant.Generator{}
}
// SupportedGroupVersionKind is currently a no-op. In the future this will allow plugins
// to handle paths for GVKs.
func (ModuleProxy) SupportedGroupVersionKind() []schema.GroupVersionKind {
return []schema.GroupVersionKind{}
}
// GroupVersionKindPath is currently a no-op. In the future this will allow plugins
// to handle paths for GVKs.
func (ModuleProxy) GroupVersionKindPath(namespace, apiVersion, kind, name string) (string, error) {
return "", nil
}
// AddCRD is a no-op
func (ModuleProxy) AddCRD(ctx context.Context, crd *unstructured.Unstructured) error {
return nil
}
// RemoveCRD is a no-op
func (ModuleProxy) RemoveCRD(ctx context.Context, crd *unstructured.Unstructured) error {
return nil
}
// ResetCRDs is a no-op
func (ModuleProxy) ResetCRDs(ctx context.Context) error {
return nil
}