-
Notifications
You must be signed in to change notification settings - Fork 0
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
Db interfaces #1
Conversation
app/utils/key_handler.py
Outdated
keyindices = self.keyCollection.index_information() | ||
# Make sure, that key is an index (avoids duplicates); | ||
if not "key" in keyindices: | ||
self.keyCollection.create_index("key") |
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.
Should we add "unique" constraint here?
self.keyCollection.create_index("key")
=>
self.keyCollection.create_index("key", "unique")
Otherwise I think it's just an index.
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.
yes. Thanks
app/utils/key_handler.py
Outdated
userindices = self.userCollection.index_information() | ||
if not "username" in userindices: | ||
self.userCollection.create_index("username") | ||
self.userCollection.find |
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.
Is this line OK? Seems to be cut off at the middle?
app/utils/key_handler.py
Outdated
|
||
def set_key_activity(self, key: string, user: string, active: bool): | ||
""" | ||
Function to set the activity of a key |
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.
Suggestion:
"Function to set the activity of a key associated with a user."
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.
Function to set whether a key is active or not.
The key has to be owned by the user indicated.
Essentially, this is a check, whether that user is allowed to modify the key. If the key is not owned by the user this is a clear "no".
|
||
Parameters: | ||
- key (str): The key to check. | ||
- user (str): The user that requests this deletion |
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.
Suggestion:
"The user associated with the key."
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.
I would keep it as is, since this is kind of an auth-check here. and, yes, it needs to be the user associated with the key, but the input could also be a different user.
app/utils/logging_handler.py
Outdated
Parameters: | ||
- tokencount (int): The count of tokens. | ||
- model (str): The model related to the log entry. | ||
- source (str): The source of the log entry. |
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 could be expanded a bit, I had to think for a second what the source was although it's clearer when combined with the sourcetype
parameter. Like
The source of the user's request.
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.
Agreed:
What about:
- source (str): The source that authorized the request that is being logged. This could be a user name or an apikey.
- sourcetype (str): Specification of what kind of source authorized the request that is being logged (either 'apikey' or 'user').
app/utils/logging_handler.py
Outdated
self.logCollection.insert_one(logEntry) | ||
|
||
def get_usage_for_user(self, username): | ||
# Needs to be implemented |
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.
A fun detail, if I remember correctly the Pythonic way of marking this is to use the inbuilt notImplementedError
raise NotImplementedError
Saves you a whopping one line cause the explaining comment can be removed.
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.
Check the unique index vs index, otherwise looks good.
Base logging implemented,
Key generation and testing implemented -> actually updates instantly when new key is created/deleted/updated
Added development environment.yml (no need for some of the packages to be in the deployed version).
Logging aggregation not yet implemented, need to discuss details as to interface of this (i.e. how do we want to provide this data and what are the queries going to look like).