• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

m-lab / packet-test / 10493180931

21 Aug 2024 03:50PM UTC coverage: 16.077% (-2.2%) from 18.241%
10493180931

push

github

web-flow
Support secure connections (#22)

0 of 8 new or added lines in 1 file covered. (0.0%)

12 existing lines in 2 files now uncovered.

100 of 622 relevant lines covered (16.08%)

0.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/cmd/server/server.go
1
package main
2

3
import (
4
        "context"
5
        "flag"
6
        "net/http"
7

8
        "github.com/m-lab/access/controller"
9
        "github.com/m-lab/access/token"
10
        "github.com/m-lab/go/flagx"
11
        "github.com/m-lab/go/rtx"
12
        "github.com/m-lab/ndt-server/ndt7/listener"
13
        "github.com/m-lab/packet-test/handler"
14
        "github.com/m-lab/packet-test/static"
15
)
16

17
var (
18
        ctx, cancel    = context.WithCancel(context.Background())
19
        dataDir        = flag.String("datadir", "./data", "Path to write data out to.")
20
        hostname       = flag.String("hostname", "localhost", "Server hostname.")
21
        address        = flag.String("address", ":80", "Listen address/port for connections.")
22
        addressSecure  = flag.String("address-secure", ":443", "Listen address/port for secure connections.")
23
        certFile       = flag.String("cert", "", "The file with server certificates in PEM format.")
24
        keyFile        = flag.String("key", "", "The file with server key in PEM format.")
25
        tokenVerifyKey = flagx.FileBytesArray{}
26
        tokenVerify    bool
27
        tokenMachine   string
28
)
29

30
func init() {
×
31
        flag.Var(&tokenVerifyKey, "token.verify-key", "Public key for verifying access tokens")
×
32
        flag.BoolVar(&tokenVerify, "token.verify", false, "Verify access tokens")
×
33
        flag.StringVar(&tokenMachine, "token.machine", "", "Use given machine name to verify token claims")
×
34
}
×
35

36
func main() {
×
37
        flag.Parse()
×
38

×
39
        v, err := token.NewVerifier(tokenVerifyKey.Get()...)
×
40
        if tokenVerify {
×
41
                rtx.Must(err, "Failed to load verifier")
×
42
        }
×
43
        paths := controller.Paths{
×
44
                static.NDT7DownloadURLPath: true,
×
45
        }
×
46
        acm, _ := controller.Setup(ctx, v, tokenVerify, tokenMachine, paths, paths)
×
47

×
48
        h := handler.New(*dataDir, *hostname)
×
49

×
50
        mux := http.NewServeMux()
×
51
        mux.HandleFunc(static.NDT7DownloadURLPath, http.HandlerFunc(h.NDT7Download))
×
52
        srv := &http.Server{
×
53
                Addr:    *address,
×
54
                Handler: acm.Then(mux),
×
55
        }
×
56
        rtx.Must(listener.ListenAndServeAsync(srv), "Failed to start server")
×
57
        defer srv.Close()
×
58

×
NEW
59
        if *certFile != "" && *keyFile != "" {
×
NEW
60
                srvSecure := &http.Server{
×
NEW
61
                        Addr:    *addressSecure,
×
NEW
62
                        Handler: acm.Then(mux),
×
NEW
63
                }
×
NEW
64
                rtx.Must(listener.ListenAndServeTLSAsync(srvSecure, *certFile, *keyFile), "Failed to start secure server")
×
NEW
65
                defer srvSecure.Close()
×
NEW
66
        }
×
67

68
        <-ctx.Done()
×
69
        cancel()
×
70
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc