Skip to content

Commit a4f4a43

Browse files
authored
Merge pull request #4916 from stefanberger/streamproc_env_vars
Allow passing environent variables to StreamProcessors
2 parents 6bf5650 + 1917ca5 commit a4f4a43

5 files changed

Lines changed: 9 additions & 5 deletions

File tree

diff/stream.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ func (c *compressedProcessor) Close() error {
168168
return c.rc.Close()
169169
}
170170

171-
func BinaryHandler(id, returnsMediaType string, mediaTypes []string, path string, args []string) Handler {
171+
func BinaryHandler(id, returnsMediaType string, mediaTypes []string, path string, args, env []string) Handler {
172172
set := make(map[string]struct{}, len(mediaTypes))
173173
for _, m := range mediaTypes {
174174
set[m] = struct{}{}
@@ -177,7 +177,7 @@ func BinaryHandler(id, returnsMediaType string, mediaTypes []string, path string
177177
if _, ok := set[mediaType]; ok {
178178
return func(ctx context.Context, stream StreamProcessor, payloads map[string]*types.Any) (StreamProcessor, error) {
179179
payload := payloads[id]
180-
return NewBinaryProcessor(ctx, mediaType, returnsMediaType, stream, path, args, payload)
180+
return NewBinaryProcessor(ctx, mediaType, returnsMediaType, stream, path, args, env, payload)
181181
}, true
182182
}
183183
return nil, false

diff/stream_unix.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ import (
3333
)
3434

3535
// NewBinaryProcessor returns a binary processor for use with processing content streams
36-
func NewBinaryProcessor(ctx context.Context, imt, rmt string, stream StreamProcessor, name string, args []string, payload *types.Any) (StreamProcessor, error) {
36+
func NewBinaryProcessor(ctx context.Context, imt, rmt string, stream StreamProcessor, name string, args, env []string, payload *types.Any) (StreamProcessor, error) {
3737
cmd := exec.CommandContext(ctx, name, args...)
3838
cmd.Env = os.Environ()
39+
cmd.Env = append(cmd.Env, env...)
3940

4041
var payloadC io.Closer
4142
if payload != nil {

diff/stream_windows.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ import (
3939
const processorPipe = "STREAM_PROCESSOR_PIPE"
4040

4141
// NewBinaryProcessor returns a binary processor for use with processing content streams
42-
func NewBinaryProcessor(ctx context.Context, imt, rmt string, stream StreamProcessor, name string, args []string, payload *types.Any) (StreamProcessor, error) {
42+
func NewBinaryProcessor(ctx context.Context, imt, rmt string, stream StreamProcessor, name string, args, env []string, payload *types.Any) (StreamProcessor, error) {
4343
cmd := exec.CommandContext(ctx, name, args...)
4444
cmd.Env = os.Environ()
45+
cmd.Env = append(cmd.Env, env...)
4546

4647
if payload != nil {
4748
data, err := proto.Marshal(payload)

services/server/config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ type StreamProcessor struct {
8080
Path string `toml:"path"`
8181
// Args to the binary
8282
Args []string `toml:"args"`
83+
// Environment variables for the binary
84+
Env []string `toml:"env"`
8385
}
8486

8587
// GetVersion returns the config file's version

services/server/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func New(ctx context.Context, config *srvconfig.Config) (*Server, error) {
9191
return nil, err
9292
}
9393
for id, p := range config.StreamProcessors {
94-
diff.RegisterProcessor(diff.BinaryHandler(id, p.Returns, p.Accepts, p.Path, p.Args))
94+
diff.RegisterProcessor(diff.BinaryHandler(id, p.Returns, p.Accepts, p.Path, p.Args, p.Env))
9595
}
9696

9797
serverOpts := []grpc.ServerOption{

0 commit comments

Comments
 (0)