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

minor improvements to auth plugins #17041

Merged
merged 1 commit into from
Sep 23, 2024

Conversation

memsharded
Copy link
Member

Changelog: Omit
Docs: Omit

@memsharded memsharded added this to the 2.8.0 milestone Sep 23, 2024
if args.username is not None and args.username != user:
raise ConanException(f"User '{args.username}' doesn't match user '{user}' in "
f"credentials.json or environment variables")
if args.username is not None and args.password is not None:
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the main change. I removed the password argument in the creds.auth(), it was confusing and it made you add it in your PR, because I think the argument was not right in the first place

@@ -33,11 +33,11 @@ class _SourceURLCredentials:
"""
def __init__(self, cache_folder):
self._urls = {}
self.auth_source_plugin = None
self._auth_source_plugin = None
Copy link
Member Author

Choose a reason for hiding this comment

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

Prefer private by default

def _load_auth_source_plugin(auth_source_plugin_path):
if os.path.exists(auth_source_plugin_path):
mod, _ = load_python_file(auth_source_plugin_path)
if hasattr(mod, "auth_source_plugin"):
return mod.auth_source_plugin
return getattr(mod, "auth_source_plugin", None)
Copy link
Member Author

Choose a reason for hiding this comment

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

More pythonic, single instruction, better than check-then-return

class RemoteCredentials:
def __init__(self, cache_folder, global_conf):
self._global_conf = global_conf
self._urls = {}
self.auth_remote_plugin = _load_auth_remote_plugin(HomePaths(cache_folder).auth_remote_plugin_path)
auth_plugin_path = HomePaths(cache_folder).auth_remote_plugin_path
self._auth_remote_plugin = _load_auth_remote_plugin(auth_plugin_path)
Copy link
Member Author

Choose a reason for hiding this comment

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

Private by default

class RemoteCredentials:
def __init__(self, cache_folder, global_conf):
self._global_conf = global_conf
self._urls = {}
self.auth_remote_plugin = _load_auth_remote_plugin(HomePaths(cache_folder).auth_remote_plugin_path)
auth_plugin_path = HomePaths(cache_folder).auth_remote_plugin_path
Copy link
Member Author

Choose a reason for hiding this comment

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

Avoid too long lines

@@ -82,8 +80,8 @@ def _get_env(remote, user):
ConanOutput().info("Got password '******' from environment")
return user, passwd


Copy link
Member Author

Choose a reason for hiding this comment

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

Pep8 says 2 blank lines here (enabling some linter in your IDE will make this highlighted)

Copy link
Contributor

@ErniGH ErniGH left a comment

Choose a reason for hiding this comment

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

LGTM Thanks

@ErniGH ErniGH merged commit 28739c7 into conan-io:develop2 Sep 23, 2024
2 checks passed
@memsharded memsharded deleted the style/auth_plugins branch September 23, 2024 14:54
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