-
-
Notifications
You must be signed in to change notification settings - Fork 430
Added a local identity provider. #1333
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
affd3f2
Added a local identity provider.
3coins 5234bd4
Fixed typo.
3coins 2dc7723
Resetting color, which fallsback to a default in UI.
3coins 7fd95a9
Added fallback user, unit tests.
3coins 354fea8
Removed fallback to base identity provider.
3coins 21d3ae8
Added fallback to anonymous user.
3coins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import getpass | ||
|
||
from jupyter_server.auth.identity import IdentityProvider, User | ||
|
||
|
||
def create_initials(username): | ||
"""Creates initials combining first 2 consonants""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: not sure we care, but generally python docstring end w/ a period |
||
|
||
username = username.lower() | ||
|
||
# Default: return first two unique consonants | ||
consonants = [c for c in username if c in "bcdfghjklmnpqrstvwxyz"] | ||
srdas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if len(consonants) >= 2: | ||
return (consonants[0] + consonants[1]).upper() | ||
|
||
# Fallback: first two characters | ||
return username[:2].upper() | ||
|
||
|
||
class LocalIdentityProvider(IdentityProvider): | ||
|
||
def get_user(self, handler): | ||
username = getpass.getuser() | ||
andrii-i marked this conversation as resolved.
Show resolved
Hide resolved
|
||
user = User( | ||
username=username, | ||
name=username, | ||
initials=create_initials(username), | ||
color=None, | ||
) | ||
return user |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
how long can
username
be?if it's bounded it's fine, but line 13 is a loop within a loop so if
username
is large it could be expensive.The variable name suggests it should be a small string in which case it's not really an issue.
Otherwise, one simple way to do it is to interrupt the loop on line 13 as soon as two consonants were found.
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 believe this should be bounded in most systems to 32-256 chars.
https://serverfault.com/questions/294121/what-is-the-maximum-username-length-on-current-gnu-linux-systems