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

mendersoftware / mender-server / 1927964654

15 Jul 2025 01:18PM UTC coverage: 65.511% (+0.06%) from 65.454%
1927964654

Pull #783

gitlab-ci

bahaa-ghazal
feat: Integrate requestsize middleware into useradm

Title: None
Signed-off-by: Bahaa Aldeen Ghazal <bahaa.ghazal@northern.tech>
Pull Request #783: feat: Implemented gin request body size limiter middleware

131 of 139 new or added lines in 17 files covered. (94.24%)

6 existing lines in 1 file now uncovered.

32173 of 49111 relevant lines covered (65.51%)

1.4 hits per line

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

81.58
/backend/services/reporting/api/http/router.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 http
16

17
import (
18
        "github.com/gin-gonic/gin"
19

20
        "github.com/mendersoftware/mender-server/pkg/identity"
21
        "github.com/mendersoftware/mender-server/pkg/rbac"
22
        "github.com/mendersoftware/mender-server/pkg/requestsize"
23
        "github.com/mendersoftware/mender-server/pkg/routing"
24

25
        "github.com/mendersoftware/mender-server/services/reporting/app/reporting"
26
        dconfig "github.com/mendersoftware/mender-server/services/reporting/config"
27
)
28

29
// API URL used by the HTTP router
30
const (
31
        URIInternal   = "/api/internal/v1/reporting"
32
        URIManagement = "/api/management/v1/reporting"
33

34
        URIAlive                   = "/alive"
35
        URIHealth                  = "/health"
36
        URIDeploymentsAggregate    = "/deployments/devices/aggregate"
37
        URIDeploymentsSearch       = "/deployments/devices/search"
38
        URIInventoryAggregate      = "/devices/aggregate"
39
        URIInventoryAttrs          = "/devices/attributes"
40
        URIInventorySearch         = "/devices/search"
41
        URIInventorySearchAttrs    = "/devices/search/attributes"
42
        URIInventorySearchInternal = "/tenants/:tenant_id/devices/search"
43
)
44

45
type Config struct {
46
        MaxRequestSize int64
47
}
48

49
func NewConfig() *Config {
1✔
50
        return &Config{
1✔
51
                MaxRequestSize: dconfig.SettingMaxRequestSizeDefault,
1✔
52
        }
1✔
53
}
1✔
54

55
type Option func(c *Config)
56

NEW
57
func SetMaxRequestSize(size int64) Option {
×
NEW
58
        return func(c *Config) {
×
NEW
59
                c.MaxRequestSize = size
×
NEW
60
        }
×
61
}
62

63
// NewRouter returns the gin router
64
func NewRouter(reporting reporting.App, options ...Option) *gin.Engine {
1✔
65
        config := NewConfig()
1✔
66
        for _, option := range options {
1✔
NEW
67
                if option != nil {
×
NEW
68
                        option(config)
×
NEW
69
                }
×
70
        }
71

72
        router := routing.NewGinRouter()
1✔
73
        router.Use(requestsize.Middleware(config.MaxRequestSize))
1✔
74

1✔
75
        internal := NewInternalController(reporting)
1✔
76
        internalAPI := router.Group(URIInternal)
1✔
77
        internalAPI.GET(URIAlive, internal.Alive)
1✔
78
        internalAPI.GET(URIHealth, internal.Health)
1✔
79
        internalAPI.POST(URIInventorySearchInternal, internal.SearchDevices)
1✔
80

1✔
81
        mgmt := NewManagementController(reporting)
1✔
82
        mgmtAPI := router.Group(URIManagement)
1✔
83
        mgmtAPI.Use(identity.Middleware())
1✔
84
        mgmtAPI.Use(rbac.Middleware())
1✔
85
        // devices
1✔
86
        mgmtAPI.POST(URIInventoryAggregate, mgmt.AggregateDevices)
1✔
87
        mgmtAPI.GET(URIInventoryAttrs, mgmt.DeviceAttrs)
1✔
88
        mgmtAPI.POST(URIInventorySearch, mgmt.SearchDevices)
1✔
89
        mgmtAPI.GET(URIInventorySearchAttrs, mgmt.SearchDeviceAttrs)
1✔
90
        // deployments
1✔
91
        mgmtAPI.POST(URIDeploymentsAggregate, mgmt.AggregateDeployments)
1✔
92
        mgmtAPI.POST(URIDeploymentsSearch, mgmt.SearchDeployments)
1✔
93

1✔
94
        return router
1✔
95
}
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