-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresolver.go
More file actions
42 lines (34 loc) · 1.1 KB
/
resolver.go
File metadata and controls
42 lines (34 loc) · 1.1 KB
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
package plugin
import (
"fmt"
"strings"
"github.com/GoCodeAlone/workflow/config"
)
// MissingCapabilitiesError is returned when a workflow config requires capabilities
// that no loaded plugin provides.
type MissingCapabilitiesError struct {
Missing []string
}
func (e *MissingCapabilitiesError) Error() string {
return fmt.Sprintf("missing required capabilities: %s", strings.Join(e.Missing, ", "))
}
// ResolveWorkflowDependencies checks that all capabilities required by a
// workflow config are satisfied by loaded plugins. If cfg.Requires is nil,
// returns nil (auto-detection will be added later). For each required
// capability, checks capabilityReg.HasProvider(). Returns
// MissingCapabilitiesError if any are missing.
func (m *EnginePluginManager) ResolveWorkflowDependencies(cfg *config.WorkflowConfig) error {
if cfg.Requires == nil {
return nil
}
var missing []string
for _, cap := range cfg.Requires.Capabilities {
if !m.capabilityReg.HasProvider(cap) {
missing = append(missing, cap)
}
}
if len(missing) > 0 {
return &MissingCapabilitiesError{Missing: missing}
}
return nil
}