Skip to content

Commit 54e45a3

Browse files
committed
impr(WKBCH-23): Add rate limit support
1 parent e8067e5 commit 54e45a3

12 files changed

Lines changed: 243 additions & 21 deletions

File tree

cmd/config.go

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,15 @@ type GlobalConfig struct {
6767
}
6868

6969
type FeatureConfig struct {
70-
Scuba ScubaFeatureConfig `yaml:"scuba"`
71-
BucketNotifications BucketNotificationsFeatureConfig `yaml:"bucket_notifications"`
70+
Scuba ScubaFeatureConfig `yaml:"scuba"`
71+
BucketNotifications BucketNotificationsFeatureConfig `yaml:"bucket_notifications"`
7272
CrossRegionReplication CrossRegionReplicationFeatureConfig `yaml:"cross_region_replication"`
73-
Utapi UtapiFeatureConfig `yaml:"utapi"`
74-
Migration MigrationFeatureConfig `yaml:"migration"`
75-
AccessLogging AccessLoggingFeatureConfig `yaml:"access_logging"`
76-
S3Frontend S3FrontendFeatureConfig `yaml:"s3_frontend"`
77-
Lifecycle LifecycleFeatureConfig `yaml:"lifecycle"`
73+
Utapi UtapiFeatureConfig `yaml:"utapi"`
74+
Migration MigrationFeatureConfig `yaml:"migration"`
75+
AccessLogging AccessLoggingFeatureConfig `yaml:"access_logging"`
76+
S3Frontend S3FrontendFeatureConfig `yaml:"s3_frontend"`
77+
Lifecycle LifecycleFeatureConfig `yaml:"lifecycle"`
78+
RateLimiting RateLimitingFeatureConfig `yaml:"rate_limiting"`
7879
}
7980

8081
type S3FrontendFeatureConfig struct {
@@ -245,6 +246,29 @@ type LifecycleFeatureConfig struct {
245246
Enabled bool `yaml:"enabled"`
246247
}
247248

249+
type RateLimitingFeatureConfig struct {
250+
Enabled bool `yaml:"enabled"`
251+
Bucket RateLimitingDefaultLimits `yaml:"bucket"`
252+
Account RateLimitingDefaultLimits `yaml:"account"`
253+
Error RateLimitingErrorConfig `yaml:"error"`
254+
}
255+
256+
type RateLimitingDefaultLimits struct {
257+
RequestsPerSecond *RateLimitingLimitConfig `yaml:"requests_per_second"`
258+
ConfigCacheTTL int `yaml:"config_cache_ttl"`
259+
}
260+
261+
type RateLimitingLimitConfig struct {
262+
Limit int `yaml:"limit"`
263+
BurstCapacity int `yaml:"burst_capacity"`
264+
}
265+
266+
type RateLimitingErrorConfig struct {
267+
StatusCode int `yaml:"status_code"`
268+
Code string `yaml:"code"`
269+
Message string `yaml:"message"`
270+
}
271+
248272
func DefaultEnvironmentConfig() EnvironmentConfig {
249273
return EnvironmentConfig{
250274
Global: GlobalConfig{
@@ -275,6 +299,20 @@ func DefaultEnvironmentConfig() EnvironmentConfig {
275299
Lifecycle: LifecycleFeatureConfig{
276300
Enabled: false,
277301
},
302+
RateLimiting: RateLimitingFeatureConfig{
303+
Enabled: false,
304+
Bucket: RateLimitingDefaultLimits{
305+
ConfigCacheTTL: 30000,
306+
},
307+
Account: RateLimitingDefaultLimits{
308+
ConfigCacheTTL: 30000,
309+
},
310+
Error: RateLimitingErrorConfig{
311+
StatusCode: 429,
312+
Code: "SlowDown",
313+
Message: "Rate limit exceeded. Please try again later.",
314+
},
315+
},
278316
},
279317
Cloudserver: CloudserverConfig{},
280318
S3Metadata: MetadataConfig{

cmd/configure.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,13 @@ func generateCloudserverConfig(cfg EnvironmentConfig, path string) error {
130130
return err
131131
}
132132

133-
return renderTemplateToFile(
134-
getTemplates(),
135-
"templates/cloudserver/locationConfig.json",
136-
cfg,
137-
filepath.Join(path, "cloudserver", "locationConfig.json"),
138-
)
133+
templates := []string{
134+
"locationConfig.json",
135+
"create-service-user.sh",
136+
"Dockerfile.setup",
137+
}
138+
139+
return renderTemplates(cfg, "templates/cloudserver", filepath.Join(path, "cloudserver"), templates)
139140
}
140141

141142
func generateBackbeatConfig(cfg EnvironmentConfig, path string) error {

cmd/util.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"strings"
1212
"text/template"
1313

14+
"github.com/Masterminds/sprig/v3"
1415
"github.com/hashicorp/go-multierror"
1516

1617
"github.com/scality/workbench"
@@ -25,7 +26,7 @@ func getTemplates() fs.FS {
2526
}
2627

2728
func templateFile(templates fs.FS, path string, data any) ([]byte, error) {
28-
tmpl, err := template.ParseFS(templates, path)
29+
tmpl, err := template.New(filepath.Base(path)).Funcs(sprig.FuncMap()).ParseFS(templates, path)
2930
if err != nil {
3031
return nil, err
3132
}
@@ -100,6 +101,10 @@ func getComposeProfiles(cfg EnvironmentConfig) []string {
100101
profiles = append(profiles, "feature-lifecycle")
101102
}
102103

104+
if cfg.Features.RateLimiting.Enabled {
105+
profiles = append(profiles, "feature-rate-limiting")
106+
}
107+
103108
return profiles
104109
}
105110

go.mod

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,25 @@ go 1.24.3
44

55
require (
66
dario.cat/mergo v1.0.2
7+
github.com/Masterminds/sprig/v3 v3.3.0
78
github.com/alecthomas/kong v1.11.0
89
github.com/hashicorp/go-multierror v1.1.1
910
github.com/rs/zerolog v1.34.0
1011
gopkg.in/yaml.v3 v3.0.1
1112
)
1213

1314
require (
15+
github.com/Masterminds/goutils v1.1.1 // indirect
16+
github.com/Masterminds/semver/v3 v3.3.0 // indirect
17+
github.com/google/uuid v1.6.0 // indirect
1418
github.com/hashicorp/errwrap v1.0.0 // indirect
19+
github.com/huandu/xstrings v1.5.0 // indirect
1520
github.com/mattn/go-colorable v0.1.13 // indirect
1621
github.com/mattn/go-isatty v0.0.19 // indirect
17-
golang.org/x/sys v0.12.0 // indirect
22+
github.com/mitchellh/copystructure v1.2.0 // indirect
23+
github.com/mitchellh/reflectwalk v1.0.2 // indirect
24+
github.com/shopspring/decimal v1.4.0 // indirect
25+
github.com/spf13/cast v1.7.0 // indirect
26+
golang.org/x/crypto v0.26.0 // indirect
27+
golang.org/x/sys v0.23.0 // indirect
1828
)

go.sum

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,72 @@
11
dario.cat/mergo v1.0.2 h1:85+piFYR1tMbRrLcDwR18y4UKJ3aH1Tbzi24VRW1TK8=
22
dario.cat/mergo v1.0.2/go.mod h1:E/hbnu0NxMFBjpMIE34DRGLWqDy0g5FuKDhCb31ngxA=
3+
github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI=
4+
github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
5+
github.com/Masterminds/semver/v3 v3.3.0 h1:B8LGeaivUe71a5qox1ICM/JLl0NqZSW5CHyL+hmvYS0=
6+
github.com/Masterminds/semver/v3 v3.3.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
7+
github.com/Masterminds/sprig/v3 v3.3.0 h1:mQh0Yrg1XPo6vjYXgtf5OtijNAKJRNcTdOOGZe3tPhs=
8+
github.com/Masterminds/sprig/v3 v3.3.0/go.mod h1:Zy1iXRYNqNLUolqCpL4uhk6SHUMAOSCzdgBfDb35Lz0=
39
github.com/alecthomas/assert/v2 v2.11.0 h1:2Q9r3ki8+JYXvGsDyBXwH3LcJ+WK5D0gc5E8vS6K3D0=
410
github.com/alecthomas/assert/v2 v2.11.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=
511
github.com/alecthomas/kong v1.11.0 h1:y++1gI7jf8O7G7l4LZo5ASFhrhJvzc+WgF/arranEmM=
612
github.com/alecthomas/kong v1.11.0/go.mod h1:p2vqieVMeTAnaC83txKtXe8FLke2X07aruPWXyMPQrU=
713
github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc=
814
github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
915
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
16+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
17+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
18+
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
19+
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
1020
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
21+
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
22+
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
23+
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
24+
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
1125
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
1226
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
1327
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
1428
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
1529
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
1630
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
31+
github.com/huandu/xstrings v1.5.0 h1:2ag3IFq9ZDANvthTwTiqSSZLjDc+BedvHPAp5tJy2TI=
32+
github.com/huandu/xstrings v1.5.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
33+
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
34+
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
35+
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
36+
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
1737
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
1838
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
1939
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
2040
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
2141
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
42+
github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw=
43+
github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s=
44+
github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
45+
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
2246
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
47+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
48+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
49+
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
50+
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
2351
github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0=
2452
github.com/rs/zerolog v1.34.0 h1:k43nTLIwcTVQAncfCw4KZ2VY6ukYoZaBPNOE8txlOeY=
2553
github.com/rs/zerolog v1.34.0/go.mod h1:bJsvje4Z08ROH4Nhs5iH600c3IkWhwp44iRc54W6wYQ=
54+
github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k=
55+
github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME=
56+
github.com/spf13/cast v1.7.0 h1:ntdiHjuueXFgm5nzDRdOS4yfT43P5Fnud6DH50rz/7w=
57+
github.com/spf13/cast v1.7.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
58+
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
59+
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
60+
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
61+
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
2662
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
2763
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
28-
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
2964
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
65+
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
66+
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
3067
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
3168
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
69+
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
70+
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
3271
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
3372
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
ARG BASE_IMAGE
2+
3+
FROM $BASE_IMAGE
4+
5+
USER root
6+
7+
RUN apt-get update && apt-get install -y jq curl
8+
9+
COPY --chmod=755 create-service-user.sh /opt/
10+
11+
CMD ["/opt/create-service-user.sh"]

templates/cloudserver/config-v7.json

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,13 @@
9898
{{ else }}
9999
"bucketNotificationDestinations": [],
100100
{{ end }}
101-
{{ if .Features.Utapi.Enabled }}
101+
{{ if or .Features.Utapi.Enabled .Features.RateLimiting.Enabled }}
102102
"localCache": {
103103
"host": "localhost",
104104
"port": 6379
105105
},
106+
{{ end }}
107+
{{ if .Features.Utapi.Enabled }}
106108
"utapi": {
107109
"host": "localhost",
108110
"port": 8100,
@@ -112,6 +114,40 @@
112114
"port": 6379
113115
}
114116
},
115-
{{ end }}
117+
{{- end }}
118+
{{- if .Features.RateLimiting.Enabled }}
119+
"rateLimiting": {
120+
"enabled": {{ .Features.RateLimiting.Enabled }},
121+
"serviceUserArn": "arn:aws:iam::000000000000:user/scality-internal/service-rate-limit-user",
122+
"nodes": 1,
123+
"bucket": {
124+
{{- if .Features.RateLimiting.Bucket.RequestsPerSecond }}
125+
"defaultConfig": {
126+
"requestsPerSecond": {
127+
"limit": {{ .Features.RateLimiting.Bucket.RequestsPerSecond.Limit }},
128+
"burstCapacity": {{ .Features.RateLimiting.Bucket.RequestsPerSecond.BurstCapacity }}
129+
}
130+
},
131+
{{- end }}
132+
"configCacheTTL": {{ .Features.RateLimiting.Bucket.ConfigCacheTTL }}
133+
},
134+
"account": {
135+
{{- if .Features.RateLimiting.Account.RequestsPerSecond }}
136+
"defaultConfig": {
137+
"requestsPerSecond": {
138+
"limit": {{ .Features.RateLimiting.Account.RequestsPerSecond.Limit }},
139+
"burstCapacity": {{ .Features.RateLimiting.Account.RequestsPerSecond.BurstCapacity }}
140+
}
141+
},
142+
{{- end }}
143+
"configCacheTTL": {{ .Features.RateLimiting.Account.ConfigCacheTTL }}
144+
},
145+
"error": {
146+
"statusCode": {{ .Features.RateLimiting.Error.StatusCode }},
147+
"code": {{ .Features.RateLimiting.Error.Code | toJson }},
148+
"message": {{ .Features.RateLimiting.Error.Message | toJson }}
149+
}
150+
},
151+
{{- end }}
116152
"testingMode": true
117153
}

templates/cloudserver/config-v9.json

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,13 @@
150150
{{ else }}
151151
"bucketNotificationDestinations": [],
152152
{{ end }}
153-
{{ if .Features.Utapi.Enabled }}
153+
{{ if or .Features.Utapi.Enabled .Features.RateLimiting.Enabled }}
154154
"localCache": {
155155
"host": "localhost",
156156
"port": 6379
157157
},
158+
{{ end }}
159+
{{ if .Features.Utapi.Enabled }}
158160
"utapi": {
159161
"host": "localhost",
160162
"port": 8100,
@@ -195,5 +197,39 @@
195197
"retryReopenDelayMS": 1000,
196198
"checkFileRotationIntervalMS": 10000
197199
},
200+
{{- if .Features.RateLimiting.Enabled }}
201+
"rateLimiting": {
202+
"enabled": {{ .Features.RateLimiting.Enabled }},
203+
"serviceUserArn": "arn:aws:iam::000000000000:user/scality-internal/service-rate-limit-user",
204+
"nodes": 1,
205+
"bucket": {
206+
{{- if .Features.RateLimiting.Bucket.RequestsPerSecond }}
207+
"defaultConfig": {
208+
"requestsPerSecond": {
209+
"limit": {{ .Features.RateLimiting.Bucket.RequestsPerSecond.Limit }},
210+
"burstCapacity": {{ .Features.RateLimiting.Bucket.RequestsPerSecond.BurstCapacity }}
211+
}
212+
},
213+
{{- end }}
214+
"configCacheTTL": {{ .Features.RateLimiting.Bucket.ConfigCacheTTL }}
215+
},
216+
"account": {
217+
{{- if .Features.RateLimiting.Account.RequestsPerSecond }}
218+
"defaultConfig": {
219+
"requestsPerSecond": {
220+
"limit": {{ .Features.RateLimiting.Account.RequestsPerSecond.Limit }},
221+
"burstCapacity": {{ .Features.RateLimiting.Account.RequestsPerSecond.BurstCapacity }}
222+
}
223+
},
224+
{{- end }}
225+
"configCacheTTL": {{ .Features.RateLimiting.Account.ConfigCacheTTL }}
226+
},
227+
"error": {
228+
"statusCode": {{ .Features.RateLimiting.Error.StatusCode }},
229+
"code": {{ .Features.RateLimiting.Error.Code | toJson }},
230+
"message": {{ .Features.RateLimiting.Error.Message | toJson }}
231+
}
232+
},
233+
{{- end }}
198234
"testingMode": true
199235
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env sh
2+
set -xe
3+
4+
MANAGEMENT_ACCESS_KEY=$(jq -r '.accessKey' /secrets/management-creds.json)
5+
MANAGEMENT_SECRET_KEY=$(jq -r '.secretKey' /secrets/management-creds.json)
6+
7+
# === Create rate-limit service user ===
8+
echo "[setup] Creating rate-limit service user..."
9+
SERVICE_CREDS_JSON=$(AWS_ACCESS_KEY_ID="$MANAGEMENT_ACCESS_KEY" \
10+
AWS_SECRET_ACCESS_KEY="$MANAGEMENT_SECRET_KEY" \
11+
AWS_REGION="us-east-1" \
12+
./bin/ensureServiceUser apply service-rate-limit-user --iam-endpoint http://127.0.0.1:8600)
13+
14+
SERVICE_ACCESS_KEY=$(echo "$SERVICE_CREDS_JSON" | jq -r '.data.AccessKeyId')
15+
SERVICE_SECRET_KEY=$(echo "$SERVICE_CREDS_JSON" | jq -r '.data.SecretAccessKey')
16+
17+
echo "[setup] rate-limit service user credentials:"
18+
echo "SERVICE_ACCESS_KEY=$SERVICE_ACCESS_KEY"
19+
echo "SERVICE_SECRET_KEY=$SERVICE_SECRET_KEY"
20+
echo
21+
22+
# === Update rate-limit-service-creds.json ===
23+
echo "[setup] Updating rate-limit-service-creds.json with service user credentials..."
24+
jq --null-input --arg ak "$SERVICE_ACCESS_KEY" --arg sk "$SERVICE_SECRET_KEY" \
25+
'{accessKey: $ak, secretKey: $sk}' > /secrets/rate-limit-service-creds.json

0 commit comments

Comments
 (0)