Move shell handlers to internal/shutils/handlers
ci/woodpecker/push/woodpecker Pipeline was successful Details

This commit is contained in:
Elara 2023-10-23 19:47:07 -07:00
parent ef923016e4
commit edad7b03b2
10 changed files with 35 additions and 35 deletions

View File

@ -33,7 +33,7 @@ import (
"github.com/mholt/archiver/v4"
"github.com/schollz/progressbar/v3"
"lure.sh/lure/internal/shutils"
"lure.sh/lure/internal/shutils/handlers"
)
// FileDownloader downloads files using HTTP
@ -125,7 +125,7 @@ func (FileDownloader) Download(opts Options) (Type, string, error) {
)
defer bar.Close()
} else {
bar = shutils.NopRWC{}
bar = handlers.NopRWC{}
}
h, err := opts.NewHash()

View File

@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package shutils
package handlers
import (
"context"

View File

@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package shutils_test
package handlers_test
import (
"context"

View File

@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package shutils
package handlers
import (
"context"

View File

@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package shutils_test
package handlers_test
import (
"bytes"

View File

@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package shutils
package handlers
import (
"context"

View File

@ -30,8 +30,8 @@ import (
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing/object"
"lure.sh/lure/internal/shutils"
"golang.org/x/exp/slices"
"lure.sh/lure/internal/shutils/handlers"
"mvdan.cc/sh/v3/interp"
)
@ -41,7 +41,7 @@ var (
)
// Helpers contains all the helper commands
var Helpers = shutils.ExecFuncs{
var Helpers = handlers.ExecFuncs{
"install-binary": installHelperCmd("/usr/bin", 0o755),
"install-systemd-user": installHelperCmd("/usr/lib/systemd/user", 0o644),
"install-systemd": installHelperCmd("/usr/lib/systemd/system", 0o644),
@ -57,14 +57,14 @@ var Helpers = shutils.ExecFuncs{
// Restricted contains restricted read-only helper commands
// that don't modify any state
var Restricted = shutils.ExecFuncs{
var Restricted = handlers.ExecFuncs{
"git-version": gitVersionCmd,
}
func installHelperCmd(prefix string, perms os.FileMode) shutils.ExecFunc {
func installHelperCmd(prefix string, perms os.FileMode) handlers.ExecFunc {
return func(hc interp.HandlerContext, cmd string, args []string) error {
if len(args) < 1 {
return shutils.InsufficientArgsError(cmd, 1, len(args))
return handlers.InsufficientArgsError(cmd, 1, len(args))
}
from := resolvePath(hc, args[0])
@ -85,7 +85,7 @@ func installHelperCmd(prefix string, perms os.FileMode) shutils.ExecFunc {
func installManualCmd(hc interp.HandlerContext, cmd string, args []string) error {
if len(args) < 1 {
return shutils.InsufficientArgsError(cmd, 1, len(args))
return handlers.InsufficientArgsError(cmd, 1, len(args))
}
from := resolvePath(hc, args[0])
@ -115,7 +115,7 @@ func installCompletionCmd(hc interp.HandlerContext, cmd string, args []string) e
}
if len(args) < 2 {
return shutils.InsufficientArgsError(cmd, 2, len(args))
return handlers.InsufficientArgsError(cmd, 2, len(args))
}
shell := args[0]

View File

@ -43,8 +43,8 @@ import (
"lure.sh/lure/internal/cpu"
"lure.sh/lure/internal/db"
"lure.sh/lure/internal/dl"
"lure.sh/lure/internal/shutils"
"lure.sh/lure/internal/shutils/decoder"
"lure.sh/lure/internal/shutils/handlers"
"lure.sh/lure/internal/shutils/helpers"
"lure.sh/lure/internal/types"
"lure.sh/lure/pkg/distro"
@ -229,10 +229,10 @@ func executeFirstPass(ctx context.Context, info *distro.OSRelease, fl *syntax.Fi
runner, err := interp.New(
interp.Env(expand.ListEnviron(env...)),
interp.StdIO(os.Stdin, os.Stdout, os.Stderr),
interp.ExecHandler(helpers.Restricted.ExecHandler(shutils.NopExec)),
interp.ReadDirHandler(shutils.RestrictedReadDir(scriptDir)),
interp.StatHandler(shutils.RestrictedStat(scriptDir)),
interp.OpenHandler(shutils.RestrictedOpen(scriptDir)),
interp.ExecHandler(helpers.Restricted.ExecHandler(handlers.NopExec)),
interp.ReadDirHandler(handlers.RestrictedReadDir(scriptDir)),
interp.StatHandler(handlers.RestrictedStat(scriptDir)),
interp.OpenHandler(handlers.RestrictedOpen(scriptDir)),
)
if err != nil {
return nil, err

View File

@ -23,7 +23,7 @@ import (
"os"
"strings"
"lure.sh/lure/internal/shutils"
"lure.sh/lure/internal/shutils/handlers"
"mvdan.cc/sh/v3/expand"
"mvdan.cc/sh/v3/interp"
"mvdan.cc/sh/v3/syntax"
@ -74,10 +74,10 @@ func ParseOSRelease(ctx context.Context) (*OSRelease, error) {
// as well as no environment variables in order to prevent vulnerabilities
// caused by changing the os-release file.
runner, err := interp.New(
interp.OpenHandler(shutils.NopOpen),
interp.ExecHandler(shutils.NopExec),
interp.ReadDirHandler(shutils.NopReadDir),
interp.StatHandler(shutils.NopStat),
interp.OpenHandler(handlers.NopOpen),
interp.ExecHandler(handlers.NopExec),
interp.ReadDirHandler(handlers.NopReadDir),
interp.StatHandler(handlers.NopStat),
interp.Env(expand.ListEnviron()),
)
if err != nil {

View File

@ -37,8 +37,8 @@ import (
"go.elara.ws/vercmp"
"lure.sh/lure/internal/config"
"lure.sh/lure/internal/db"
"lure.sh/lure/internal/shutils"
"lure.sh/lure/internal/shutils/decoder"
"lure.sh/lure/internal/shutils/handlers"
"lure.sh/lure/internal/types"
"lure.sh/lure/pkg/distro"
"lure.sh/lure/pkg/loggerctx"
@ -243,11 +243,11 @@ func processRepoChanges(ctx context.Context, repo types.Repo, r *git.Repository,
env := append(os.Environ(), "scriptdir="+filepath.Dir(filepath.Join(repoDir, action.File)))
runner, err := interp.New(
interp.Env(expand.ListEnviron(env...)),
interp.ExecHandler(shutils.NopExec),
interp.ReadDirHandler(shutils.RestrictedReadDir(repoDir)),
interp.StatHandler(shutils.RestrictedStat(repoDir)),
interp.OpenHandler(shutils.RestrictedOpen(repoDir)),
interp.StdIO(shutils.NopRWC{}, shutils.NopRWC{}, shutils.NopRWC{}),
interp.ExecHandler(handlers.NopExec),
interp.ReadDirHandler(handlers.RestrictedReadDir(repoDir)),
interp.StatHandler(handlers.RestrictedStat(repoDir)),
interp.OpenHandler(handlers.RestrictedOpen(repoDir)),
interp.StdIO(handlers.NopRWC{}, handlers.NopRWC{}, handlers.NopRWC{}),
)
if err != nil {
return err
@ -349,11 +349,11 @@ func processRepoFull(ctx context.Context, repo types.Repo, repoDir string) error
env := append(os.Environ(), "scriptdir="+filepath.Dir(match))
runner, err := interp.New(
interp.Env(expand.ListEnviron(env...)),
interp.ExecHandler(shutils.NopExec),
interp.ReadDirHandler(shutils.RestrictedReadDir(repoDir)),
interp.StatHandler(shutils.RestrictedStat(repoDir)),
interp.OpenHandler(shutils.RestrictedOpen(repoDir)),
interp.StdIO(shutils.NopRWC{}, shutils.NopRWC{}, shutils.NopRWC{}),
interp.ExecHandler(handlers.NopExec),
interp.ReadDirHandler(handlers.RestrictedReadDir(repoDir)),
interp.StatHandler(handlers.RestrictedStat(repoDir)),
interp.OpenHandler(handlers.RestrictedOpen(repoDir)),
interp.StdIO(handlers.NopRWC{}, handlers.NopRWC{}, handlers.NopRWC{}),
)
if err != nil {
return err