| 85 | } |
| 86 | |
| 87 | func newCfgForManualLaunch(p ExternalPlugin, opts ...ManualLaunchOption) (*cfg, error) { |
| 88 | cfg := &cfg{ |
| 89 | plugin: p, |
| 90 | registrationTimeout: api.DefaultPluginRegistrationTimeout, |
| 91 | } |
| 92 | for _, o := range opts { |
| 93 | if err := o(cfg); err != nil { |
| 94 | return nil, err |
| 95 | } |
| 96 | } |
| 97 | if cfg.conn == nil { |
| 98 | socketPath := api.DaemonSocketPath() |
| 99 | conn, err := net.Dial("unix", socketPath) |
| 100 | if err != nil { |
| 101 | return nil, fmt.Errorf("failed to connect to default socket %q: %w", socketPath, err) |
| 102 | } |
| 103 | hijackedConn, err := ipc.Hijackify(conn, hijackTimeout) |
| 104 | if err != nil { |
| 105 | return nil, fmt.Errorf("external plugin rejected: %w", err) |
| 106 | } |
| 107 | cfg.conn = hijackedConn |
| 108 | } |
| 109 | if cfg.name == "" { |
| 110 | if len(os.Args) == 0 { |
| 111 | // This should never happen in practice but can happen in tests or when something else empties os.Args for whatever reason. |
| 112 | return nil, errors.New("plugin name must be specified (could not derive from os.Args)") |
| 113 | } |
| 114 | cfg.name = filepath.Base(os.Args[0]) |
| 115 | } |
| 116 | return cfg, nil |
| 117 | } |
| 118 | |
| 119 | var errPluginNotLaunchedByEngine = errors.New("plugin not launched by secrets engine") |
| 120 | |