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

mendersoftware / inventory / 1358092525

01 Jul 2024 10:03AM UTC coverage: 91.217%. Remained the same
1358092525

push

gitlab-ci

web-flow
Merge pull request #459 from mendersoftware/dependabot/docker/docker-dependencies-0bdf6079d6

chore: bump golang from 1.22.3-alpine3.19 to 1.22.4-alpine3.19 in the docker-dependencies group

3095 of 3393 relevant lines covered (91.22%)

148.68 hits per line

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

84.62
/server.go
1
// Copyright 2023 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
package main
15

16
import (
17
        "net/http"
18

19
        "github.com/pkg/errors"
20

21
        "github.com/mendersoftware/go-lib-micro/log"
22

23
        api_http "github.com/mendersoftware/inventory/api/http"
24
        "github.com/mendersoftware/inventory/client/devicemonitor"
25
        "github.com/mendersoftware/inventory/client/workflows"
26
        "github.com/mendersoftware/inventory/config"
27
        inventory "github.com/mendersoftware/inventory/inv"
28
        "github.com/mendersoftware/inventory/store/mongo"
29
)
30

31
func RunServer(c config.Reader) error {
1✔
32

1✔
33
        l := log.New(log.Ctx{})
1✔
34

1✔
35
        db, err := mongo.NewDataStoreMongo(makeDataStoreConfig())
1✔
36
        if err != nil {
1✔
37
                return errors.Wrap(err, "database connection failed")
×
38
        }
×
39

40
        limitAttributes := c.GetInt(SettingLimitAttributes)
1✔
41
        limitTags := c.GetInt(SettingLimitTags)
1✔
42

1✔
43
        inv := inventory.NewInventory(db).WithLimits(limitAttributes, limitTags)
1✔
44

1✔
45
        devicemonitorAddr := c.GetString(SettingDevicemonitorAddr)
1✔
46
        if devicemonitorAddr != "" {
2✔
47
                c := devicemonitor.NewClient(devicemonitorAddr)
1✔
48
                inv = inv.WithDevicemonitor(c)
1✔
49
        }
1✔
50

51
        if inv, err = maybeWithInventory(inv, c); err != nil {
1✔
52
                return err
×
53
        }
×
54

55
        invapi := api_http.NewInventoryApiHandlers(inv)
1✔
56
        handler, err := invapi.Build()
1✔
57
        if err != nil {
1✔
58
                return errors.Wrap(err, "inventory API handlers setup failed")
×
59
        }
×
60
        addr := c.GetString(SettingListen)
1✔
61
        l.Printf("listening on %s", addr)
1✔
62

1✔
63
        return http.ListenAndServe(addr, handler)
1✔
64
}
65

66
func maybeWithInventory(
67
        inv inventory.InventoryApp,
68
        c config.Reader,
69
) (inventory.InventoryApp, error) {
3✔
70
        if reporting := c.GetBool(SettingEnableReporting); reporting {
5✔
71
                orchestrator := c.GetString(SettingOrchestratorAddr)
2✔
72
                if orchestrator == "" {
3✔
73
                        return inv, errors.New("reporting integration needs orchestrator address")
1✔
74
                }
1✔
75

76
                c := workflows.NewClient(orchestrator)
1✔
77
                inv = inv.WithReporting(c)
1✔
78
        }
79
        return inv, nil
2✔
80
}
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