Initial setup for adding support for api key based auth
This commit is contained in:
38
db.py
38
db.py
@@ -134,4 +134,40 @@ ORDER BY invocation_time DESC""", [http_function_id])
|
||||
def get_http_function_history(self, function_id):
|
||||
http_function_history = self.execute(
|
||||
'SELECT version_id, http_function_id, script_content, version_number, updated_at FROM http_functions_versions WHERE http_function_id=%s ORDER BY version_number DESC', [function_id])
|
||||
return http_function_history
|
||||
return http_function_history
|
||||
|
||||
def create_api_key(self, user_id, name, key, scopes):
|
||||
self.execute(
|
||||
'INSERT INTO api_keys (user_id, name, key, scopes) VALUES (%s, %s, %s, %s)',
|
||||
[user_id, name, key, json.dumps(scopes)],
|
||||
commit=True
|
||||
)
|
||||
|
||||
def get_api_key(self, key):
|
||||
api_key = self.execute(
|
||||
'SELECT id, user_id, name, key, scopes, created_at, last_used_at FROM api_keys WHERE key=%s',
|
||||
[key],
|
||||
one=True
|
||||
)
|
||||
return api_key
|
||||
|
||||
def delete_api_key(self, user_id, key_id):
|
||||
self.execute(
|
||||
'DELETE FROM api_keys WHERE user_id=%s AND id=%s',
|
||||
[user_id, key_id],
|
||||
commit=True
|
||||
)
|
||||
|
||||
def list_api_keys(self, user_id):
|
||||
api_keys = self.execute(
|
||||
'SELECT id, user_id, name, key, scopes, created_at, last_used_at FROM api_keys WHERE user_id=%s ORDER BY created_at DESC',
|
||||
[user_id]
|
||||
)
|
||||
return api_keys
|
||||
|
||||
def update_api_key_last_used(self, key_id):
|
||||
self.execute(
|
||||
'UPDATE api_keys SET last_used_at=NOW() WHERE id=%s',
|
||||
[key_id],
|
||||
commit=True
|
||||
)
|
||||
Reference in New Issue
Block a user