1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import React from 'react';
import * as Utils from 'utils/utils.jsx';
import AdminSettings from './admin_settings.jsx';
import BooleanSetting from './boolean_setting.jsx';
import {FormattedMessage} from 'react-intl';
import SettingsGroup from './settings_group.jsx';
import TextSetting from './text_setting.jsx';
export default class RateSettings extends AdminSettings {
constructor(props) {
super(props);
this.getConfigFromState = this.getConfigFromState.bind(this);
this.renderSettings = this.renderSettings.bind(this);
}
getConfigFromState(config) {
config.RateLimitSettings.Enable = this.state.enable;
config.RateLimitSettings.PerSec = this.parseIntNonZero(this.state.perSec);
config.RateLimitSettings.MaxBurst = this.parseIntNonZero(this.state.maxBurst);
config.RateLimitSettings.MemoryStoreSize = this.parseIntNonZero(this.state.memoryStoreSize);
config.RateLimitSettings.VaryByRemoteAddr = this.state.varyByRemoteAddr;
config.RateLimitSettings.VaryByHeader = this.state.varyByHeader;
return config;
}
getStateFromConfig(config) {
return {
enable: config.RateLimitSettings.Enable,
perSec: config.RateLimitSettings.PerSec,
maxBurst: config.RateLimitSettings.MaxBurst,
memoryStoreSize: config.RateLimitSettings.MemoryStoreSize,
varyByRemoteAddr: config.RateLimitSettings.VaryByRemoteAddr,
varyByHeader: config.RateLimitSettings.VaryByHeader
};
}
renderTitle() {
return (
<FormattedMessage
id='admin.rate.title'
defaultMessage='Rate Limit Settings'
/>
);
}
renderSettings() {
return (
<SettingsGroup>
<div className='banner'>
<div className='banner__content'>
<FormattedMessage
id='admin.rate.noteDescription'
defaultMessage='Changing properties in this section will require a server restart before taking effect.'
/>
</div>
</div>
<BooleanSetting
id='enable'
label={
<FormattedMessage
id='admin.rate.enableLimiterTitle'
defaultMessage='Enable Rate Limiting: '
/>
}
helpText={
<FormattedMessage
id='admin.rate.enableLimiterDescription'
defaultMessage='When true, APIs are throttled at rates specified below.'
/>
}
value={this.state.enable}
onChange={this.handleChange}
/>
<TextSetting
id='perSec'
label={
<FormattedMessage
id='admin.rate.queriesTitle'
defaultMessage='Maximum Queries per Second:'
/>
}
placeholder={Utils.localizeMessage('admin.rate.queriesExample', 'Ex "10"')}
helpText={
<FormattedMessage
id='admin.rate.queriesDescription'
defaultMessage='Throttles API at this number of requests per second.'
/>
}
value={this.state.perSec}
onChange={this.handleChange}
disabled={!this.state.enable}
/>
<TextSetting
id='maxBurst'
label={
<FormattedMessage
id='admin.rate.maxBurst'
defaultMessage='Maximum Burst Size:'
/>
}
placeholder={Utils.localizeMessage('admin.rate.maxBurstExample', 'Ex "100"')}
helpText={
<FormattedMessage
id='admin.rate.maxBurstDescription'
defaultMessage='Maximum number of requests allowed beyond the per second query limit.'
/>
}
value={this.state.maxBurst}
onChange={this.handleChange}
disabled={!this.state.enable}
/>
<TextSetting
id='memoryStoreSize'
label={
<FormattedMessage
id='admin.rate.memoryTitle'
defaultMessage='Memory Store Size:'
/>
}
placeholder={Utils.localizeMessage('admin.rate.memoryExample', 'Ex "10000"')}
helpText={
<FormattedMessage
id='admin.rate.memoryDescription'
defaultMessage='Maximum number of users sessions connected to the system as determined by "Vary rate limit by remote address" and "Vary rate limit by HTTP header".'
/>
}
value={this.state.memoryStoreSize}
onChange={this.handleChange}
disabled={!this.state.enable}
/>
<BooleanSetting
id='varyByRemoteAddr'
label={
<FormattedMessage
id='admin.rate.remoteTitle'
defaultMessage='Vary rate limit by remote address: '
/>
}
helpText={
<FormattedMessage
id='admin.rate.remoteDescription'
defaultMessage='When true, rate limit API access by IP address.'
/>
}
value={this.state.varyByRemoteAddr}
onChange={this.handleChange}
disabled={!this.state.enable}
/>
<TextSetting
id='varyByHeader'
label={
<FormattedMessage
id='admin.rate.httpHeaderTitle'
defaultMessage='Vary rate limit by HTTP header:'
/>
}
placeholder={Utils.localizeMessage('admin.rate.httpHeaderExample', 'Ex "X-Real-IP", "X-Forwarded-For"')}
helpText={
<FormattedMessage
id='admin.rate.httpHeaderDescription'
defaultMessage='When filled in, vary rate limiting by HTTP header field specified (e.g. when configuring NGINX set to "X-Real-IP", when configuring AmazonELB set to "X-Forwarded-For").'
/>
}
value={this.state.varyByHeader}
onChange={this.handleChange}
disabled={!this.state.enable || this.state.varyByRemoteAddr}
/>
</SettingsGroup>
);
}
}
|