Allow creation of api keys scoped to functions

This commit is contained in:
Peter Stockings
2025-11-20 19:44:00 +11:00
parent 7241c4803f
commit f0d63bed22
2 changed files with 20 additions and 4 deletions

View File

@@ -18,14 +18,18 @@ def api_keys():
if isinstance(key['scopes'], str):
key['scopes'] = json.loads(key['scopes'])
# Fetch user's functions for scoping
functions = db.get_http_functions_for_user(user_id)
if htmx:
return render_block(
environment,
"dashboard/settings/api_keys.html",
"page",
api_keys=api_keys
api_keys=api_keys,
functions=functions
)
return render_template("dashboard/settings/api_keys.html", api_keys=api_keys)
return render_template("dashboard/settings/api_keys.html", api_keys=api_keys, functions=functions)
@settings.route("/api-keys", methods=["POST"])
@login_required

View File

@@ -96,9 +96,21 @@
class="rounded border-gray-300 text-blue-600 focus:ring-blue-500">
<span class="ml-2 text-sm text-gray-600 dark:text-gray-400">Full Access (*)</span>
</label>
<!-- Future: Add function specific scopes here -->
<div class="mt-3 border-t pt-3">
<p class="text-xs font-medium text-gray-500 mb-2">Or limit to specific functions:</p>
<div class="max-h-40 overflow-y-auto space-y-2 pl-1">
{% for function in functions %}
<label class="flex items-center">
<input type="checkbox" name="scopes" value="function:{{ function.id }}"
class="rounded border-gray-300 text-blue-600 focus:ring-blue-500">
<span class="ml-2 text-sm text-gray-600 dark:text-gray-400">{{ function.name }}</span>
</label>
{% endfor %}
</div>
</div>
</div>
<p class="mt-1 text-xs text-gray-500">Currently only full access is supported via UI.</p>
<p class="mt-1 text-xs text-gray-500">Select "Full Access" or specific functions.</p>
</div>
<div class="flex justify-end space-x-3">