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

mendersoftware / mender-server / 1495380963

14 Oct 2024 03:35PM UTC coverage: 70.373% (-2.5%) from 72.904%
1495380963

Pull #101

gitlab-ci

mineralsfree
feat: tenant list added

Ticket: MEN-7568
Changelog: None

Signed-off-by: Mikita Pilinka <mikita.pilinka@northern.tech>
Pull Request #101: feat: tenant list added

4406 of 6391 branches covered (68.94%)

Branch coverage included in aggregate %.

88 of 183 new or added lines in 10 files covered. (48.09%)

2623 existing lines in 65 files now uncovered.

36673 of 51982 relevant lines covered (70.55%)

31.07 hits per line

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

0.0
/backend/services/deviceconnect/model/session.go
1
// Copyright 2021 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
        "strings"
19
        "sync"
20
        "time"
21

22
        validation "github.com/go-ozzo/ozzo-validation/v4"
23
)
24

25
// Values for the session status attribute
26
const (
27
        SessionStatusDisconnected = "disconnected"
28
        SessiontatusConnected     = "connected"
29
)
30

31
// Values for the session types attribute
32
const (
33
        SessionTypeTerminal    = "terminal"
34
        SessionTypePortForward = "portforward"
35
)
36

UNCOV
37
func GetSessionSubject(tenantID, sessionID string) string {
×
UNCOV
38
        if tenantID == "" {
×
UNCOV
39
                return strings.Join([]string{
×
UNCOV
40
                        "session", sessionID,
×
UNCOV
41
                }, ".")
×
UNCOV
42
        }
×
UNCOV
43
        return strings.Join([]string{
×
UNCOV
44
                "session",
×
UNCOV
45
                tenantID,
×
UNCOV
46
                sessionID,
×
UNCOV
47
        }, ".")
×
48
}
49

UNCOV
50
func GetDeviceSubject(tenantID, deviceID string) string {
×
UNCOV
51
        if tenantID == "" {
×
UNCOV
52
                return strings.Join([]string{
×
UNCOV
53
                        "device",
×
UNCOV
54
                        deviceID,
×
UNCOV
55
                }, ".")
×
UNCOV
56
        }
×
UNCOV
57
        return strings.Join([]string{
×
UNCOV
58
                "device",
×
UNCOV
59
                tenantID,
×
UNCOV
60
                deviceID,
×
UNCOV
61
        }, ".")
×
62
}
63

64
// Session represents a session from a user to a device and its attributes
65
type Session struct {
66
        ID                 string      `json:"id" bson:"_id"`
67
        UserID             string      `json:"user_id" bson:"user_id"`
68
        DeviceID           string      `json:"device_id" bson:"device_id"`
69
        Types              []string    `json:"-" bson:"-"`
70
        StartTS            time.Time   `json:"start_ts" bson:"start_ts"`
71
        TenantID           string      `json:"tenant_id" bson:"tenant_id"`
72
        BytesRecordedMutex *sync.Mutex `json:"-" bson:"-"`
73
        BytesRecorded      int         `json:"bytes_transferred" bson:"bytes_transferred"`
74
}
75

UNCOV
76
func (sess Session) Subject(tenantID string) string {
×
UNCOV
77
        return GetSessionSubject(tenantID, sess.ID)
×
UNCOV
78
}
×
79

UNCOV
80
func (sess Session) Validate() error {
×
UNCOV
81
        return validation.ValidateStruct(&sess,
×
UNCOV
82
                validation.Field(&sess.ID, validation.Required),
×
UNCOV
83
                validation.Field(&sess.UserID, validation.Required),
×
UNCOV
84
                validation.Field(&sess.DeviceID, validation.Required),
×
UNCOV
85
                validation.Field(&sess.StartTS, validation.Required),
×
UNCOV
86
        )
×
UNCOV
87
}
×
88

89
// ActiveSession stores the data about an active session in memory
90
type ActiveSession struct {
91
        RemoteTerminal bool
92
}
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