(ctx context.Context, httpServer *http.Server)
| 37 | } |
| 38 | |
| 39 | func (c *commandServerStart) startServerWithOptionalTLS(ctx context.Context, httpServer *http.Server) error { |
| 40 | var l net.Listener |
| 41 | |
| 42 | var err error |
| 43 | |
| 44 | listeners, err := activation.Listeners() |
| 45 | if err != nil { |
| 46 | return errors.Wrap(err, "socket-activation error") |
| 47 | } |
| 48 | |
| 49 | switch len(listeners) { |
| 50 | case 0: |
| 51 | if after, ok := strings.CutPrefix(httpServer.Addr, "unix:"); ok { |
| 52 | l, err = (&net.ListenConfig{}).Listen(ctx, "unix", after) |
| 53 | } else { |
| 54 | l, err = (&net.ListenConfig{}).Listen(ctx, "tcp", httpServer.Addr) |
| 55 | } |
| 56 | |
| 57 | if err != nil { |
| 58 | return errors.Wrap(err, "listen error") |
| 59 | } |
| 60 | case 1: |
| 61 | l = listeners[0] |
| 62 | default: |
| 63 | return errors.Errorf("Too many activated sockets found. Expected 1, got %v", len(listeners)) |
| 64 | } |
| 65 | |
| 66 | if err := insecureserverbind.ValidateListenerAddrIfRestricted( |
| 67 | c.serverStartInsecure, |
| 68 | c.serverStartWithoutPassword, |
| 69 | c.serverStartAllowDangerousUnauthenticatedNetwork, |
| 70 | l.Addr(), |
| 71 | ); err != nil { |
| 72 | l.Close() //nolint:errcheck |
| 73 | |
| 74 | return errors.Wrap(err, "insecure server bind validation") |
| 75 | } |
| 76 | |
| 77 | defer l.Close() //nolint:errcheck |
| 78 | |
| 79 | httpServer.Addr = l.Addr().String() |
| 80 | |
| 81 | return c.startServerWithOptionalTLSAndListener(ctx, httpServer, l) |
| 82 | } |
| 83 | |
| 84 | func (c *commandServerStart) maybeGenerateTLS(ctx context.Context) error { |
| 85 | if !c.serverStartTLSGenerateCert || c.serverStartTLSCertFile == "" || c.serverStartTLSKeyFile == "" { |
no test coverage detected