2020-04-20 16:36:34 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/containous/traefik/v2/pkg/config/static"
|
|
|
|
"github.com/containous/traefik/v2/pkg/plugins"
|
|
|
|
)
|
|
|
|
|
|
|
|
const outputDir = "./plugins-storage/"
|
|
|
|
|
|
|
|
func initPlugins(staticCfg *static.Configuration) (*plugins.Client, map[string]plugins.Descriptor, *plugins.DevPlugin, error) {
|
|
|
|
if !isPilotEnabled(staticCfg) || !hasPlugins(staticCfg) {
|
|
|
|
return nil, map[string]plugins.Descriptor{}, nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
opts := plugins.ClientOptions{
|
|
|
|
Output: outputDir,
|
2020-09-15 10:08:03 +00:00
|
|
|
Token: staticCfg.Pilot.Token,
|
2020-04-20 16:36:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
client, err := plugins.NewClient(opts)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = plugins.Setup(client, staticCfg.Experimental.Plugins, staticCfg.Experimental.DevPlugin)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return client, staticCfg.Experimental.Plugins, staticCfg.Experimental.DevPlugin, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func isPilotEnabled(staticCfg *static.Configuration) bool {
|
2020-09-15 10:08:03 +00:00
|
|
|
return staticCfg.Pilot != nil && staticCfg.Pilot.Token != ""
|
2020-04-20 16:36:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func hasPlugins(staticCfg *static.Configuration) bool {
|
|
|
|
return staticCfg.Experimental != nil &&
|
|
|
|
len(staticCfg.Experimental.Plugins) > 0 || staticCfg.Experimental.DevPlugin != nil
|
|
|
|
}
|