Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove AUTH_PROVIDER references #1299

Merged
merged 5 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions agixt/ApiClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,20 @@ def verify_api_key(authorization: str = Header(None)):
authorization = str(authorization).replace("Bearer ", "").replace("bearer ", "")
if DEFAULT_USER == "" or DEFAULT_USER is None or DEFAULT_USER == "None":
DEFAULT_USER = "user"
if getenv("AUTH_PROVIDER") == "magicalauth":
auth_key = AGIXT_API_KEY + str(datetime.now().strftime("%Y%m%d"))
try:
token = jwt.decode(
jwt=authorization,
key=auth_key,
algorithms=["HS256"],
leeway=timedelta(hours=5),
)
return token["email"]
except Exception as e:
if authorization == auth_key:
return DEFAULT_USER
if authorization != AGIXT_API_KEY:
logging.info(f"Invalid API Key: {authorization}")
raise HTTPException(status_code=401, detail="Invalid API Key")
try:
token = jwt.decode(
jwt=authorization,
key=AGIXT_API_KEY,
algorithms=["HS256"],
leeway=timedelta(hours=5),
)
return token["email"]
except Exception as e:
if authorization == AGIXT_API_KEY:
return DEFAULT_USER
if authorization != AGIXT_API_KEY:
logging.info(f"Invalid API Key: {authorization}")
raise HTTPException(status_code=401, detail="Invalid API Key")
if AGIXT_API_KEY:
if authorization is None:
logging.info("Authorization header is missing")
Expand Down
1 change: 0 additions & 1 deletion agixt/Globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def getenv(var_name: str):
"DISABLED_EXTENSIONS": "",
"DISABLED_PROVIDERS": "",
"REGISTRATION_DISABLED": "false",
"AUTH_PROVIDER": "magicalauth",
"CREATE_AGENT_ON_REGISTER": "true",
"CREATE_AGIXT_AGENT": "true",
}
Expand Down
8 changes: 2 additions & 6 deletions agixt/MagicalAuth.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,6 @@ def urldecode(data: str):

def verify_api_key(authorization: str = Header(None)):
AGIXT_API_KEY = getenv("AGIXT_API_KEY")
if getenv("AUTH_PROVIDER") == "magicalauth":
AGIXT_API_KEY = f'{AGIXT_API_KEY}{datetime.now().strftime("%Y%m%d")}'
authorization = str(authorization).replace("Bearer ", "").replace("bearer ", "")
if AGIXT_API_KEY:
if authorization is None:
Expand Down Expand Up @@ -167,7 +165,6 @@ def verify_api_key(authorization: str = Header(None)):

def impersonate_user(user_id: str):
AGIXT_API_KEY = getenv("AGIXT_API_KEY")
AGIXT_API_KEY = f'{AGIXT_API_KEY}{datetime.now().strftime("%Y%m%d")}'
# Get users email
session = get_session()
user = session.query(User).filter(User.id == user_id).first()
Expand Down Expand Up @@ -289,9 +286,8 @@ def decrypt(key: str, data: str):

class MagicalAuth:
def __init__(self, token: str = None):
encryption_key = getenv("AGIXT_API_KEY")
self.encryption_key = getenv("AGIXT_API_KEY")
self.link = getenv("MAGIC_LINK_URL")
self.encryption_key = f'{encryption_key}{datetime.now().strftime("%Y%m%d")}'
token = (
str(token)
.replace("%2B", "+")
Expand Down Expand Up @@ -341,7 +337,7 @@ def __init__(self, token: str = None):
self.email = None
self.token = None
self.user_id = None
if token == encryption_key:
if token == self.encryption_key:
self.email = getenv("DEFAULT_USER")
self.user_id = get_user_id(self.email)
self.token = token
Expand Down
40 changes: 22 additions & 18 deletions agixt/Memories.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,24 +86,28 @@ def query_results_to_records(results: "QueryResult"):
results[k] = [v]
except IndexError:
return []
memory_records = [
{
"external_source_name": metadata.get("external_source_name", "user input"),
"id": metadata["id"],
"description": metadata["description"],
"text": document,
"embedding": embedding,
"additional_metadata": metadata["additional_metadata"],
"key": id,
"timestamp": metadata["timestamp"],
}
for id, document, embedding, metadata in zip(
results["ids"][0],
results["documents"][0],
results["embeddings"][0],
results["metadatas"][0],
)
]
memory_records = []
for id, document, embedding, metadata in zip(
results["ids"][0],
results["documents"][0],
results["embeddings"][0],
results["metadatas"][0],
):
if metadata:
memory_records.append(
{
"external_source_name": metadata.get(
"external_source_name", "user input"
),
"id": metadata["id"],
"description": metadata["description"],
"text": document,
"embedding": embedding,
"additional_metadata": metadata["additional_metadata"],
"key": id,
"timestamp": metadata["timestamp"],
}
)
return memory_records


Expand Down
1 change: 0 additions & 1 deletion docker-compose-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ services:
UVICORN_WORKERS: ${UVICORN_WORKERS:-10}
AGIXT_API_KEY: ${AGIXT_API_KEY:-None}
AGIXT_URI: ${AGIXT_URI:-http://agixt:7437}
AUTH_PROVIDER: ${AUTH_PROVIDER:-magicalauth}
MAGIC_LINK_URL: ${AUTH_WEB:-http://localhost:3437/user}
DISABLED_EXTENSIONS: ${DISABLED_EXTENSIONS}
DISABLED_PROVIDERS: ${DISABLED_PROVIDERS}
Expand Down
1 change: 0 additions & 1 deletion docker-compose-nostreamlit-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ services:
UVICORN_WORKERS: ${UVICORN_WORKERS:-10}
AGIXT_API_KEY: ${AGIXT_API_KEY:-None}
AGIXT_URI: ${AGIXT_URI:-http://agixt:7437}
AUTH_PROVIDER: ${AUTH_PROVIDER:-magicalauth}
MAGIC_LINK_URL: ${AUTH_WEB:-http://localhost:3437/user}
DISABLED_EXTENSIONS: ${DISABLED_EXTENSIONS}
DISABLED_PROVIDERS: ${DISABLED_PROVIDERS}
Expand Down
1 change: 0 additions & 1 deletion docker-compose-nostreamlit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ services:
UVICORN_WORKERS: ${UVICORN_WORKERS:-10}
AGIXT_API_KEY: ${AGIXT_API_KEY:-None}
AGIXT_URI: ${AGIXT_URI:-http://agixt:7437}
AUTH_PROVIDER: ${AUTH_PROVIDER:-magicalauth}
MAGIC_LINK_URL: ${AUTH_WEB:-http://localhost:3437/user}
DISABLED_EXTENSIONS: ${DISABLED_EXTENSIONS}
DISABLED_PROVIDERS: ${DISABLED_PROVIDERS}
Expand Down
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ services:
UVICORN_WORKERS: ${UVICORN_WORKERS:-10}
AGIXT_API_KEY: ${AGIXT_API_KEY:-None}
AGIXT_URI: ${AGIXT_URI:-http://agixt:7437}
AUTH_PROVIDER: ${AUTH_PROVIDER:-magicalauth}
MAGIC_LINK_URL: ${AUTH_WEB:-http://localhost:3437/user}
DISABLED_EXTENSIONS: ${DISABLED_EXTENSIONS}
DISABLED_PROVIDERS: ${DISABLED_PROVIDERS}
Expand Down
1 change: 0 additions & 1 deletion start.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ def get_default_env_vars():
"APP_URI": "http://localhost:3437",
"STREAMLIT_APP_URI": "http://localhost:8501",
"AUTH_WEB": "http://localhost:3437/user",
"AUTH_PROVIDER": "magicalauth",
"CREATE_AGENT_ON_REGISTER": "true",
"CREATE_AGIXT_AGENT": "true",
"DISABLED_PROVIDERS": "",
Expand Down
Loading