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

mendersoftware / deviceauth / 1284672998

09 May 2024 01:19PM UTC coverage: 81.658% (-1.1%) from 82.796%
1284672998

Pull #715

gitlab-ci

alfrunes
test(acceptance/os): :broom: Remove unused fixtures

Signed-off-by: Alf-Rune Siqveland <alf.rune@northern.tech>
Pull Request #715: Acceptance test fixup

4808 of 5888 relevant lines covered (81.66%)

51.13 hits per line

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

65.91
/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

15
package main
16

17
import (
18
        "context"
19
        "net/http"
20
        "time"
21

22
        "github.com/mendersoftware/go-lib-micro/config"
23
        "github.com/mendersoftware/go-lib-micro/log"
24
        "github.com/pkg/errors"
25

26
        api_http "github.com/mendersoftware/deviceauth/api/http"
27
        "github.com/mendersoftware/deviceauth/cache"
28
        "github.com/mendersoftware/deviceauth/client/orchestrator"
29
        "github.com/mendersoftware/deviceauth/client/tenant"
30
        dconfig "github.com/mendersoftware/deviceauth/config"
31
        "github.com/mendersoftware/deviceauth/devauth"
32
        "github.com/mendersoftware/deviceauth/jwt"
33
        "github.com/mendersoftware/deviceauth/store/mongo"
34
)
35

36
func RunServer(c config.Reader) error {
1✔
37
        var tenantadmAddr = c.GetString(dconfig.SettingTenantAdmAddr)
1✔
38

1✔
39
        l := log.New(log.Ctx{})
1✔
40

1✔
41
        db, err := mongo.NewDataStoreMongo(
1✔
42
                mongo.DataStoreMongoConfig{
1✔
43
                        ConnectionString: c.GetString(dconfig.SettingDb),
1✔
44

1✔
45
                        SSL:           c.GetBool(dconfig.SettingDbSSL),
1✔
46
                        SSLSkipVerify: c.GetBool(dconfig.SettingDbSSLSkipVerify),
1✔
47

1✔
48
                        Username: c.GetString(dconfig.SettingDbUsername),
1✔
49
                        Password: c.GetString(dconfig.SettingDbPassword),
1✔
50
                })
1✔
51
        if err != nil {
1✔
52
                return errors.Wrap(err, "database connection failed")
×
53
        }
×
54

55
        jwtHandler, err := jwt.NewJWTHandler(
1✔
56
                c.GetString(dconfig.SettingServerPrivKeyPath),
1✔
57
        )
1✔
58
        var jwtFallbackHandler jwt.Handler
1✔
59
        fallback := c.GetString(dconfig.SettingServerFallbackPrivKeyPath)
1✔
60
        if err == nil && fallback != "" {
1✔
61
                jwtFallbackHandler, err = jwt.NewJWTHandler(
×
62
                        fallback,
×
63
                )
×
64
        }
×
65
        if err != nil {
1✔
66
                return err
×
67
        }
×
68

69
        orchClientConf := orchestrator.Config{
1✔
70
                OrchestratorAddr: c.GetString(dconfig.SettingOrchestratorAddr),
1✔
71
                Timeout:          time.Duration(30) * time.Second,
1✔
72
        }
1✔
73

1✔
74
        devauth := devauth.NewDevAuth(db,
1✔
75
                orchestrator.NewClient(orchClientConf),
1✔
76
                jwtHandler,
1✔
77
                devauth.Config{
1✔
78
                        Issuer:             c.GetString(dconfig.SettingJWTIssuer),
1✔
79
                        ExpirationTime:     int64(c.GetInt(dconfig.SettingJWTExpirationTimeout)),
1✔
80
                        DefaultTenantToken: c.GetString(dconfig.SettingDefaultTenantToken),
1✔
81
                        InventoryAddr:      config.Config.GetString(dconfig.SettingInventoryAddr),
1✔
82

1✔
83
                        EnableReporting: config.Config.GetBool(dconfig.SettingEnableReporting),
1✔
84
                        HaveAddons: config.Config.GetBool(dconfig.SettingHaveAddons) &&
1✔
85
                                tenantadmAddr != "",
1✔
86
                })
1✔
87

1✔
88
        if jwtFallbackHandler != nil {
1✔
89
                devauth = devauth.WithJWTFallbackHandler(jwtFallbackHandler)
×
90
        }
×
91

92
        if tenantadmAddr != "" {
1✔
93
                tc := tenant.NewClient(tenant.Config{
×
94
                        TenantAdmAddr: tenantadmAddr,
×
95
                })
×
96
                devauth = devauth.WithTenantVerification(tc)
×
97
        }
×
98

99
        cacheConnStr := c.GetString(dconfig.SettingRedisConnectionString)
1✔
100
        if cacheConnStr == "" {
2✔
101
                // for backward compatibility check old redis_addr setting
1✔
102
                cacheConnStr = c.GetString(dconfig.SettingRedisAddr)
1✔
103
        }
1✔
104
        if cacheConnStr != "" {
1✔
105
                l.Infof("setting up redis cache")
×
106

×
107
                cache, err := cache.NewRedisCache(
×
108
                        context.TODO(),
×
109
                        cacheConnStr,
×
110
                        c.GetString(dconfig.SettingRedisKeyPrefix),
×
111
                        c.GetInt(dconfig.SettingRedisLimitsExpSec),
×
112
                )
×
113

×
114
                if err != nil {
×
115
                        return err
×
116
                }
×
117

118
                devauth = devauth.WithCache(cache)
×
119
        }
120

121
        devauthapi := api_http.NewDevAuthApiHandlers(devauth, db)
1✔
122

1✔
123
        apiHandler, err := devauthapi.Build()
1✔
124
        if err != nil {
1✔
125
                return errors.Wrap(err, "device authentication API handlers setup failed")
×
126
        }
×
127

128
        addr := c.GetString(dconfig.SettingListen)
1✔
129
        l.Printf("listening on %s", addr)
1✔
130

1✔
131
        return http.ListenAndServe(addr, apiHandler)
1✔
132
}
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