MCPcopy Index your code
hub / github.com/docker/cli / RunHook

Method RunHook

cli-plugins/manager/plugin.go:158–177  ·  view source on GitHub ↗

RunHook executes the plugin's hooks command and returns its unprocessed output.

(ctx context.Context, hookData hooks.Request)

Source from the content-addressed store, hash-verified

156// RunHook executes the plugin's hooks command
157// and returns its unprocessed output.
158func (p *Plugin) RunHook(ctx context.Context, hookData hooks.Request) ([]byte, error) {
159 hDataBytes, err := json.Marshal(hookData)
160 if err != nil {
161 return nil, wrapAsPluginError(err, "failed to marshall hook data")
162 }
163
164 pCmd := exec.CommandContext(ctx, p.Path, p.Name, metadata.HookSubcommandName, string(hDataBytes)) // #nosec G204 -- ignore "Subprocess launched with a potential tainted input or cmd arguments"
165 pCmd.Env = os.Environ()
166 pCmd.Env = append(pCmd.Env, metadata.ReexecEnvvar+"="+os.Args[0])
167
168 out, err := pCmd.Output()
169 if err != nil {
170 var exitErr *exec.ExitError
171 if errors.As(err, &exitErr) {
172 return nil, wrapAsPluginError(err, "plugin hook subcommand exited unsuccessfully")
173 }
174 return nil, wrapAsPluginError(err, "failed to execute plugin hook subcommand: "+pCmd.String())
175 }
176 return out, nil
177}
178
179// pluginNameFormat is used as part of errors for invalid plugin-names.
180// We should consider making this less technical ("must start with "a-z",

Callers 1

invokeAndCollectHooksFunction · 0.80

Calls 3

wrapAsPluginErrorFunction · 0.85
OutputMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected