detached 101f297

feat(boundaries): add RateLimiter output port interface

commit
101f2974ad707bc56a30b4960d311982248a75fc
author
bnema · · 2026-01-18 02:14 UTC
parent
2f7df3b
signature
GPG VerifiedCD88F9E564E0102646FB6077A1A07C7C7C3E349D · arch-gpg Verified for the committer email
3 files · +174 -0
M .mockery.yaml +1 -0
@@ -21,6 +21,7 @@ packages:
2121 ContainerLogWriter:
2222 TokenStore:
2323 DomainSecretStore:
24+ RateLimiter:
2425 gordon/internal/boundaries/in:
2526 interfaces:
2627 ContainerService:
@@ -21,6 +21,7 @@ packages:
21 ContainerLogWriter:21 ContainerLogWriter:
22 TokenStore:22 TokenStore:
23 DomainSecretStore:23 DomainSecretStore:
24+ RateLimiter:
24 gordon/internal/boundaries/in:25 gordon/internal/boundaries/in:
25 interfaces:26 interfaces:
26 ContainerService:27 ContainerService:
A internal/boundaries/out/mocks/mock_rate_limiter.go +158 -0
@@ -0,0 +1,158 @@
1+// Code generated by mockery; DO NOT EDIT.
2+// github.com/vektra/mockery
3+// template: testify
4+
5+package mocks
6+
7+import (
8+ "context"
9+
10+ mock "github.com/stretchr/testify/mock"
11+)
12+
13+// NewMockRateLimiter creates a new instance of MockRateLimiter. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
14+// The first argument is typically a *testing.T value.
15+func NewMockRateLimiter(t interface {
16+ mock.TestingT
17+ Cleanup(func())
18+}) *MockRateLimiter {
19+ mock := &MockRateLimiter{}
20+ mock.Mock.Test(t)
21+
22+ t.Cleanup(func() { mock.AssertExpectations(t) })
23+
24+ return mock
25+}
26+
27+// MockRateLimiter is an autogenerated mock type for the RateLimiter type
28+type MockRateLimiter struct {
29+ mock.Mock
30+}
31+
32+type MockRateLimiter_Expecter struct {
33+ mock *mock.Mock
34+}
35+
36+func (_m *MockRateLimiter) EXPECT() *MockRateLimiter_Expecter {
37+ return &MockRateLimiter_Expecter{mock: &_m.Mock}
38+}
39+
40+// Allow provides a mock function for the type MockRateLimiter
41+func (_mock *MockRateLimiter) Allow(ctx context.Context, key string) bool {
42+ ret := _mock.Called(ctx, key)
43+
44+ if len(ret) == 0 {
45+ panic("no return value specified for Allow")
46+ }
47+
48+ var r0 bool
49+ if returnFunc, ok := ret.Get(0).(func(context.Context, string) bool); ok {
50+ r0 = returnFunc(ctx, key)
51+ } else {
52+ r0 = ret.Get(0).(bool)
53+ }
54+ return r0
55+}
56+
57+// MockRateLimiter_Allow_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Allow'
58+type MockRateLimiter_Allow_Call struct {
59+ *mock.Call
60+}
61+
62+// Allow is a helper method to define mock.On call
63+// - ctx context.Context
64+// - key string
65+func (_e *MockRateLimiter_Expecter) Allow(ctx interface{}, key interface{}) *MockRateLimiter_Allow_Call {
66+ return &MockRateLimiter_Allow_Call{Call: _e.mock.On("Allow", ctx, key)}
67+}
68+
69+func (_c *MockRateLimiter_Allow_Call) Run(run func(ctx context.Context, key string)) *MockRateLimiter_Allow_Call {
70+ _c.Call.Run(func(args mock.Arguments) {
71+ var arg0 context.Context
72+ if args[0] != nil {
73+ arg0 = args[0].(context.Context)
74+ }
75+ var arg1 string
76+ if args[1] != nil {
77+ arg1 = args[1].(string)
78+ }
79+ run(
80+ arg0,
81+ arg1,
82+ )
83+ })
84+ return _c
85+}
86+
87+func (_c *MockRateLimiter_Allow_Call) Return(b bool) *MockRateLimiter_Allow_Call {
88+ _c.Call.Return(b)
89+ return _c
90+}
91+
92+func (_c *MockRateLimiter_Allow_Call) RunAndReturn(run func(ctx context.Context, key string) bool) *MockRateLimiter_Allow_Call {
93+ _c.Call.Return(run)
94+ return _c
95+}
96+
97+// AllowN provides a mock function for the type MockRateLimiter
98+func (_mock *MockRateLimiter) AllowN(ctx context.Context, key string, n int) bool {
99+ ret := _mock.Called(ctx, key, n)
100+
101+ if len(ret) == 0 {
102+ panic("no return value specified for AllowN")
103+ }
104+
105+ var r0 bool
106+ if returnFunc, ok := ret.Get(0).(func(context.Context, string, int) bool); ok {
107+ r0 = returnFunc(ctx, key, n)
108+ } else {
109+ r0 = ret.Get(0).(bool)
110+ }
111+ return r0
112+}
113+
114+// MockRateLimiter_AllowN_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllowN'
115+type MockRateLimiter_AllowN_Call struct {
116+ *mock.Call
117+}
118+
119+// AllowN is a helper method to define mock.On call
120+// - ctx context.Context
121+// - key string
122+// - n int
123+func (_e *MockRateLimiter_Expecter) AllowN(ctx interface{}, key interface{}, n interface{}) *MockRateLimiter_AllowN_Call {
124+ return &MockRateLimiter_AllowN_Call{Call: _e.mock.On("AllowN", ctx, key, n)}
125+}
126+
127+func (_c *MockRateLimiter_AllowN_Call) Run(run func(ctx context.Context, key string, n int)) *MockRateLimiter_AllowN_Call {
128+ _c.Call.Run(func(args mock.Arguments) {
129+ var arg0 context.Context
130+ if args[0] != nil {
131+ arg0 = args[0].(context.Context)
132+ }
133+ var arg1 string
134+ if args[1] != nil {
135+ arg1 = args[1].(string)
136+ }
137+ var arg2 int
138+ if args[2] != nil {
139+ arg2 = args[2].(int)
140+ }
141+ run(
142+ arg0,
143+ arg1,
144+ arg2,
145+ )
146+ })
147+ return _c
148+}
149+
150+func (_c *MockRateLimiter_AllowN_Call) Return(b bool) *MockRateLimiter_AllowN_Call {
151+ _c.Call.Return(b)
152+ return _c
153+}
154+
155+func (_c *MockRateLimiter_AllowN_Call) RunAndReturn(run func(ctx context.Context, key string, n int) bool) *MockRateLimiter_AllowN_Call {
156+ _c.Call.Return(run)
157+ return _c
158+}
@@ -0,0 +1,158 @@
1+// Code generated by mockery; DO NOT EDIT.
2+// github.com/vektra/mockery
3+// template: testify
4+
5+package mocks
6+
7+import (
8+ "context"
9+
10+ mock "github.com/stretchr/testify/mock"
11+)
12+
13+// NewMockRateLimiter creates a new instance of MockRateLimiter. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
14+// The first argument is typically a *testing.T value.
15+func NewMockRateLimiter(t interface {
16+ mock.TestingT
17+ Cleanup(func())
18+}) *MockRateLimiter {
19+ mock := &MockRateLimiter{}
20+ mock.Mock.Test(t)
21+
22+ t.Cleanup(func() { mock.AssertExpectations(t) })
23+
24+ return mock
25+}
26+
27+// MockRateLimiter is an autogenerated mock type for the RateLimiter type
28+type MockRateLimiter struct {
29+ mock.Mock
30+}
31+
32+type MockRateLimiter_Expecter struct {
33+ mock *mock.Mock
34+}
35+
36+func (_m *MockRateLimiter) EXPECT() *MockRateLimiter_Expecter {
37+ return &MockRateLimiter_Expecter{mock: &_m.Mock}
38+}
39+
40+// Allow provides a mock function for the type MockRateLimiter
41+func (_mock *MockRateLimiter) Allow(ctx context.Context, key string) bool {
42+ ret := _mock.Called(ctx, key)
43+
44+ if len(ret) == 0 {
45+ panic("no return value specified for Allow")
46+ }
47+
48+ var r0 bool
49+ if returnFunc, ok := ret.Get(0).(func(context.Context, string) bool); ok {
50+ r0 = returnFunc(ctx, key)
51+ } else {
52+ r0 = ret.Get(0).(bool)
53+ }
54+ return r0
55+}
56+
57+// MockRateLimiter_Allow_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Allow'
58+type MockRateLimiter_Allow_Call struct {
59+ *mock.Call
60+}
61+
62+// Allow is a helper method to define mock.On call
63+// - ctx context.Context
64+// - key string
65+func (_e *MockRateLimiter_Expecter) Allow(ctx interface{}, key interface{}) *MockRateLimiter_Allow_Call {
66+ return &MockRateLimiter_Allow_Call{Call: _e.mock.On("Allow", ctx, key)}
67+}
68+
69+func (_c *MockRateLimiter_Allow_Call) Run(run func(ctx context.Context, key string)) *MockRateLimiter_Allow_Call {
70+ _c.Call.Run(func(args mock.Arguments) {
71+ var arg0 context.Context
72+ if args[0] != nil {
73+ arg0 = args[0].(context.Context)
74+ }
75+ var arg1 string
76+ if args[1] != nil {
77+ arg1 = args[1].(string)
78+ }
79+ run(
80+ arg0,
81+ arg1,
82+ )
83+ })
84+ return _c
85+}
86+
87+func (_c *MockRateLimiter_Allow_Call) Return(b bool) *MockRateLimiter_Allow_Call {
88+ _c.Call.Return(b)
89+ return _c
90+}
91+
92+func (_c *MockRateLimiter_Allow_Call) RunAndReturn(run func(ctx context.Context, key string) bool) *MockRateLimiter_Allow_Call {
93+ _c.Call.Return(run)
94+ return _c
95+}
96+
97+// AllowN provides a mock function for the type MockRateLimiter
98+func (_mock *MockRateLimiter) AllowN(ctx context.Context, key string, n int) bool {
99+ ret := _mock.Called(ctx, key, n)
100+
101+ if len(ret) == 0 {
102+ panic("no return value specified for AllowN")
103+ }
104+
105+ var r0 bool
106+ if returnFunc, ok := ret.Get(0).(func(context.Context, string, int) bool); ok {
107+ r0 = returnFunc(ctx, key, n)
108+ } else {
109+ r0 = ret.Get(0).(bool)
110+ }
111+ return r0
112+}
113+
114+// MockRateLimiter_AllowN_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllowN'
115+type MockRateLimiter_AllowN_Call struct {
116+ *mock.Call
117+}
118+
119+// AllowN is a helper method to define mock.On call
120+// - ctx context.Context
121+// - key string
122+// - n int
123+func (_e *MockRateLimiter_Expecter) AllowN(ctx interface{}, key interface{}, n interface{}) *MockRateLimiter_AllowN_Call {
124+ return &MockRateLimiter_AllowN_Call{Call: _e.mock.On("AllowN", ctx, key, n)}
125+}
126+
127+func (_c *MockRateLimiter_AllowN_Call) Run(run func(ctx context.Context, key string, n int)) *MockRateLimiter_AllowN_Call {
128+ _c.Call.Run(func(args mock.Arguments) {
129+ var arg0 context.Context
130+ if args[0] != nil {
131+ arg0 = args[0].(context.Context)
132+ }
133+ var arg1 string
134+ if args[1] != nil {
135+ arg1 = args[1].(string)
136+ }
137+ var arg2 int
138+ if args[2] != nil {
139+ arg2 = args[2].(int)
140+ }
141+ run(
142+ arg0,
143+ arg1,
144+ arg2,
145+ )
146+ })
147+ return _c
148+}
149+
150+func (_c *MockRateLimiter_AllowN_Call) Return(b bool) *MockRateLimiter_AllowN_Call {
151+ _c.Call.Return(b)
152+ return _c
153+}
154+
155+func (_c *MockRateLimiter_AllowN_Call) RunAndReturn(run func(ctx context.Context, key string, n int) bool) *MockRateLimiter_AllowN_Call {
156+ _c.Call.Return(run)
157+ return _c
158+}
A internal/boundaries/out/ratelimiter.go +15 -0
@@ -0,0 +1,15 @@
1+package out
2+
3+import "context"
4+
5+// RateLimiter defines the contract for rate limiting operations.
6+// Implementations may use different backends (memory, Redis).
7+type RateLimiter interface {
8+ // Allow checks if a request identified by key is allowed.
9+ // Returns true if allowed, false if rate limited.
10+ // Key is typically "global" or "ip:<address>".
11+ Allow(ctx context.Context, key string) bool
12+
13+ // AllowN checks if n requests identified by key are allowed.
14+ AllowN(ctx context.Context, key string, n int) bool
15+}
@@ -0,0 +1,15 @@
1+package out
2+
3+import "context"
4+
5+// RateLimiter defines the contract for rate limiting operations.
6+// Implementations may use different backends (memory, Redis).
7+type RateLimiter interface {
8+ // Allow checks if a request identified by key is allowed.
9+ // Returns true if allowed, false if rate limited.
10+ // Key is typically "global" or "ip:<address>".
11+ Allow(ctx context.Context, key string) bool
12+
13+ // AllowN checks if n requests identified by key are allowed.
14+ AllowN(ctx context.Context, key string, n int) bool
15+}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 7

Tags 106

↑↓ moveenter openesc close