go fmt
This commit is contained in:
parent
da2ea12f30
commit
03d7250cf6
|
|
@ -1,29 +1,29 @@
|
||||||
package acl
|
package acl
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
config "github.com/jamesread/OliveTin/internal/config"
|
config "github.com/jamesread/OliveTin/internal/config"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
Username string;
|
Username string
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsAllowedExec(cfg *config.Config, user *User, action *config.ActionButton) bool {
|
func IsAllowedExec(cfg *config.Config, user *User, action *config.ActionButton) bool {
|
||||||
canExec := cfg.DefaultPermissions.Exec
|
canExec := cfg.DefaultPermissions.Exec
|
||||||
|
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
"User": user.Username,
|
"User": user.Username,
|
||||||
"Action": action.Title,
|
"Action": action.Title,
|
||||||
"CanExec": canExec,
|
"CanExec": canExec,
|
||||||
}).Debug("isAllowedExec Permission Default")
|
}).Debug("isAllowedExec Permission Default")
|
||||||
|
|
||||||
for _, permissionEntry := range action.Permissions {
|
for _, permissionEntry := range action.Permissions {
|
||||||
if isUserInGroup(user, permissionEntry.Usergroup) {
|
if isUserInGroup(user, permissionEntry.Usergroup) {
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
"User": user.Username,
|
"User": user.Username,
|
||||||
"Action": action.Title,
|
"Action": action.Title,
|
||||||
"CanExec": permissionEntry.Exec,
|
"CanExec": permissionEntry.Exec,
|
||||||
}).Debug("isAllowedExec Permission Entry")
|
}).Debug("isAllowedExec Permission Entry")
|
||||||
|
|
||||||
|
|
@ -32,30 +32,30 @@ func IsAllowedExec(cfg *config.Config, user *User, action *config.ActionButton)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
"User": user.Username,
|
"User": user.Username,
|
||||||
"Action": action.Title,
|
"Action": action.Title,
|
||||||
"CanExec": canExec,
|
"CanExec": canExec,
|
||||||
}).Debug("isAllowedExec Final Result")
|
}).Debug("isAllowedExec Final Result")
|
||||||
|
|
||||||
return canExec;
|
return canExec
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsAllowedView(cfg *config.Config, user *User, action *config.ActionButton) bool {
|
func IsAllowedView(cfg *config.Config, user *User, action *config.ActionButton) bool {
|
||||||
canView := cfg.DefaultPermissions.View
|
canView := cfg.DefaultPermissions.View
|
||||||
|
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
"User": user.Username,
|
"User": user.Username,
|
||||||
"Action": action.Title,
|
"Action": action.Title,
|
||||||
"CanView": canView,
|
"CanView": canView,
|
||||||
}).Debug("isAllowedView Permission Default")
|
}).Debug("isAllowedView Permission Default")
|
||||||
|
|
||||||
for idx, permissionEntry := range action.Permissions {
|
for idx, permissionEntry := range action.Permissions {
|
||||||
if isUserInGroup(user, permissionEntry.Usergroup) {
|
if isUserInGroup(user, permissionEntry.Usergroup) {
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
"User": user.Username,
|
"User": user.Username,
|
||||||
"Action": action.Title,
|
"Action": action.Title,
|
||||||
"CanView": permissionEntry.View,
|
"CanView": permissionEntry.View,
|
||||||
"Index": idx,
|
"Index": idx,
|
||||||
}).Debug("isAllowedView Permission Entry")
|
}).Debug("isAllowedView Permission Entry")
|
||||||
|
|
||||||
canView = permissionEntry.View
|
canView = permissionEntry.View
|
||||||
|
|
@ -63,22 +63,20 @@ func IsAllowedView(cfg *config.Config, user *User, action *config.ActionButton)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
"User": user.Username,
|
"User": user.Username,
|
||||||
"Action": action.Title,
|
"Action": action.Title,
|
||||||
"CanView": canView,
|
"CanView": canView,
|
||||||
}).Debug("isAllowedView Final Result")
|
}).Debug("isAllowedView Final Result")
|
||||||
|
|
||||||
return canView;
|
return canView
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func isUserInGroup(user *User, usergroup string) bool {
|
func isUserInGroup(user *User, usergroup string) bool {
|
||||||
return true;
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func UserFromContext(ctx context.Context) *User {
|
func UserFromContext(ctx context.Context) *User {
|
||||||
return &User {
|
return &User{
|
||||||
Username: "Guest",
|
Username: "Guest",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,12 @@ import ()
|
||||||
|
|
||||||
// ActionButton represents a button that is shown in the webui.
|
// ActionButton represents a button that is shown in the webui.
|
||||||
type ActionButton struct {
|
type ActionButton struct {
|
||||||
ID string
|
ID string
|
||||||
Title string
|
Title string
|
||||||
Icon string
|
Icon string
|
||||||
Shell string
|
Shell string
|
||||||
CSS map[string]string `mapstructure:"omitempty"`
|
CSS map[string]string `mapstructure:"omitempty"`
|
||||||
Timeout int
|
Timeout int
|
||||||
Permissions []PermissionsEntry
|
Permissions []PermissionsEntry
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -24,8 +24,8 @@ type Entity struct {
|
||||||
|
|
||||||
type PermissionsEntry struct {
|
type PermissionsEntry struct {
|
||||||
Usergroup string
|
Usergroup string
|
||||||
View bool
|
View bool
|
||||||
Exec bool
|
Exec bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type DefaultPermissions struct {
|
type DefaultPermissions struct {
|
||||||
|
|
@ -34,7 +34,7 @@ type DefaultPermissions struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserGroup struct {
|
type UserGroup struct {
|
||||||
Name string
|
Name string
|
||||||
Members []string
|
Members []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -51,8 +51,8 @@ type Config struct {
|
||||||
ActionButtons []ActionButton `mapstructure:"actions"`
|
ActionButtons []ActionButton `mapstructure:"actions"`
|
||||||
Entities []Entity `mapstructure:"entities"`
|
Entities []Entity `mapstructure:"entities"`
|
||||||
CheckForUpdates bool
|
CheckForUpdates bool
|
||||||
Usergroups []UserGroup
|
Usergroups []UserGroup
|
||||||
DefaultPermissions DefaultPermissions
|
DefaultPermissions DefaultPermissions
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultConfig gets a new Config structure with sensible default values.
|
// DefaultConfig gets a new Config structure with sensible default values.
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,9 @@ package executor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
pb "github.com/jamesread/OliveTin/gen/grpc"
|
pb "github.com/jamesread/OliveTin/gen/grpc"
|
||||||
|
acl "github.com/jamesread/OliveTin/internal/acl"
|
||||||
config "github.com/jamesread/OliveTin/internal/config"
|
config "github.com/jamesread/OliveTin/internal/config"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
acl "github.com/jamesread/OliveTin/internal/acl"
|
|
||||||
|
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
|
@ -13,12 +13,12 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type InternalLogEntry struct {
|
type InternalLogEntry struct {
|
||||||
Datetime string
|
Datetime string
|
||||||
Content string
|
Content string
|
||||||
Stdout string
|
Stdout string
|
||||||
Stderr string
|
Stderr string
|
||||||
TimedOut bool
|
TimedOut bool
|
||||||
ExitCode int32
|
ExitCode int32
|
||||||
ActionTitle string
|
ActionTitle string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -34,23 +34,23 @@ func (e *Executor) ExecAction(cfg *config.Config, user *acl.User, actualAction *
|
||||||
|
|
||||||
res := execAction(cfg, actualAction)
|
res := execAction(cfg, actualAction)
|
||||||
|
|
||||||
e.Logs = append(e.Logs, *res);
|
e.Logs = append(e.Logs, *res)
|
||||||
|
|
||||||
return &pb.StartActionResponse{
|
return &pb.StartActionResponse{
|
||||||
LogEntry: &pb.LogEntry {
|
LogEntry: &pb.LogEntry{
|
||||||
ActionTitle: actualAction.Title,
|
ActionTitle: actualAction.Title,
|
||||||
TimedOut: res.TimedOut,
|
TimedOut: res.TimedOut,
|
||||||
Stderr: res.Stderr,
|
Stderr: res.Stderr,
|
||||||
Stdout: res.Stdout,
|
Stdout: res.Stdout,
|
||||||
ExitCode: res.ExitCode,
|
ExitCode: res.ExitCode,
|
||||||
},
|
},
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func execAction(cfg *config.Config, actualAction *config.ActionButton) *InternalLogEntry {
|
func execAction(cfg *config.Config, actualAction *config.ActionButton) *InternalLogEntry {
|
||||||
res := &InternalLogEntry {
|
res := &InternalLogEntry{
|
||||||
Datetime: time.Now().Format("2006-01-02 15:04:05"),
|
Datetime: time.Now().Format("2006-01-02 15:04:05"),
|
||||||
TimedOut: false,
|
TimedOut: false,
|
||||||
ActionTitle: actualAction.Title,
|
ActionTitle: actualAction.Title,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,14 +9,14 @@ import (
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
|
acl "github.com/jamesread/OliveTin/internal/acl"
|
||||||
config "github.com/jamesread/OliveTin/internal/config"
|
config "github.com/jamesread/OliveTin/internal/config"
|
||||||
executor "github.com/jamesread/OliveTin/internal/executor"
|
executor "github.com/jamesread/OliveTin/internal/executor"
|
||||||
acl "github.com/jamesread/OliveTin/internal/acl"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
cfg *config.Config
|
cfg *config.Config
|
||||||
ex = executor.Executor{}
|
ex = executor.Executor{}
|
||||||
)
|
)
|
||||||
|
|
||||||
type oliveTinAPI struct {
|
type oliveTinAPI struct {
|
||||||
|
|
@ -37,8 +37,7 @@ func (api *oliveTinAPI) StartAction(ctx ctx.Context, req *pb.StartActionRequest)
|
||||||
user := acl.UserFromContext(ctx)
|
user := acl.UserFromContext(ctx)
|
||||||
|
|
||||||
if !acl.IsAllowedExec(cfg, user, actualAction) {
|
if !acl.IsAllowedExec(cfg, user, actualAction) {
|
||||||
return &pb.StartActionResponse{
|
return &pb.StartActionResponse{}, nil
|
||||||
}, nil
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -56,9 +55,9 @@ func (api *oliveTinAPI) GetButtons(ctx ctx.Context, req *pb.GetButtonsRequest) (
|
||||||
}
|
}
|
||||||
|
|
||||||
btn := pb.ActionButton{
|
btn := pb.ActionButton{
|
||||||
Id: fmt.Sprintf("%x", md5.Sum([]byte(action.Title))),
|
Id: fmt.Sprintf("%x", md5.Sum([]byte(action.Title))),
|
||||||
Title: action.Title,
|
Title: action.Title,
|
||||||
Icon: lookupHTMLIcon(action.Icon),
|
Icon: lookupHTMLIcon(action.Icon),
|
||||||
CanExec: acl.IsAllowedExec(cfg, user, &action),
|
CanExec: acl.IsAllowedExec(cfg, user, &action),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -75,18 +74,18 @@ func (api *oliveTinAPI) GetButtons(ctx ctx.Context, req *pb.GetButtonsRequest) (
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *oliveTinAPI) GetLogs(ctx ctx.Context, req *pb.GetLogsRequest) (*pb.GetLogsResponse, error) {
|
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.
|
// TODO Limit to 10 entries or something to prevent browser lag.
|
||||||
|
|
||||||
for _, logEntry := range ex.Logs {
|
for _, logEntry := range ex.Logs {
|
||||||
ret.Logs = append(ret.Logs, &pb.LogEntry{
|
ret.Logs = append(ret.Logs, &pb.LogEntry{
|
||||||
ActionTitle: logEntry.ActionTitle,
|
ActionTitle: logEntry.ActionTitle,
|
||||||
Datetime: logEntry.Datetime,
|
Datetime: logEntry.Datetime,
|
||||||
Stdout: logEntry.Stdout,
|
Stdout: logEntry.Stdout,
|
||||||
Stderr: logEntry.Stderr,
|
Stderr: logEntry.Stderr,
|
||||||
TimedOut: logEntry.TimedOut,
|
TimedOut: logEntry.TimedOut,
|
||||||
ExitCode: logEntry.ExitCode,
|
ExitCode: logEntry.ExitCode,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue