Skip to content

Commit

Permalink
feat: Allow managedplugins to control their environment (#246)
Browse files Browse the repository at this point in the history
This change allows callers of managedplugin to optionally pass in an `Environment` array, which, if used, will replace the default os.Environ for the created plugin.

The idea is that we will use this from the CLI to isolate plugin environment from one another. The core logic of how exactly that happens will stay in the CLI.
  • Loading branch information
hermanschaaf authored Feb 20, 2024
1 parent 277b6f2 commit 31fbbf0
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions managedplugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@ func (p PluginType) String() string {
type Clients []*Client

type Config struct {
Name string
Registry Registry
Path string
Version string
Name string
Registry Registry
Path string
Version string
Environment []string // environment variables to pass to the plugin in key=value format
}

type Client struct {
Expand Down Expand Up @@ -276,6 +277,7 @@ func (c *Client) startDockerPlugin(ctx context.Context, configPath string) error
Image: configPath,
Cmd: pluginArgs,
Tty: true,
Env: c.config.Environment,
}
hostConfig := &container.HostConfig{
PortBindings: map[nat.Port][]nat.PortBinding{
Expand Down Expand Up @@ -393,6 +395,9 @@ func (c *Client) startLocal(ctx context.Context, path string) error {
return fmt.Errorf("failed to get stdout pipe: %w", err)
}
cmd.Stderr = os.Stderr
if c.config.Environment != nil {
cmd.Env = c.config.Environment
}
cmd.SysProcAttr = getSysProcAttr()
if err := cmd.Start(); err != nil {
return fmt.Errorf("failed to start plugin %s: %w", path, err)
Expand Down

0 comments on commit 31fbbf0

Please sign in to comment.