Skip to content

Commit e16a9f9

Browse files
Copybara Servicecopybara-github
authored andcommitted
Support preconfigured args in stdinservice.
PiperOrigin-RevId: 802948632
1 parent bfd1358 commit e16a9f9

File tree

6 files changed

+35
-12
lines changed

6 files changed

+35
-12
lines changed

fleetspeak/src/client/stdinservice/proto/fleetspeak_stdinservice/config.pb.go

Lines changed: 20 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fleetspeak/src/client/stdinservice/proto/fleetspeak_stdinservice/config.proto

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,8 @@ option go_package = "github.com/google/fleetspeak/fleetspeak/src/client/stdinser
88
// in ClientServiceConfig.config.
99
message Config {
1010
string cmd = 1;
11+
12+
// Command line arguments.
13+
// These arguments are prepended to the arguments specified in the message.
14+
repeated string args = 2;
1115
}

fleetspeak/src/client/stdinservice/proto/fleetspeak_stdinservice/messages.pb.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fleetspeak/src/client/stdinservice/proto/fleetspeak_stdinservice/messages.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ message InputMessage {
1111
bytes input = 1;
1212

1313
// Command line arguments.
14+
// These arguments are appended to the arguments specified in the config.
1415
repeated string args = 2;
1516
}
1617

fleetspeak/src/client/stdinservice/stdinservice.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,11 @@ func (s *StdinService) ProcessMessage(ctx context.Context, m *fspb.Message) erro
8181

8282
var stdout, stderr bytes.Buffer
8383

84-
cmd := exec.CommandContext(ctx, s.ssConf.Cmd, im.Args...)
84+
var args []string
85+
args = append(args, s.ssConf.Args...)
86+
args = append(args, im.Args...)
87+
88+
cmd := exec.CommandContext(ctx, s.ssConf.Cmd, args...)
8589
cmd.Stdin = bytes.NewBuffer(im.Input)
8690
cmd.Stdout = &stdout
8791
cmd.Stderr = &stderr

fleetspeak/src/client/stdinservice/stdinservice_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ func TestStdinServiceWithEcho(t *testing.T) {
3232
s, err := Factory(&fspb.ClientServiceConfig{
3333
Name: "EchoService",
3434
Config: anypbtest.New(t, &sspb.Config{
35-
Cmd: "python",
35+
Cmd: "python",
36+
Args: []string{"-c", `import sys; sys.stdout.write(" ".join(sys.argv[1:]))`},
3637
}),
3738
})
3839
if err != nil {
@@ -51,7 +52,7 @@ func TestStdinServiceWithEcho(t *testing.T) {
5152
&fspb.Message{
5253
MessageType: "StdinServiceInputMessage",
5354
Data: anypbtest.New(t, &sspb.InputMessage{
54-
Args: []string{"-c", `import sys; sys.stdout.write("foo bar")`},
55+
Args: []string{"a", "b"},
5556
}),
5657
})
5758
if err != nil {
@@ -70,7 +71,7 @@ func TestStdinServiceWithEcho(t *testing.T) {
7071
t.Fatal(err)
7172
}
7273

73-
wantStdout := []byte("foo bar")
74+
wantStdout := []byte("a b")
7475
if !bytes.Equal(om.Stdout, wantStdout) {
7576
t.Fatalf("unexpected output; got %q, want %q", om.Stdout, wantStdout)
7677
}

0 commit comments

Comments
 (0)