Skip to content

Commit 5f10a42

Browse files
feature/Rate Limiting endpoint tweaks
1 parent 0a7f5b2 commit 5f10a42

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

apimanager/consumers/templates/consumers/detail.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ <h4 class="panel-title">{% trans "Existing Rate Limits" %}</h4>
115115
<table class="table table-striped table-hover">
116116
<thead>
117117
<tr>
118+
<th>{% trans "Rate Limiting ID" %}</th>
118119
<th>{% trans "From Date" %}</th>
119120
<th>{% trans "To Date" %}</th>
120121
<th>{% trans "Per Second" %}</th>
@@ -131,6 +132,7 @@ <h4 class="panel-title">{% trans "Existing Rate Limits" %}</h4>
131132
<tbody>
132133
{% for limit in call_limits.limits %}
133134
<tr>
135+
<td><code>{{ limit.rate_limiting_id|default:"N/A" }}</code></td>
134136
<td>{{ limit.from_date|parse_iso_date:"Y-m-d H:i" }}</td>
135137
<td>{{ limit.to_date|parse_iso_date:"Y-m-d H:i" }}</td>
136138
<td>{{ limit.per_second_call_limit|default:"-1" }}</td>

apimanager/consumers/views.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def get_form(self, *args, **kwargs):
127127
api = API(self.request.session.get("obp"))
128128
try:
129129
call_limits_urlpath = (
130-
"/management/consumers/{}/consumer/call-limits".format(
130+
"/management/consumers/{}/consumer/rate-limits".format(
131131
self.kwargs["consumer_id"]
132132
)
133133
)
@@ -239,7 +239,7 @@ def format_datetime_utc(dt_str):
239239
}
240240

241241
# Use v6.0.0 API for creating rate limits
242-
urlpath = "/management/consumers/{}/consumer/call-limits".format(
242+
urlpath = "/management/consumers/{}/consumer/rate-limits".format(
243243
consumer_id
244244
)
245245
response = self.api.post(
@@ -262,9 +262,16 @@ def format_datetime_utc(dt_str):
262262
return HttpResponseRedirect(request.path)
263263

264264
def update_rate_limit(self, request):
265-
"""Update existing rate limit using v5.1.0 PUT API"""
265+
"""Update existing rate limit using v6.0.0 PUT API"""
266266
try:
267267
consumer_id = self.kwargs["consumer_id"]
268+
rate_limiting_id = request.POST.get("rate_limit_id")
269+
270+
if not rate_limiting_id:
271+
messages.error(request, "Rate limiting ID is required for update.")
272+
return JsonResponse(
273+
{"success": False, "error": "Missing rate limiting ID"}
274+
)
268275

269276
# Helper function to format datetime to UTC
270277
def format_datetime_utc(dt_str):
@@ -297,12 +304,12 @@ def format_datetime_utc(dt_str):
297304
),
298305
}
299306

300-
# Use v5.1.0 API for updating rate limits
301-
urlpath = "/management/consumers/{}/consumer/call-limits".format(
302-
consumer_id
307+
# Use v6.0.0 API for updating rate limits with rate_limiting_id
308+
urlpath = "/management/consumers/{}/consumer/rate-limits/{}".format(
309+
consumer_id, rate_limiting_id
303310
)
304311
response = self.api.put(
305-
urlpath, payload, version=settings.API_VERSION["v510"]
312+
urlpath, payload, version=settings.API_VERSION["v600"]
306313
)
307314

308315
if "code" in response and response["code"] >= 400:
@@ -333,7 +340,7 @@ def delete_rate_limit(self, request):
333340
)
334341

335342
# Use v6.0.0 API for deleting rate limits
336-
urlpath = "/management/consumers/{}/consumer/call-limits/{}".format(
343+
urlpath = "/management/consumers/{}/consumer/rate-limits/{}".format(
337344
consumer_id, rate_limiting_id
338345
)
339346
response = self.api.delete(urlpath, version=settings.API_VERSION["v600"])
@@ -358,7 +365,7 @@ def form_valid_legacy(self, request, form):
358365
try:
359366
data = form.cleaned_data
360367

361-
urlpath = "/management/consumers/{}/consumer/call-limits".format(
368+
urlpath = "/management/consumers/{}/consumer/rate-limits".format(
362369
data["consumer_id"]
363370
)
364371

@@ -428,7 +435,7 @@ def get_usage_data_ajax(self):
428435
api = API(self.request.session.get("obp"))
429436
try:
430437
call_limits_urlpath = (
431-
"/management/consumers/{}/consumer/call-limits".format(
438+
"/management/consumers/{}/consumer/rate-limits".format(
432439
self.kwargs["consumer_id"]
433440
)
434441
)
@@ -462,7 +469,7 @@ def get_context_data(self, **kwargs):
462469

463470
# Get call limits using the correct API endpoint
464471
call_limits_urlpath = (
465-
"/management/consumers/{}/consumer/call-limits".format(
472+
"/management/consumers/{}/consumer/rate-limits".format(
466473
self.kwargs["consumer_id"]
467474
)
468475
)
@@ -545,7 +552,7 @@ def get(self, request, *args, **kwargs):
545552
api = API(self.request.session.get("obp"))
546553
try:
547554
call_limits_urlpath = (
548-
"/management/consumers/{}/consumer/call-limits".format(
555+
"/management/consumers/{}/consumer/rate-limits".format(
549556
self.kwargs["consumer_id"]
550557
)
551558
)

0 commit comments

Comments
 (0)