2017-03-22 00:58:33 +08:00
|
|
|
|
|
|
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_service_get_rate_limit(
|
|
|
|
username TEXT,
|
|
|
|
orgname TEXT,
|
|
|
|
service TEXT)
|
|
|
|
RETURNS JSON AS $$
|
|
|
|
import json
|
|
|
|
from cartodb_services.config import ServiceConfiguration, RateLimitsConfigBuilder
|
|
|
|
|
|
|
|
import cartodb_services
|
|
|
|
cartodb_services.init(plpy, GD)
|
|
|
|
|
|
|
|
service_config = ServiceConfiguration(service, username, orgname)
|
2017-03-28 16:53:16 +08:00
|
|
|
rate_limit_config = RateLimitsConfigBuilder(service_config.server, service_config.user, service_config.org, service=service, username=username, orgname=orgname).get()
|
2017-03-22 00:58:33 +08:00
|
|
|
if rate_limit_config.is_limited():
|
|
|
|
return json.dumps({'limit': rate_limit_config.limit, 'period': rate_limit_config.period})
|
|
|
|
else:
|
|
|
|
return None
|
2020-02-24 23:12:27 +08:00
|
|
|
$$ LANGUAGE @@plpythonu@@ STABLE PARALLEL RESTRICTED;
|
2017-03-22 00:58:33 +08:00
|
|
|
|
|
|
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_service_set_user_rate_limit(
|
|
|
|
username TEXT,
|
|
|
|
orgname TEXT,
|
|
|
|
service TEXT,
|
|
|
|
rate_limit_json JSON)
|
|
|
|
RETURNS VOID AS $$
|
|
|
|
import json
|
|
|
|
from cartodb_services.config import RateLimitsConfig, RateLimitsConfigSetter
|
|
|
|
|
|
|
|
import cartodb_services
|
|
|
|
cartodb_services.init(plpy, GD)
|
|
|
|
|
|
|
|
config_setter = RateLimitsConfigSetter(service=service, username=username, orgname=orgname)
|
|
|
|
if rate_limit_json:
|
|
|
|
rate_limit = json.loads(rate_limit_json)
|
|
|
|
limit = rate_limit.get('limit', None)
|
|
|
|
period = rate_limit.get('period', None)
|
|
|
|
else:
|
|
|
|
limit = None
|
|
|
|
period = None
|
|
|
|
config = RateLimitsConfig(service=service, username=username, limit=limit, period=period)
|
|
|
|
config_setter.set_user_rate_limits(config)
|
2020-02-24 23:12:27 +08:00
|
|
|
$$ LANGUAGE @@plpythonu@@ VOLATILE PARALLEL UNSAFE;
|
2017-03-22 00:58:33 +08:00
|
|
|
|
|
|
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_service_set_org_rate_limit(
|
|
|
|
username TEXT,
|
|
|
|
orgname TEXT,
|
|
|
|
service TEXT,
|
|
|
|
rate_limit_json JSON)
|
|
|
|
RETURNS VOID AS $$
|
|
|
|
import json
|
|
|
|
from cartodb_services.config import RateLimitsConfig, RateLimitsConfigSetter
|
|
|
|
|
|
|
|
import cartodb_services
|
|
|
|
cartodb_services.init(plpy, GD)
|
|
|
|
|
|
|
|
config_setter = RateLimitsConfigSetter(service=service, username=username, orgname=orgname)
|
|
|
|
if rate_limit_json:
|
|
|
|
rate_limit = json.loads(rate_limit_json)
|
|
|
|
limit = rate_limit.get('limit', None)
|
|
|
|
period = rate_limit.get('period', None)
|
|
|
|
else:
|
|
|
|
limit = None
|
|
|
|
period = None
|
|
|
|
config = RateLimitsConfig(service=service, username=username, limit=limit, period=period)
|
|
|
|
config_setter.set_org_rate_limits(config)
|
2020-02-24 23:12:27 +08:00
|
|
|
$$ LANGUAGE @@plpythonu@@ STABLE PARALLEL RESTRICTED;
|
2017-03-22 00:58:33 +08:00
|
|
|
|
|
|
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_service_set_server_rate_limit(
|
|
|
|
username TEXT,
|
|
|
|
orgname TEXT,
|
|
|
|
service TEXT,
|
|
|
|
rate_limit_json JSON)
|
|
|
|
RETURNS VOID AS $$
|
|
|
|
import json
|
|
|
|
from cartodb_services.config import RateLimitsConfig, RateLimitsConfigSetter
|
|
|
|
|
|
|
|
import cartodb_services
|
|
|
|
cartodb_services.init(plpy, GD)
|
|
|
|
|
|
|
|
config_setter = RateLimitsConfigSetter(service=service, username=username, orgname=orgname)
|
|
|
|
if rate_limit_json:
|
|
|
|
rate_limit = json.loads(rate_limit_json)
|
|
|
|
limit = rate_limit.get('limit', None)
|
|
|
|
period = rate_limit.get('period', None)
|
|
|
|
else:
|
|
|
|
limit = None
|
|
|
|
period = None
|
|
|
|
config = RateLimitsConfig(service=service, username=username, limit=limit, period=period)
|
|
|
|
config_setter.set_server_rate_limits(config)
|
2020-02-24 23:12:27 +08:00
|
|
|
$$ LANGUAGE @@plpythonu@@ VOLATILE PARALLEL UNSAFE;
|