Skip to content

Commit 1fa2668

Browse files
authored
Merge pull request #1667 from apinf/feature/rate-limiting2
Feature/rate limiting2
2 parents 1b2b409 + c524f0a commit 1fa2668

File tree

4 files changed

+94
-3
lines changed

4 files changed

+94
-3
lines changed

core/lib/i18n/en.i18n.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,31 @@
401401
"settings": {
402402
"disable_api_key": {
403403
"label": "Disable API key requirement"
404+
},
405+
"rate_limit_mode": {
406+
"label": "Rate limit mode",
407+
"options": {
408+
"custom": "Custom rate limits",
409+
"unlimited": "Unlimited requests"
410+
}
411+
},
412+
"rate_limit": {
413+
"duration": {
414+
"label": "Duration (ms)"
415+
},
416+
"limit_by": {
417+
"label": "Limit by",
418+
"options": {
419+
"apiKey": "API Key",
420+
"ip": "IP Address"
421+
}
422+
},
423+
"limit": {
424+
"label": "Number of requests"
425+
},
426+
"response_headers": {
427+
"label": "Show rate limit in response headers"
428+
}
404429
}
405430
}
406431
}

proxy_backends/client/form/form.html

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,35 @@
129129
<h3>
130130
{{_ "proxyBackendForm_advancedSettings_title" }}
131131
</h3>
132-
133132
<!-- field input -->
134133
{{> afQuickField
135134
name="apiUmbrella.settings.disable_api_key"
136135
type="boolean-checkbox"
137136
}}
138-
139137
<!-- help text -->
140138
<p class="help-block">
141139
{{_ "proxyBackendForm_disableApiKey_helpText" }}
142140
</p>
141+
142+
<!-- Rate limiting -->
143+
<div class="form-group" id="rate-limiting">
144+
<div class="col-md-3" id="rate-limit-mode">
145+
{{> afQuickField
146+
name="apiUmbrella.settings.rate_limit_mode"
147+
firstOption=false
148+
}}
149+
</div>
150+
{{#if afFieldValueIs
151+
name="apiUmbrella.settings.rate_limit_mode"
152+
value="custom"
153+
}}
154+
<div class="col-md-12" id="rate-limits">
155+
{{> afQuickField
156+
name="apiUmbrella.settings.rate_limits"
157+
}}
158+
</div>
159+
{{/if }}
160+
</div>
143161
</div>
144162

145163
<div id="proxy-form-buttons" class="btn-group pull-left">

proxy_backends/client/form/form.less

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@
2020
}
2121
}
2222

23+
#rate-limiting {
24+
margin: 1em;
25+
margin-left: 0em;
26+
}
27+
28+
#rate-limit-mode {
29+
margin-bottom: 1em;
30+
}
31+
2332
#save-proxy-button {
2433
margin-top: 1em;
2534
}

proxy_backends/collection/apiUmbrellaSchema.js

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,52 @@ import { SimpleSchema } from 'meteor/aldeed:simple-schema';
22
// Utility import
33
import { proxyBasePathRegEx, apiBasePathRegEx } from './regex';
44

5+
const RateLimitSchema = new SimpleSchema({
6+
duration: {
7+
type: Number,
8+
optional: true,
9+
},
10+
limit_by: {
11+
type: String,
12+
optional: true,
13+
allowedValues: [
14+
'apiKey',
15+
'ip',
16+
],
17+
},
18+
limit: {
19+
type: Number,
20+
optional: true,
21+
},
22+
response_headers: {
23+
type: Boolean,
24+
optional: true,
25+
defaultValue: false,
26+
},
27+
});
28+
29+
// Internationalize Rate limit schema texts
30+
RateLimitSchema.i18n('schemas.ProxyBackends.apiUmbrella.settings.rate_limit');
531

632
const SettingsSchema = new SimpleSchema({
7-
'disable_api_key': {
33+
disable_api_key: {
834
type: Boolean,
935
optional: true,
1036
defaultValue: false,
1137
},
38+
rate_limit_mode: {
39+
type: String,
40+
optional: false,
41+
allowedValues: [
42+
'custom',
43+
'unlimited',
44+
],
45+
defaultValue: 'unlimited',
46+
},
47+
rate_limits: {
48+
type: [RateLimitSchema],
49+
optional: true,
50+
},
1251
});
1352

1453
// Internationalize settings schema texts

0 commit comments

Comments
 (0)