-
Notifications
You must be signed in to change notification settings - Fork 27
/
step.go
35 lines (29 loc) · 894 Bytes
/
step.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
package go2chef
/*
Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
*/
// Step defines the interface for go2chef execution steps
type Step interface {
Component
Download() error
Execute() error
}
// StepLoader defines the function call interface for step loaders
type StepLoader func(map[string]interface{}) (Step, error)
var (
stepRegistry = make(map[string]StepLoader)
)
// RegisterStep registers a new step plugin with go2chef
func RegisterStep(name string, s StepLoader) {
if _, ok := stepRegistry[name]; ok {
panic("step plugin " + name + " is already registered")
}
stepRegistry[name] = s
}
// GetStep gets a new step given a type and configuration
func GetStep(stepType string, config map[string]interface{}) (Step, error) {
if s, ok := stepRegistry[stepType]; ok {
return s(config)
}
return nil, &ErrComponentDoesNotExist{Component: stepType}
}