Progress on plugin loading
This commit is contained in:
parent
df7f3bdadc
commit
c2ccaff8ab
@ -41,6 +41,9 @@ func main () {
|
|||||||
flagDirectories := cli.NewFlag (
|
flagDirectories := cli.NewFlag (
|
||||||
'd', "directories",
|
'd', "directories",
|
||||||
"Serve the contents of directories.")
|
"Serve the contents of directories.")
|
||||||
|
flagUnsafePlugins := cli.NewFlag (
|
||||||
|
0, "unsafe-plugins",
|
||||||
|
"Load plugins not owned by the root user.")
|
||||||
cmd := cli.New (
|
cmd := cli.New (
|
||||||
"Run an HTTP server that automaticaly executes STEP files.",
|
"Run an HTTP server that automaticaly executes STEP files.",
|
||||||
flagPidFile,
|
flagPidFile,
|
||||||
@ -48,10 +51,24 @@ func main () {
|
|||||||
flagHTTPErrorDocument,
|
flagHTTPErrorDocument,
|
||||||
flagHTTPDirectoryDocument,
|
flagHTTPDirectoryDocument,
|
||||||
flagDirectories,
|
flagDirectories,
|
||||||
|
flagUnsafePlugins,
|
||||||
cli.NewHelp())
|
cli.NewHelp())
|
||||||
cmd.Syntax = "[OPTIONS]... [DIRECTORY]"
|
cmd.Syntax = "[OPTIONS]... [DIRECTORY]"
|
||||||
cmd.ParseOrExit(os.Args)
|
cmd.ParseOrExit(os.Args)
|
||||||
|
|
||||||
|
// get env variables
|
||||||
|
pluginPath := filepath.SplitList(os.Getenv("STEP_PLUGIN_PATH"))
|
||||||
|
if len(pluginPath) == 0 {
|
||||||
|
pluginPath = []string {
|
||||||
|
"/usr/lib/step/plugins",
|
||||||
|
"/usr/local/lib/step/plugins",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for index, pat := range pluginPath {
|
||||||
|
pluginPath[index], _ = filepath.Abs(pat)
|
||||||
|
}
|
||||||
|
|
||||||
|
// log header for telling apart separate program runs
|
||||||
log.Println(`==========| STEP |===========`)
|
log.Println(`==========| STEP |===========`)
|
||||||
log.Println(`Scriptable Template Processor`)
|
log.Println(`Scriptable Template Processor`)
|
||||||
log.Println(`... initializing`)
|
log.Println(`... initializing`)
|
||||||
@ -115,21 +132,21 @@ func main () {
|
|||||||
err := environment.Init(context.Background())
|
err := environment.Init(context.Background())
|
||||||
if err != nil { log.Fatal(err) }
|
if err != nil { log.Fatal(err) }
|
||||||
|
|
||||||
// TODO: load plugins
|
// load plugins
|
||||||
pluginPath := os.Getenv("STEP_PLUGIN_PATH")
|
for _, pat := range pluginPath {
|
||||||
if pluginPath == "" {
|
|
||||||
pluginPath = "/usr/lib/step/plugins:/usr/local/lib/step/plugins"
|
|
||||||
}
|
|
||||||
for _, pat := range filepath.SplitList(pluginPath) {
|
|
||||||
entries, err := os.ReadDir(pat)
|
entries, err := os.ReadDir(pat)
|
||||||
if err != nil { continue }
|
if err != nil { continue }
|
||||||
for _, entry := range entries {
|
for _, entry := range entries {
|
||||||
pluginPath := filepath.Join(pat, entry.Name())
|
pluginPath := filepath.Join(pat, entry.Name())
|
||||||
_, err := environment.LoadProviderPlugin(pat)
|
ext := filepath.Ext(pluginPath)
|
||||||
|
if ext != ".so" { continue }
|
||||||
|
if flagUnsafePlugins.Value == "true" {
|
||||||
|
_, err = environment.LoadProviderPluginUnsafe(pluginPath)
|
||||||
|
} else {
|
||||||
|
_, err = environment.LoadProviderPlugin(pluginPath)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf (
|
log.Println("!!!", err)
|
||||||
"!!! could not load plugin %s: %v",
|
|
||||||
pluginPath, err)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -197,6 +214,18 @@ func (this *httpServerRoutine) Run (ctx context.Context) error {
|
|||||||
func logProviders (providers []step.Provider) {
|
func logProviders (providers []step.Provider) {
|
||||||
output := "providers: "
|
output := "providers: "
|
||||||
x := utf8.RuneCountInString(output)
|
x := utf8.RuneCountInString(output)
|
||||||
|
first := true
|
||||||
|
line := func () {
|
||||||
|
if output == "" { return }
|
||||||
|
if first {
|
||||||
|
first = false
|
||||||
|
log.Println("(i)", output)
|
||||||
|
} else {
|
||||||
|
log.Println(" ", output)
|
||||||
|
}
|
||||||
|
output = ""
|
||||||
|
x = 0
|
||||||
|
}
|
||||||
for index, provider := range providers {
|
for index, provider := range providers {
|
||||||
packag := provider.Package()
|
packag := provider.Package()
|
||||||
if index != len(providers) - 1 {
|
if index != len(providers) - 1 {
|
||||||
@ -204,16 +233,11 @@ func logProviders (providers []step.Provider) {
|
|||||||
x += 2
|
x += 2
|
||||||
}
|
}
|
||||||
packageLen := utf8.RuneCountInString(packag)
|
packageLen := utf8.RuneCountInString(packag)
|
||||||
if x + packageLen >= 60 && output != "" {
|
if x + packageLen >= 60 {
|
||||||
log.Println("(i)", output)
|
line()
|
||||||
output = ""
|
|
||||||
x = 2
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
output += packag
|
output += packag
|
||||||
x += packageLen
|
x += packageLen
|
||||||
}
|
}
|
||||||
if output != "" {
|
line()
|
||||||
log.Println("(i)", output)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -129,7 +129,7 @@ func (this *Environment) LoadProviderPluginUnsafe (name string) (Provider, error
|
|||||||
func (this *Environment) loadProviderPlugin (name string, checkRoot bool) (Provider, error) {
|
func (this *Environment) loadProviderPlugin (name string, checkRoot bool) (Provider, error) {
|
||||||
plugin, err := this.loadPlugin(name, checkRoot)
|
plugin, err := this.loadPlugin(name, checkRoot)
|
||||||
if err != nil { return nil, err }
|
if err != nil { return nil, err }
|
||||||
providerSymbol, err := plugin.Lookup("Provider")
|
providerSymbol, err := plugin.Lookup("NewProvider")
|
||||||
if err != nil { return nil, err }
|
if err != nil { return nil, err }
|
||||||
providerFactory, ok := providerSymbol.(func () Provider)
|
providerFactory, ok := providerSymbol.(func () Provider)
|
||||||
if !ok { return nil, ErrPluginBadSymbol }
|
if !ok { return nil, ErrPluginBadSymbol }
|
||||||
|
Loading…
Reference in New Issue
Block a user