• 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/useradm/model/token.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 model
16

17
import (
18
        "encoding/json"
19
        "time"
20

21
        validation "github.com/go-ozzo/ozzo-validation/v4"
22

23
        "github.com/mendersoftware/mender-server/pkg/mongo/oid"
24

25
        "github.com/mendersoftware/mender-server/services/useradm/jwt"
26
)
27

28
type TokenRequest struct {
29
        Name      *string `json:"name"`
30
        ExpiresIn int64   `json:"expires_in"`
31
}
32

33
const defaultTokenMaxExpiration = 31536000
34

UNCOV
35
func (tr TokenRequest) Validate(maxExpiration int) error {
×
UNCOV
36
        if maxExpiration <= 0 {
×
37
                maxExpiration = defaultTokenMaxExpiration
×
38
        }
×
UNCOV
39
        return validation.ValidateStruct(&tr,
×
UNCOV
40
                validation.Field(&tr.Name, validation.Required, lessThan4096),
×
UNCOV
41
                validation.Field(&tr.ExpiresIn, validation.Min(0), validation.Max(maxExpiration)))
×
42
}
43

44
type PersonalAccessToken struct {
45
        // system-generated user ID
46
        ID oid.ObjectID `json:"id,omitempty" bson:"_id,omitempty"`
47
        // token name
48
        Name *string `json:"name,omitempty" on:"name,omitempty"`
49
        // timestamp of the last usage
50
        LastUsed *time.Time `json:"last_used,omitempty" bson:"last_used,omitempty"`
51
        // the absolute time when the token expires.
52
        ExpirationDate *jwt.Time `json:"expiration_date,omitempty" bson:"exp,omitempty"`
53
        // CreatedTs is the absolute time the token was created.
54
        CreatedTs jwt.Time `json:"created_ts,omitempty" bson:"iat,omitempty"`
55
}
56

57
type apiToken struct {
58
        // system-generated user ID
59
        ID oid.ObjectID `json:"id,omitempty"`
60
        // token name
61
        Name *string `json:"name,omitempty"`
62
        // timestamp of the last usage
63
        LastUsed *time.Time `json:"last_used,omitempty"`
64
        // the absolute time when the token expires
65
        ExpirationDate *time.Time `json:"expiration_date,omitempty"`
66
        // timestamp of the token creation
67
        CreatedTs *time.Time `json:"created_ts,omitempty"`
68
}
69

UNCOV
70
func newApiToken(t PersonalAccessToken) apiToken {
×
UNCOV
71
        var expiration *time.Time
×
UNCOV
72
        if t.ExpirationDate != nil {
×
UNCOV
73
                expiration = &t.ExpirationDate.Time
×
UNCOV
74
        }
×
UNCOV
75
        return apiToken{
×
UNCOV
76
                t.ID,
×
UNCOV
77
                t.Name,
×
UNCOV
78
                t.LastUsed,
×
UNCOV
79
                expiration,
×
UNCOV
80
                &t.CreatedTs.Time,
×
UNCOV
81
        }
×
82
}
83

UNCOV
84
func (t PersonalAccessToken) MarshalJSON() ([]byte, error) {
×
UNCOV
85
        return json.Marshal(newApiToken(t))
×
UNCOV
86
}
×
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