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

mendersoftware / mender-server / 1622978334

13 Jan 2025 03:51PM UTC coverage: 72.802% (-3.8%) from 76.608%
1622978334

Pull #300

gitlab-ci

alfrunes
fix: Deployment device count should not exceed max devices

Added a condition to skip deployments when the device count reaches max
devices.

Changelog: Title
Ticket: MEN-7847
Signed-off-by: Alf-Rune Siqveland <alf.rune@northern.tech>
Pull Request #300: fix: Deployment device count should not exceed max devices

4251 of 6164 branches covered (68.96%)

Branch coverage included in aggregate %.

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

2544 existing lines in 83 files now uncovered.

42741 of 58384 relevant lines covered (73.21%)

21.49 hits per line

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

0.0
/backend/services/deployments/storage/manager/client.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 manager
16

17
import (
18
        "context"
19
        "errors"
20
        "io"
21
        "time"
22

23
        "github.com/mendersoftware/mender-server/services/deployments/model"
24
        "github.com/mendersoftware/mender-server/services/deployments/storage"
25
        "github.com/mendersoftware/mender-server/services/deployments/storage/azblob"
26
        "github.com/mendersoftware/mender-server/services/deployments/storage/s3"
27
)
28

29
var (
30
        ErrInvalidProvider = errors.New("manager: invalid storage provider")
31
)
32

33
type client struct {
34
        defaultStorage storage.ObjectStorage
35
        providerMap    map[model.StorageType]storage.ObjectStorage
36
}
37

38
func New(
39
        ctx context.Context,
40
        defaultStore storage.ObjectStorage,
41
        s3Options *s3.Options,
42
        azOptions *azblob.Options,
UNCOV
43
) (storage.ObjectStorage, error) {
×
UNCOV
44
        var err error
×
UNCOV
45
        providerMap := make(map[model.StorageType]storage.ObjectStorage, 2)
×
UNCOV
46
        providerMap[model.StorageTypeAzure], err = azblob.NewEmpty(ctx, azOptions)
×
UNCOV
47
        if err != nil {
×
48
                return nil, err
×
49
        }
×
UNCOV
50
        providerMap[model.StorageTypeS3], err = s3.NewEmpty(ctx, s3Options)
×
UNCOV
51
        if err != nil {
×
52
                return nil, err
×
53
        }
×
54

UNCOV
55
        return &client{
×
UNCOV
56
                defaultStorage: defaultStore,
×
UNCOV
57
                providerMap:    providerMap,
×
UNCOV
58
        }, nil
×
59
}
60

61
func (c *client) clientFromContext(
62
        ctx context.Context,
UNCOV
63
) (objStore storage.ObjectStorage, err error) {
×
UNCOV
64
        var ok bool
×
UNCOV
65
        if settings, _ := storage.SettingsFromContext(ctx); settings != nil {
×
UNCOV
66
                if objStore, ok = c.providerMap[settings.Type]; !ok {
×
67
                        err = ErrInvalidProvider
×
68
                }
×
UNCOV
69
        } else {
×
UNCOV
70
                objStore = c.defaultStorage
×
UNCOV
71
        }
×
UNCOV
72
        return objStore, err
×
73
}
74

UNCOV
75
func (c *client) HealthCheck(ctx context.Context) (err error) {
×
UNCOV
76
        var objStore storage.ObjectStorage
×
UNCOV
77
        objStore, err = c.clientFromContext(ctx)
×
UNCOV
78
        if err != nil {
×
79
                return err
×
80
        }
×
UNCOV
81
        return objStore.HealthCheck(ctx)
×
82
}
83

UNCOV
84
func (c *client) GetObject(ctx context.Context, path string) (io.ReadCloser, error) {
×
UNCOV
85
        objStore, err := c.clientFromContext(ctx)
×
UNCOV
86
        if err != nil {
×
87
                return nil, err
×
88
        }
×
UNCOV
89
        return objStore.GetObject(ctx, path)
×
90
}
91

UNCOV
92
func (c *client) PutObject(ctx context.Context, path string, src io.Reader) error {
×
UNCOV
93
        objStore, err := c.clientFromContext(ctx)
×
UNCOV
94
        if err != nil {
×
95
                return err
×
96
        }
×
97

UNCOV
98
        return objStore.PutObject(ctx, path, src)
×
99
}
100

UNCOV
101
func (c *client) DeleteObject(ctx context.Context, path string) error {
×
UNCOV
102
        objStore, err := c.clientFromContext(ctx)
×
UNCOV
103
        if err != nil {
×
104
                return err
×
105
        }
×
UNCOV
106
        return objStore.DeleteObject(ctx, path)
×
107
}
108

UNCOV
109
func (c *client) StatObject(ctx context.Context, path string) (*storage.ObjectInfo, error) {
×
UNCOV
110
        objStore, err := c.clientFromContext(ctx)
×
UNCOV
111
        if err != nil {
×
112
                return nil, err
×
113
        }
×
UNCOV
114
        return objStore.StatObject(ctx, path)
×
115
}
116

117
func (c *client) GetRequest(
118
        ctx context.Context,
119
        path string,
120
        filename string,
121
        duration time.Duration,
UNCOV
122
) (*model.Link, error) {
×
UNCOV
123
        objStore, err := c.clientFromContext(ctx)
×
UNCOV
124
        if err != nil {
×
125
                return nil, err
×
126
        }
×
UNCOV
127
        return objStore.GetRequest(ctx, path, filename, duration)
×
128
}
129

130
func (c *client) DeleteRequest(
131
        ctx context.Context,
132
        path string,
133
        duration time.Duration,
UNCOV
134
) (*model.Link, error) {
×
UNCOV
135
        objStore, err := c.clientFromContext(ctx)
×
UNCOV
136
        if err != nil {
×
137
                return nil, err
×
138
        }
×
UNCOV
139
        return objStore.DeleteRequest(ctx, path, duration)
×
140
}
141

142
func (c *client) PutRequest(
143
        ctx context.Context,
144
        path string,
145
        duration time.Duration,
UNCOV
146
) (*model.Link, error) {
×
UNCOV
147
        objStore, err := c.clientFromContext(ctx)
×
UNCOV
148
        if err != nil {
×
149
                return nil, err
×
150
        }
×
UNCOV
151
        return objStore.PutRequest(ctx, path, duration)
×
152
}
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