Skip to content

Commit cc8a3d9

Browse files
authored
Merge pull request #4 from FalkorDB/verification-token
Verification token
2 parents 9678aba + 3f66d81 commit cc8a3d9

File tree

7 files changed

+339
-1022
lines changed

7 files changed

+339
-1022
lines changed

.env.template

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FALKORDB_HOST=<host>
2+
FALKORDB_PORT=<port>
3+
FALKORDB_USERNAME=<username>
4+
FALKORDB_PASSWORD=<password>
5+
OPENAI_API_KEY=<openai_api_key>
6+
GOOGLE_API_KEY=<google_api_key>
7+
SECRET_TOKEN=<secret_token>
8+

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.env

code_graph/app.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import datetime
33
from code_graph import *
44
from typing import Optional
5+
from functools import wraps
56
from falkordb import FalkorDB
67
from dotenv import load_dotenv
78
from urllib.parse import urlparse
@@ -17,10 +18,26 @@
1718
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
1819
logger = logging.getLogger(__name__)
1920

21+
# Function to verify the token
22+
SECRET_TOKEN = os.getenv('SECRET_TOKEN')
23+
def verify_token(token):
24+
return token == SECRET_TOKEN
25+
26+
# Decorator to protect routes with token authentication
27+
def token_required(f):
28+
@wraps(f)
29+
def decorated_function(*args, **kwargs):
30+
token = request.headers.get('Authorization') # Get token from header
31+
if not token or not verify_token(token):
32+
return jsonify(message="Unauthorized"), 401
33+
return f(*args, **kwargs)
34+
return decorated_function
35+
2036
def create_app():
2137
app = Flask(__name__)
2238

2339
@app.route('/graph_entities', methods=['GET'])
40+
@token_required # Apply token authentication decorator
2441
def graph_entities():
2542
"""
2643
Endpoint to fetch sub-graph entities from a given repository.
@@ -64,6 +81,7 @@ def graph_entities():
6481

6582

6683
@app.route('/get_neighbors', methods=['GET'])
84+
@token_required # Apply token authentication decorator
6785
def get_neighbors():
6886
"""
6987
Endpoint to get neighbors of a specific node in the graph.
@@ -117,6 +135,7 @@ def get_neighbors():
117135

118136

119137
@app.route('/process_repo', methods=['POST'])
138+
@token_required # Apply token authentication decorator
120139
def process_repo():
121140
"""
122141
Process a GitHub repository.
@@ -151,6 +170,7 @@ def process_repo():
151170
return jsonify(response), 200
152171

153172
@app.route('/process_local_repo', methods=['POST'])
173+
@token_required # Apply token authentication decorator
154174
def process_local_repo():
155175
# Get JSON data from the request
156176
data = request.get_json()
@@ -182,6 +202,7 @@ def process_local_repo():
182202
return jsonify(response), 200
183203

184204
@app.route('/process_code_coverage', methods=['POST'])
205+
@token_required # Apply token authentication decorator
185206
def process_code_coverage():
186207
"""
187208
Endpoint to process code coverage data for a given repository.
@@ -217,6 +238,7 @@ def process_code_coverage():
217238

218239

219240
@app.route('/switch_commit', methods=['POST'])
241+
@token_required # Apply token authentication decorator
220242
def switch_commit():
221243
"""
222244
Endpoint to switch a repository to a specific commit.
@@ -250,6 +272,7 @@ def switch_commit():
250272
return jsonify(response), 200
251273

252274
@app.route('/auto_complete', methods=['POST'])
275+
@token_required # Apply token authentication decorator
253276
def auto_complete():
254277
"""
255278
Endpoint to process auto-completion requests for a repository based on a prefix.
@@ -288,6 +311,7 @@ def auto_complete():
288311

289312

290313
@app.route('/list_repos', methods=['GET'])
314+
@token_required # Apply token authentication decorator
291315
def list_repos():
292316
"""
293317
Endpoint to list all available repositories.
@@ -309,6 +333,7 @@ def list_repos():
309333

310334

311335
@app.route('/list_commits', methods=['POST'])
336+
@token_required # Apply token authentication decorator
312337
def list_commits():
313338
"""
314339
Endpoint to list all commits of a specified repository.
@@ -346,6 +371,7 @@ def list_commits():
346371

347372

348373
@app.route('/repo_info', methods=['POST'])
374+
@token_required # Apply token authentication decorator
349375
def repo_info():
350376
"""
351377
Endpoint to retrieve information about a specific repository.
@@ -390,6 +416,7 @@ def repo_info():
390416
return jsonify(response), 200
391417

392418
@app.route('/find_paths', methods=['POST'])
419+
@token_required # Apply token authentication decorator
393420
def find_paths():
394421
"""
395422
Finds all paths between a source node (src) and a destination node (dest) in the graph.
@@ -445,6 +472,7 @@ def find_paths():
445472

446473

447474
@app.route('/unreachable', methods=['POST'])
475+
@token_required # Apply token authentication decorator
448476
def unreachable_entities():
449477
"""
450478
Endpoint to retrieve unreachable entities in the graph.
@@ -478,6 +506,7 @@ def unreachable_entities():
478506
return jsonify(response), 200
479507

480508
@app.route('/chat', methods=['POST'])
509+
@token_required # Apply token authentication decorator
481510
def chat():
482511
# Get JSON data from the request
483512
data = request.get_json()

code_graph/llm.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
22

33
from graphrag_sdk.models.openai import OpenAiGenerativeModel
4-
from graphrag_sdk.models.gemini import GeminiGenerativeModel
4+
#from graphrag_sdk.models.gemini import GeminiGenerativeModel
55

66
from graphrag_sdk import (
77
Ontology,
@@ -193,14 +193,14 @@ def _create_kg_agent(repo_name: str):
193193
global ontology
194194

195195
openapi_model = OpenAiGenerativeModel("gpt-4o")
196-
gemini_model = GeminiGenerativeModel("gemini-1.5-flash-001")
197-
gemini_model_pro = GeminiGenerativeModel("gemini-1.5-pro")
196+
#gemini_model = GeminiGenerativeModel("gemini-1.5-flash-001")
197+
#gemini_model_pro = GeminiGenerativeModel("gemini-1.5-pro")
198198

199199
#ontology = _define_ontology()
200200
code_graph_kg = KnowledgeGraph(
201201
name=repo_name,
202202
ontology=ontology,
203-
model_config=KnowledgeGraphModelConfig.with_model(gemini_model),
203+
model_config=KnowledgeGraphModelConfig.with_model(openapi_model),
204204
)
205205

206206
return code_graph_kg.chat_session()

0 commit comments

Comments
 (0)