mirror of
https://github.com/ncarlier/webhookd.git
synced 2025-04-07 21:47:09 +00:00
23 lines
469 B
Go
23 lines
469 B
Go
package tools
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"path"
|
|
"strings"
|
|
)
|
|
|
|
// ResolveScript is resolving the target script.
|
|
func ResolveScript(dir, name string) (string, error) {
|
|
script := path.Clean(path.Join(dir, fmt.Sprintf("%s.sh", name)))
|
|
if !strings.HasPrefix(script, dir) {
|
|
return "", errors.New("Invalid script path: " + name)
|
|
}
|
|
if _, err := os.Stat(script); os.IsNotExist(err) {
|
|
return "", errors.New("Script not found: " + script)
|
|
}
|
|
|
|
return script, nil
|
|
}
|