This commit is contained in:
jamesread 2021-10-16 07:38:47 +01:00
parent da2ea12f30
commit 03d7250cf6
4 changed files with 62 additions and 65 deletions

View File

@ -1,13 +1,13 @@
package acl
import (
"context"
config "github.com/jamesread/OliveTin/internal/config"
log "github.com/sirupsen/logrus"
"context"
)
type User struct {
Username string;
Username string
}
func IsAllowedExec(cfg *config.Config, user *User, action *config.ActionButton) bool {
@ -37,7 +37,7 @@ func IsAllowedExec(cfg *config.Config, user *User, action *config.ActionButton)
"CanExec": canExec,
}).Debug("isAllowedExec Final Result")
return canExec;
return canExec
}
func IsAllowedView(cfg *config.Config, user *User, action *config.ActionButton) bool {
@ -68,17 +68,15 @@ func IsAllowedView(cfg *config.Config, user *User, action *config.ActionButton)
"CanView": canView,
}).Debug("isAllowedView Final Result")
return canView;
return canView
}
func isUserInGroup(user *User, usergroup string) bool {
return true;
return true
}
func UserFromContext(ctx context.Context) *User {
return &User {
return &User{
Username: "Guest",
}
}

View File

@ -2,9 +2,9 @@ package executor
import (
pb "github.com/jamesread/OliveTin/gen/grpc"
acl "github.com/jamesread/OliveTin/internal/acl"
config "github.com/jamesread/OliveTin/internal/config"
log "github.com/sirupsen/logrus"
acl "github.com/jamesread/OliveTin/internal/acl"
"context"
"errors"
@ -34,21 +34,21 @@ func (e *Executor) ExecAction(cfg *config.Config, user *acl.User, actualAction *
res := execAction(cfg, actualAction)
e.Logs = append(e.Logs, *res);
e.Logs = append(e.Logs, *res)
return &pb.StartActionResponse{
LogEntry: &pb.LogEntry {
LogEntry: &pb.LogEntry{
ActionTitle: actualAction.Title,
TimedOut: res.TimedOut,
Stderr: res.Stderr,
Stdout: res.Stdout,
ExitCode: res.ExitCode,
},
};
}
}
func execAction(cfg *config.Config, actualAction *config.ActionButton) *InternalLogEntry {
res := &InternalLogEntry {
res := &InternalLogEntry{
Datetime: time.Now().Format("2006-01-02 15:04:05"),
TimedOut: false,
ActionTitle: actualAction.Title,

View File

@ -9,9 +9,9 @@ import (
"google.golang.org/grpc"
"net"
acl "github.com/jamesread/OliveTin/internal/acl"
config "github.com/jamesread/OliveTin/internal/config"
executor "github.com/jamesread/OliveTin/internal/executor"
acl "github.com/jamesread/OliveTin/internal/acl"
)
var (
@ -37,8 +37,7 @@ func (api *oliveTinAPI) StartAction(ctx ctx.Context, req *pb.StartActionRequest)
user := acl.UserFromContext(ctx)
if !acl.IsAllowedExec(cfg, user, actualAction) {
return &pb.StartActionResponse{
}, nil
return &pb.StartActionResponse{}, nil
}
@ -75,7 +74,7 @@ func (api *oliveTinAPI) GetButtons(ctx ctx.Context, req *pb.GetButtonsRequest) (
}
func (api *oliveTinAPI) GetLogs(ctx ctx.Context, req *pb.GetLogsRequest) (*pb.GetLogsResponse, error) {
ret := &pb.GetLogsResponse{};
ret := &pb.GetLogsResponse{}
// TODO Limit to 10 entries or something to prevent browser lag.