Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ option go_package = "github.com/google/fleetspeak/fleetspeak/src/client/stdinser
// in ClientServiceConfig.config.
message Config {
string cmd = 1;

// Command line arguments.
// These arguments are prepended to the arguments specified in the message.
repeated string args = 2;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ message InputMessage {
bytes input = 1;

// Command line arguments.
// These arguments are appended to the arguments specified in the config.
repeated string args = 2;
}

Expand Down
6 changes: 5 additions & 1 deletion fleetspeak/src/client/stdinservice/stdinservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ func (s *StdinService) ProcessMessage(ctx context.Context, m *fspb.Message) erro

var stdout, stderr bytes.Buffer

cmd := exec.CommandContext(ctx, s.ssConf.Cmd, im.Args...)
var args []string
args = append(args, s.ssConf.Args...)
args = append(args, im.Args...)

cmd := exec.CommandContext(ctx, s.ssConf.Cmd, args...)
cmd.Stdin = bytes.NewBuffer(im.Input)
cmd.Stdout = &stdout
cmd.Stderr = &stderr
Expand Down
7 changes: 4 additions & 3 deletions fleetspeak/src/client/stdinservice/stdinservice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ func TestStdinServiceWithEcho(t *testing.T) {
s, err := Factory(&fspb.ClientServiceConfig{
Name: "EchoService",
Config: anypbtest.New(t, &sspb.Config{
Cmd: "python",
Cmd: "python",
Args: []string{"-c", `import sys; sys.stdout.write(" ".join(sys.argv[1:]))`},
}),
})
if err != nil {
Expand All @@ -51,7 +52,7 @@ func TestStdinServiceWithEcho(t *testing.T) {
&fspb.Message{
MessageType: "StdinServiceInputMessage",
Data: anypbtest.New(t, &sspb.InputMessage{
Args: []string{"-c", `import sys; sys.stdout.write("foo bar")`},
Args: []string{"a", "b"},
}),
})
if err != nil {
Expand All @@ -70,7 +71,7 @@ func TestStdinServiceWithEcho(t *testing.T) {
t.Fatal(err)
}

wantStdout := []byte("foo bar")
wantStdout := []byte("a b")
if !bytes.Equal(om.Stdout, wantStdout) {
t.Fatalf("unexpected output; got %q, want %q", om.Stdout, wantStdout)
}
Expand Down
Loading