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

Db interfaces #1

Merged
merged 10 commits into from
Nov 29, 2023
Merged

Db interfaces #1

merged 10 commits into from
Nov 29, 2023

Conversation

tpfau
Copy link
Member

@tpfau tpfau commented Nov 29, 2023

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).

keyindices = self.keyCollection.index_information()
# Make sure, that key is an index (avoids duplicates);
if not "key" in keyindices:
self.keyCollection.create_index("key")
Copy link
Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. Thanks

userindices = self.userCollection.index_information()
if not "username" in userindices:
self.userCollection.create_index("username")
self.userCollection.find
Copy link
Contributor

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?


def set_key_activity(self, key: string, user: string, active: bool):
"""
Function to set the activity of a key
Copy link
Contributor

@ruokolt ruokolt Nov 29, 2023

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."

Copy link
Member Author

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
Copy link
Contributor

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."

Copy link
Member Author

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.

Parameters:
- tokencount (int): The count of tokens.
- model (str): The model related to the log entry.
- source (str): The source of the log entry.
Copy link
Contributor

@ruokolt ruokolt Nov 29, 2023

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.

Copy link
Member Author

@tpfau tpfau Nov 29, 2023

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').

self.logCollection.insert_one(logEntry)

def get_usage_for_user(self, username):
# Needs to be implemented
Copy link
Contributor

@ruokolt ruokolt Nov 29, 2023

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.

Copy link
Contributor

@ruokolt ruokolt left a 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.

@tpfau tpfau merged commit af988b3 into main Nov 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants