MCPcopy Create free account
hub / github.com/docker/secrets-engine / setup

Function setup

plugin/setup.go:30–69  ·  view source on GitHub ↗
(ctx context.Context, config cfg, onClose func(err error))

Source from the content-addressed store, hash-verified

28)
29
30func setup(ctx context.Context, config cfg, onClose func(err error)) (io.Closer, error) {
31 httpMux := http.NewServeMux()
32 httpMux.HandleFunc("/health", func(w http.ResponseWriter, _ *http.Request) {
33 w.WriteHeader(http.StatusOK)
34 _, _ = w.Write([]byte("ok"))
35 })
36 closed := make(chan struct{})
37 once := sync.OnceFunc(func() { close(closed) })
38 httpMux.Handle(pluginsv1connect.NewPluginServiceHandler(&pluginService{func(context.Context) {
39 once()
40 }}))
41 setupCompleted := make(chan struct{})
42 httpMux.Handle(resolverv1connect.NewResolverServiceHandler(&resolverService{
43 handler: resolverv1.NewResolverHandler(config.plugin),
44 setupCompleted: setupCompleted,
45 registrationTimeout: config.registrationTimeout,
46 }))
47 ipc, c, err := ipc.NewClientIPC(config.Logger, config.conn, httpMux, func(err error) {
48 if errors.Is(err, io.EOF) {
49 config.Logger.Printf("Plugin runtime stopped, plugin %s is shutting down...", config.name)
50 err = nil // In the context of a plugin, the runtime shutting down IPC/plugin is not an error.
51 }
52 onClose(err)
53 })
54 if err != nil {
55 return nil, err
56 }
57 runtimeCfg, err := doRegister(ctx, c, config.name, config.Config, config.registrationTimeout)
58 if err != nil {
59 ipc.Close()
60 return nil, err
61 }
62 go func() {
63 <-closed
64 ipc.Close()
65 }()
66 config.Logger.Printf("Started plugin (runtime: %s@%s) %s...", runtimeCfg.Engine, runtimeCfg.Version, config.name)
67 close(setupCompleted)
68 return ipc, nil
69}

Callers 2

Test_setupFunction · 0.85
NewFunction · 0.85

Calls 5

doRegisterFunction · 0.85
HandleMethod · 0.80
PrintfMethod · 0.65
CloseMethod · 0.65
WriteMethod · 0.45

Tested by 1

Test_setupFunction · 0.68