-
Notifications
You must be signed in to change notification settings - Fork 5k
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
chore: Move GitHub logic out of the frontend #6307
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a big PR, but the backend looks good to me. I had a question about those redundant values saved in Settings. IMHO only github_token
is needed, and we can compute the rest. We can compute them in the BE if you want, so that nothing changes for FE, we just don't save them.
If you feel strongly that they need saved, okay, but please note that then it's a bit more difficult to remove them later, because they will be on users' machines.
@@ -21,6 +21,7 @@ class Settings(BaseModel): | |||
llm_api_key: SecretStr | None = None | |||
llm_base_url: str | None = None | |||
remote_runtime_resource_factor: int | None = None | |||
github_token: str | None = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe good for a follow-up, rather than add to this large PR, but can we use SecretStr
inline with llm_api_key
and other secrets, rather than str
for github_token
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah that seems like a good idea. I hate to extend this PR further but maybe it's worth doing now. Up to you @amanape
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will follow-up
""" | ||
|
||
github_token_is_set: bool | None = None | ||
unset_github_token: bool | None = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, I like that we have a solution for this trick!
content={'message': 'Settings stored'}, | ||
) | ||
await settings_store.store(settings) | ||
return response | ||
except Exception as e: | ||
logger.warning(f'Invalid token: {e}') | ||
return JSONResponse( | ||
status_code=status.HTTP_401_UNAUTHORIZED, | ||
content={'error': 'Invalid token'}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: this catches Exception, and it can be for other reasons than the token. In fact, it seems that at line 65 we already failed because of the token, if that was the cause. Maybe we can send some other response here, because it might be confusing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will follow-up
This PR replaces and simplifies #6286
Give a summary of what the PR does, explaining any non-trivial design decisions
Frontend
github_token
in the settings file store on the servergithub_token
on the frontendgithubTokenIsSet
insteadBackend
GitHubTokenMiddleware
to retrieve and set thegithub_token
from the settings file store to the request state objectrequest.state.github_token
instead of"X-GitHub-Token"
header/user
) whenPOST /settings
is called with agithub_token
Common
github_token
,unset_github_token
, andgithub_token_is_set
propertiesUI
To run this PR locally, use the following command: