Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make data limits a permanent feature #698

Merged
merged 15 commits into from
Jul 20, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Configure data limits path based on shadowbox version
  • Loading branch information
alalamav committed Jun 17, 2020
commit 654547e65608c512e2caff4b82b74e31cea885d7
26 changes: 17 additions & 9 deletions src/server_manager/web_app/shadowbox_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import * as semver from 'semver';

import * as errors from '../infrastructure/errors';
import * as server from '../model/server';

Expand Down Expand Up @@ -63,30 +65,36 @@ export class ShadowboxServer implements server.Server {
return this.apiRequest<void>('access-keys/' + accessKeyId, {method: 'DELETE'});
}

setAccessKeyDataLimit(limit: server.DataLimit): Promise<void> {
async setAccessKeyDataLimit(limit: server.DataLimit): Promise<void> {
console.info(`Setting access key data limit: ${JSON.stringify(limit)}`);
const requestOptions = {
method: 'PUT',
headers: new Headers({'Content-Type': 'application/json'}),
body: JSON.stringify({limit})
};
return this.apiRequest<void>('experimental/access-key-data-limit', requestOptions).then(() => {
this.serverConfig.accessKeyDataLimit = limit;
});
await this.apiRequest<void>(this.getAccessKeyDataLimitPath(), requestOptions);
this.serverConfig.accessKeyDataLimit = limit;
}

removeAccessKeyDataLimit(): Promise<void> {
async removeAccessKeyDataLimit(): Promise<void> {
console.info(`Removing access key data limit`);
return this.apiRequest<void>('experimental/access-key-data-limit', {method: 'DELETE'})
.then(() => {
delete this.serverConfig.accessKeyDataLimit;
});
await this.apiRequest<void>(this.getAccessKeyDataLimitPath(), {method: 'DELETE'});
delete this.serverConfig.accessKeyDataLimit;
}

getAccessKeyDataLimit(): server.DataLimit|undefined {
return this.serverConfig.accessKeyDataLimit;
}

private getAccessKeyDataLimitPath(): string {
const version = this.getVersion();
if (semver.gte(version, '1.3.0')) {
// Data limits became a permanent feature in shadowbox v1.3.0.
return 'server/access-key-data-limit';
}
return 'experimental/access-key-data-limit';
}

getDataUsage(): Promise<server.DataUsageByAccessKey> {
return this.apiRequest<server.DataUsageByAccessKey>('metrics/transfer');
}
Expand Down