-
Notifications
You must be signed in to change notification settings - Fork 33
Add KeyChain Cache, Plain-Text File Cache, and Cache Factory #15
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
Conversation
This reverts commit f8f61bd.
…mplementation that can be overriden
Previously, implementations lived in their platform specific files. However, this created an import cycle that pylint was complaining about.
rayluo
left a comment
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.
@marstr As usual, thanks for your good work in this PR! I'm sending part of my comments here. I'll send out part 2 of the review on the osx.py soon too.
This accomplishes a couple of things: - Establishes that _read and _write SHOULD error out if they are unable to do their job. This way different places in code base can choose what is and is not an acceptable place to fail a read or write operation. - Keeps the contract that derived class implementers need to fulfill very simple.
…ne strategically with kwargs
|
Got word from @rayluo offline that there were still some outstanding problems with the Error factory. I've decided to just go ahead and consolidate the different Error Types into one. It's easier to add to public surface area than remove, after all. |
rayluo
left a comment
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.
Thanks @marstr ! Definitely love what we have seen so far!
This PR is now functionally correct. The comments below is for a higher level on the usability aspect. Let's have some quick sync and get this done. :-)
msal_extensions/token_cache.py
Outdated
| def get_protected_token_cache( | ||
| cache_location=None, | ||
| lock_location=None, | ||
| enforce_encryption=False, **kwargs): |
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.
From a usability standpoint, wouldn't it be somewhat misleading that such constructor's name is get_protected_token_cache(...), yet one of the optional parameter is enforce_encryption=False? It would cause confusion for dev who reads our api signature and even its docs, but not reading its implementation (which means the majority of devs), "am I supposed to always enable enforce_encryption or what?".
Would better make the encryption_thing=True the default behavior. And then of course we would probably want to NOT blow out by RuntimeError. A noticeable warning would be fine. Please see my another comment for a more detailed proposal.
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.
Fixed in a68ba24
msal_extensions/token_cache.py
Outdated
| from .osx import Keychain | ||
|
|
||
|
|
||
| def get_protected_token_cache( |
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.
What if we skip this helper completely, and just define the following into the __init__.py? It would be conceptually one less layer of helper, from the perspective of app devs. And it is believed to be the pattern from the python os package.
if sys.platform.startswith('win'):
from .token_cache import WindowsTokenCache as TokenCache
elif sys.platform.startswith('darwin'):
from .token_cache import OSXTokenCache as TokenCache
else:
from .token_cache import UnencryptedTokenCache as TokenCacheAnd then theUnencryptedTokenCache (formerly the inherited from the base FileTokenCache) constructor can have nothing else but that "no encryption" warning behavior built-in, even without a dedicated flag for it.
class UnencryptedTokenCache(FileTokenCache):
def __init__(self, **kwargs):
warnings.warn("You are using an unprotected token cache for platform {}".format(sys.platform)
# Note: since this becomes the default behavior now,
# we do not want to raise RuntimeError(...) which would break an app on a Linux platform
super(UnencryptedTokenCache, self).__init__(**kwargs)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 like this :) Something I wouldn't have thought of, but it definitely simplifies the consumption of this API. I'll have those changes in shortly
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.
Fixed in a68ba24
rayluo
left a comment
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.
Thanks for the tirelessly refining our implementation! Ship it!
🚢 👍
Closes #3
Closes #5
I usually like to keep my PRs small. This time I got tantalized into exploding the size to do some integration test with the Azure CLI.
We are rapidly approaching functional parity with my initial prototype, but with much much cleaner code.