-
Notifications
You must be signed in to change notification settings - Fork 197
/
drivers.go
36 lines (32 loc) · 1015 Bytes
/
drivers.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
package drivers
import (
"fmt"
"get.porter.sh/porter/pkg/portercontext"
"github.com/cnabio/cnab-go/driver"
"github.com/cnabio/cnab-go/driver/command"
"github.com/cnabio/cnab-go/driver/debug"
"github.com/cnabio/cnab-go/driver/docker"
"github.com/cnabio/cnab-go/driver/kubernetes"
)
// LookupDriver creates a driver by name.
//
// This replaces cnab-go's lookup function because cnab-go uses global process
// values, such as $PATH, instead of our context.
func LookupDriver(cxt *portercontext.Context, name string) (driver.Driver, error) {
switch name {
case "docker":
return &docker.Driver{}, nil
case "kubernetes", "k8s":
return &kubernetes.Driver{}, nil
case "debug":
return &debug.Driver{}, nil
default:
// Drivers must be named "cnab-NAME" and be on the PATH
if driverPath, ok := cxt.LookPath("cnab-" + name); ok {
d := &command.Driver{Name: name}
d.Path = driverPath
return d, nil
}
return nil, fmt.Errorf("unsupported driver or driver not found in PATH: %s", name)
}
}