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

sapcc / keppel / 15215267305

23 May 2025 04:49PM UTC coverage: 80.957% (+0.05%) from 80.908%
15215267305

Pull #538

github

SuperSandro2000
Use test helpers instead of raw sql
Pull Request #538: Tag policy

195 of 222 new or added lines in 19 files covered. (87.84%)

81 existing lines in 9 files now uncovered.

7610 of 9400 relevant lines covered (80.96%)

164.55 hits per line

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

75.0
/internal/api/utils.go
1
// SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company
2
// SPDX-License-Identifier: Apache-2.0
3

4
package api
5

6
import (
7
        "net/http"
8
        "strconv"
9
        "time"
10

11
        "github.com/sapcc/go-bits/httpext"
12
        "github.com/sapcc/go-bits/sqlext"
13

14
        "github.com/sapcc/keppel/internal/auth"
15
        "github.com/sapcc/keppel/internal/keppel"
16
        "github.com/sapcc/keppel/internal/models"
17
)
18

19
func CheckRateLimit(r *http.Request, rle *keppel.RateLimitEngine, account models.ReducedAccount, authz *auth.Authorization, action keppel.RateLimitedAction, amount uint64) error {
1,511✔
20
        // rate-limiting is optional
1,511✔
21
        if rle == nil {
2,948✔
22
                return nil
1,437✔
23
        }
1,437✔
24

25
        // cluster-internal traffic is exempt from rate-limits (if the request is
26
        // caused by a user API request, the rate-limit has been checked already
27
        // before the cluster-internal request was sent)
28
        userType := authz.UserIdentity.UserType()
74✔
29
        if userType == keppel.PeerUser || userType == keppel.TrivyUser {
74✔
UNCOV
30
                return nil
×
31
        }
×
32

33
        result, err := rle.RateLimitAllows(r.Context(), httpext.GetRequesterIPFor(r), account, action, amount)
74✔
34
        if err != nil {
74✔
UNCOV
35
                return err
×
36
        }
×
37
        if result.Allowed <= 0 {
102✔
38
                retryAfterStr := strconv.FormatUint(keppel.AtLeastZero(int64(result.RetryAfter/time.Second)), 10)
28✔
39
                return keppel.ErrTooManyRequests.With("").WithHeader("Retry-After", retryAfterStr)
28✔
40
        }
28✔
41

42
        return nil
46✔
43
}
44

45
var getTagPolicyByAccountNameQuery = sqlext.SimplifyWhitespace(`
46
        SELECT tag_policies_json FROM accounts WHERE name = $1
47
`)
48

49
func GetTagPolicies(db *keppel.DB, account models.ReducedAccount) ([]keppel.TagPolicy, error) {
292✔
50
        tagPoliciesStr, err := db.SelectStr(getTagPolicyByAccountNameQuery, account.Name)
292✔
51
        if err != nil {
292✔
NEW
52
                return nil, err
×
NEW
53
        }
×
54

55
        return keppel.ParseTagPolicies(tagPoliciesStr)
292✔
56
}
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

© 2026 Coveralls, Inc