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

mendersoftware / mender-server / 1833359013

23 May 2025 01:25PM UTC coverage: 66.318% (+0.5%) from 65.861%
1833359013

Pull #674

gitlab-ci

mzedel
fix(gui): prevented device tag editor to be shown when no tags exist

- this is to reduce confusion about tags defined async to the current session not being visible

Ticket: ME-528
Signed-off-by: Manuel Zedel <manuel.zedel@northern.tech>
Pull Request #674: ME-529, ME-528 - adjustments to device tag editing

29554 of 44564 relevant lines covered (66.32%)

1.45 hits per line

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

95.65
/backend/pkg/store/utils.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
package store
15

16
import (
17
        "context"
18
        "strings"
19

20
        "github.com/mendersoftware/mender-server/pkg/identity"
21
)
22

23
// DbFromContext generates database name using tenant field from identity extracted
24
// from context and original database name
25
func DbFromContext(ctx context.Context, origDbName string) string {
6✔
26
        identity := identity.FromContext(ctx)
6✔
27
        tenant := ""
6✔
28
        if identity != nil {
11✔
29
                tenant = identity.Tenant
5✔
30
        }
5✔
31

32
        return DbNameForTenant(tenant, origDbName)
6✔
33
}
34

35
type TenantDbMatchFunc func(name string) bool
36

37
// IsTenantDb returns a function of `TenantDbMatchFunc` that can be used for
38
// checking if database has a tenant DB name format
39
func IsTenantDb(baseDb string) TenantDbMatchFunc {
4✔
40
        prefix := baseDb + "-"
4✔
41
        return func(name string) bool {
8✔
42
                return strings.HasPrefix(name, prefix)
4✔
43
        }
4✔
44
}
45

46
// TenantFromDbName attempts to extract tenant ID from provided tenant DB name.
47
// Returns extracted tenant ID or an empty string.
48
func TenantFromDbName(dbName string, baseDb string) string {
5✔
49
        noBase := strings.TrimPrefix(dbName, baseDb+"-")
5✔
50
        if noBase == dbName {
10✔
51
                return ""
5✔
52
        }
5✔
53
        return noBase
×
54
}
55

56
// DbNameForTenant composes tenant's db name.
57
func DbNameForTenant(tenantId string, baseDb string) string {
6✔
58
        if tenantId == "" {
12✔
59
                return baseDb
6✔
60
        }
6✔
61
        return baseDb + "-" + tenantId
4✔
62
}
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