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

mendersoftware / deviceconnect / 938326290

pending completion
938326290

push

gitlab-ci

web-flow
Merge pull request #251 from lluiscampos/chore-update-dind

ci: Update Docker-inDocker service images to latest

2546 of 3223 relevant lines covered (78.99%)

22.83 hits per line

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

82.46
/server/server.go
1
// Copyright 2022 Northern.tech AS
2
//
3
//    Licensed under the Apache License, Version 2.0 (the "License");
4
//    you may not use this file except in compliance with the License.
5
//    You may obtain a copy of the License at
6
//
7
//        http://www.apache.org/licenses/LICENSE-2.0
8
//
9
//    Unless required by applicable law or agreed to in writing, software
10
//    distributed under the License is distributed on an "AS IS" BASIS,
11
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
//    See the License for the specific language governing permissions and
13
//    limitations under the License.
14

15
package server
16

17
import (
18
        "context"
19
        "net/http"
20
        "os"
21
        "os/signal"
22
        "time"
23

24
        "github.com/mendersoftware/go-lib-micro/config"
25
        "github.com/mendersoftware/go-lib-micro/log"
26
        "golang.org/x/sys/unix"
27

28
        api "github.com/mendersoftware/deviceconnect/api/http"
29
        "github.com/mendersoftware/deviceconnect/app"
30
        "github.com/mendersoftware/deviceconnect/client/inventory"
31
        "github.com/mendersoftware/deviceconnect/client/nats"
32
        "github.com/mendersoftware/deviceconnect/client/workflows"
33
        dconfig "github.com/mendersoftware/deviceconnect/config"
34
        "github.com/mendersoftware/deviceconnect/store"
35
)
36

37
// InitAndRun initializes the server and runs it
38
func InitAndRun(conf config.Reader, dataStore store.DataStore) error {
1✔
39
        ctx := context.Background()
1✔
40

1✔
41
        log.Setup(conf.GetBool(dconfig.SettingDebugLog))
1✔
42
        l := log.FromContext(ctx)
1✔
43

1✔
44
        allowedOrigin := conf.GetStringSlice(dconfig.SettingWSAllowedOrigins)
1✔
45
        if allowedOrigin != nil {
2✔
46
                api.SetAcceptedOrigins(allowedOrigin)
1✔
47
        }
1✔
48

49
        natsClient, err := nats.NewClientWithDefaults(
1✔
50
                config.Config.GetString(dconfig.SettingNatsURI),
1✔
51
        )
1✔
52
        if err != nil {
1✔
53
                return err
×
54
        }
×
55
        inventory := inventory.NewClient(
1✔
56
                config.Config.GetString(dconfig.SettingInventoryURI),
1✔
57
                config.Config.GetInt(dconfig.SettingInventoryTimeout),
1✔
58
        )
1✔
59
        wflows := workflows.NewClient(
1✔
60
                config.Config.GetString(dconfig.SettingWorkflowsURL),
1✔
61
        )
1✔
62
        deviceConnectApp := app.New(
1✔
63
                dataStore, inventory,
1✔
64
                wflows, app.Config{
1✔
65
                        HaveAuditLogs: conf.GetBool(dconfig.SettingEnableAuditLogs),
1✔
66
                },
1✔
67
        )
1✔
68

1✔
69
        router, err := api.NewRouter(deviceConnectApp, natsClient)
1✔
70
        if err != nil {
1✔
71
                l.Fatal(err)
×
72
        }
×
73

74
        var listen = conf.GetString(dconfig.SettingListen)
1✔
75
        srv := &http.Server{
1✔
76
                Addr:    listen,
1✔
77
                Handler: router,
1✔
78
        }
1✔
79

1✔
80
        go func() {
2✔
81
                if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
1✔
82
                        l.Fatalf("listen: %s\n", err)
×
83
                }
×
84
        }()
85

86
        quit := make(chan os.Signal, 1)
1✔
87
        signal.Notify(quit, unix.SIGINT, unix.SIGTERM)
1✔
88
        <-quit
1✔
89

1✔
90
        l.Info("server shutdown")
1✔
91

1✔
92
        ctxWithTimeout, cancel := context.WithTimeout(ctx, 5*time.Second)
1✔
93
        defer cancel()
1✔
94
        if err := srv.Shutdown(ctxWithTimeout); err != nil {
1✔
95
                l.Fatal("error when shutting down the server ", err)
×
96
        }
×
97

98
        l.Info("server exiting")
×
99
        return nil
×
100
}
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

© 2025 Coveralls, Inc