MCPcopy Index your code
hub / github.com/kopia/kopia / startServerWithOptionalTLS

Method startServerWithOptionalTLS

cli/command_server_tls.go:39–82  ·  view source on GitHub ↗
(ctx context.Context, httpServer *http.Server)

Source from the content-addressed store, hash-verified

37}
38
39func (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
84func (c *commandServerStart) maybeGenerateTLS(ctx context.Context) error {
85 if !c.serverStartTLSGenerateCert || c.serverStartTLSCertFile == "" || c.serverStartTLSKeyFile == "" {

Callers 1

runMethod · 0.95

Calls 5

ErrorfMethod · 0.80
CloseMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected