Skip to content

Commit

Permalink
[coconut] Include user@host in relevant coconut requests
Browse files Browse the repository at this point in the history
  • Loading branch information
teo committed Jul 12, 2024
1 parent e045f52 commit 22a875a
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 5 deletions.
45 changes: 40 additions & 5 deletions coconut/control/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"text/template"
"time"

commonpb "github.com/AliceO2Group/Control/common/protos"
"github.com/fatih/color"

"github.com/xlab/treeprint"
Expand Down Expand Up @@ -365,7 +366,13 @@ func CreateEnvironment(cxt context.Context, rpc *coconut.RpcClient, cmd *cobra.C
WithError(err).
Fatal("command finished with error")
}
_, err = rpc.NewAutoEnvironment(cxt, &pb.NewAutoEnvironmentRequest{WorkflowTemplate: wfPath, Vars: extraVarsMap, Id: id}, grpc.EmptyCallOption{})
_, err = rpc.NewAutoEnvironment(cxt, &pb.NewAutoEnvironmentRequest{
WorkflowTemplate: wfPath,
Vars: extraVarsMap,
Id: id,
RequestUser: &commonpb.User{
Name: getUserAndHost(),
}}, grpc.EmptyCallOption{})
if err != nil {
return err
}
Expand Down Expand Up @@ -424,9 +431,23 @@ func CreateEnvironment(cxt context.Context, rpc *coconut.RpcClient, cmd *cobra.C

var response *pb.NewEnvironmentReply
if asynchronous {
response, err = rpc.NewEnvironmentAsync(cxt, &pb.NewEnvironmentRequest{WorkflowTemplate: wfPath, Vars: extraVarsMap, Public: public}, grpc.EmptyCallOption{})
response, err = rpc.NewEnvironmentAsync(cxt, &pb.NewEnvironmentRequest{
WorkflowTemplate: wfPath,
Vars: extraVarsMap,
Public: public,
RequestUser: &commonpb.User{
Name: getUserAndHost(),
},
}, grpc.EmptyCallOption{})
} else {
response, err = rpc.NewEnvironment(cxt, &pb.NewEnvironmentRequest{WorkflowTemplate: wfPath, Vars: extraVarsMap, Public: public}, grpc.EmptyCallOption{})
response, err = rpc.NewEnvironment(cxt, &pb.NewEnvironmentRequest{
WorkflowTemplate: wfPath,
Vars: extraVarsMap,
Public: public,
RequestUser: &commonpb.User{
Name: getUserAndHost(),
},
}, grpc.EmptyCallOption{})
}
if err != nil {
return
Expand Down Expand Up @@ -588,7 +609,13 @@ func ControlEnvironment(cxt context.Context, rpc *coconut.RpcClient, cmd *cobra.
}

var response *pb.ControlEnvironmentReply
response, err = rpc.ControlEnvironment(cxt, &pb.ControlEnvironmentRequest{Id: args[0], Type: pb.ControlEnvironmentRequest_Optype(pb.ControlEnvironmentRequest_Optype_value[event])}, grpc.EmptyCallOption{})
response, err = rpc.ControlEnvironment(cxt, &pb.ControlEnvironmentRequest{
Id: args[0],
Type: pb.ControlEnvironmentRequest_Optype(pb.ControlEnvironmentRequest_Optype_value[event]),
RequestUser: &commonpb.User{
Name: getUserAndHost(),
},
}, grpc.EmptyCallOption{})
if err != nil {
return
}
Expand Down Expand Up @@ -717,7 +744,15 @@ func DestroyEnvironment(cxt context.Context, rpc *coconut.RpcClient, cmd *cobra.
keepTasks = false
}

_, err = rpc.DestroyEnvironment(cxt, &pb.DestroyEnvironmentRequest{Id: envId, KeepTasks: keepTasks, AllowInRunningState: allowInRunningState, Force: force}, grpc.EmptyCallOption{})
_, err = rpc.DestroyEnvironment(cxt, &pb.DestroyEnvironmentRequest{
Id: envId,
KeepTasks: keepTasks,
AllowInRunningState: allowInRunningState,
Force: force,
RequestUser: &commonpb.User{
Name: getUserAndHost(),
},
}, grpc.EmptyCallOption{})
if err != nil {
return
}
Expand Down
19 changes: 19 additions & 0 deletions coconut/control/controlutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
"encoding/json"
"fmt"
"io"
"os"
"os/user"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -191,3 +193,20 @@ func formatNumber(numberOfMachines int32) string {
}
return nMString
}

func getUserAndHost() string {
userName := "unknown"
hostName := "unknown"

currentUser, err := user.Current()
if err == nil {
userName = currentUser.Username
}

currentHost, err := os.Hostname()
if err == nil {
hostName = currentHost
}

return fmt.Sprintf("%s@%s", userName, hostName)
}

0 comments on commit 22a875a

Please sign in to comment.