Skip to content

Conversation

@marstr
Copy link
Contributor

@marstr marstr commented May 16, 2019

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.

@marstr marstr requested review from abhidnya13 and rayluo May 16, 2019 23:05
@marstr marstr closed this May 22, 2019
@marstr marstr reopened this May 22, 2019
@marstr marstr changed the title Add KeyChain Cache Add KeyChain Cache, Plain-Text File Cache, and Cache Factory May 31, 2019
Copy link
Contributor

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

marstr added 8 commits June 10, 2019 15:51
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.
@marstr marstr requested a review from rayluo June 21, 2019 17:24
@marstr
Copy link
Contributor Author

marstr commented Jun 24, 2019

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.

Copy link
Contributor

@rayluo rayluo left a 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. :-)

def get_protected_token_cache(
cache_location=None,
lock_location=None,
enforce_encryption=False, **kwargs):
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in a68ba24

from .osx import Keychain


def get_protected_token_cache(
Copy link
Contributor

@rayluo rayluo Jun 24, 2019

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 TokenCache

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

Copy link
Contributor Author

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in a68ba24

@marstr marstr requested a review from rayluo June 25, 2019 17:12
Copy link
Contributor

@rayluo rayluo left a 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! :shipit: 🚢 👍

@marstr marstr merged commit 6bc5141 into AzureAD:dev Jun 25, 2019
@rayluo rayluo mentioned this pull request Jul 11, 2019
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.

Create Secret Backend Mux Create a KeyChain Token Cache (MacOS Only)

2 participants