woodpecker/pipeline/backend/backend.go
qwerty287 f582ad3159
Various enhancements in configuration (#1645)
- backends: move to cli flags instead of os.Getenv
- ssh: support 2fa with key and password
- allow to set grpc jwt secret (solves todo)
- allow to set default and max timeout (solves todo)

Closes https://github.com/woodpecker-ci/woodpecker/issues/896
Closes https://github.com/woodpecker-ci/woodpecker/issues/1131
2023-03-19 20:24:43 +01:00

50 lines
1.1 KiB
Go

package backend
import (
"context"
"fmt"
"github.com/woodpecker-ci/woodpecker/pipeline/backend/docker"
"github.com/woodpecker-ci/woodpecker/pipeline/backend/kubernetes"
"github.com/woodpecker-ci/woodpecker/pipeline/backend/local"
"github.com/woodpecker-ci/woodpecker/pipeline/backend/ssh"
"github.com/woodpecker-ci/woodpecker/pipeline/backend/types"
)
var (
enginesByName map[string]types.Engine
engines []types.Engine
)
func Init(ctx context.Context) {
engines = []types.Engine{
docker.New(),
local.New(),
ssh.New(),
kubernetes.New(ctx),
}
enginesByName = make(map[string]types.Engine)
for _, engine := range engines {
enginesByName[engine.Name()] = engine
}
}
func FindEngine(ctx context.Context, engineName string) (types.Engine, error) {
if engineName == "auto-detect" {
for _, engine := range engines {
if engine.IsAvailable(ctx) {
return engine, nil
}
}
return nil, fmt.Errorf("can't detect an available backend engine")
}
engine, ok := enginesByName[engineName]
if !ok {
return nil, fmt.Errorf("backend engine '%s' not found", engineName)
}
return engine, nil
}