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
Fix username & password in SCM for git clone with ssh #8016
Conversation
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.
There are a couple of tests
|
||
def test_ssh_password(self): | ||
scm = SCMBase(password="pass") |
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 am a bit confused a bit about this test. So adding the password, but not the user, will not add the password, but will not error either?
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.
This was the behavior before but I am not sure how the user could set only the password. Maybe providing the user already in the URL?
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.
Well, that is the point, the previous behavior was requiring both user+password. Now we changed it, and adding only the user is a new valid behavior, with a new test checking it.
I'd say that we need to define a new behavior for only the password: either an error for this case, or check that there is a valid scenario, like the user is already in the URL, but that should probably be a new test too.
I have added some warning messages for options that ignore parameters |
This comment has been minimized.
This comment has been minimized.
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.
My spider-sense says this is going to fail somewhere and somehow. I find too many if/else here. I'd suggest a dispatcher, something like:
def handle_scp_pattern(user, domain, url):
... logic related to user, password and warnings.
return "{usr}@{domain}:{url}".format(user=user, domain=domain, url=url)
def handle_url_pattern(protocol, url, user=None, password=Non):
... logic related to user, password and warnings
auth = "{user}:{password}@" if xxxx else "{user}@" if yyyyy else ""
return "{protocol}://{auth}{url}".format(protocol=protocol, auth=auth, url=url)
# Maybe other actions if the logic inside of them starts to be cumbersome
# Now a map/list we will iterate and use the matching dispatcher
url_patterns = {
'scp': [
re.compile("^(?P<user>[a-zA-Z0-9_]+)@(?P<domain>[a-zA-Z0-9._-]+):(?P<url>.*)$"),
handle_scp_pattern
]
'url_user_pass': [
re.compile("^(?P<protocol>file|http|git)s?:\/\/(?P<user>\S+):(?P<password>\S+)@(?P<url>.*)$"),
handle_url_pattern
]
'url_user': [
re.compile("^(?P<protocol>file|http|git)s?:\/\/(?P<user>\S+)@(?P<url>.*)$"),
handle_url_pattern
]
}
for key, (pattern, action) in url_patterns:
m = pattern.match(url)
if m:
return action(**m.groupdict())
self.output.warn("URL not recognized....")
return url
wdyt? This is just a suggestion. Let me know and I'll review carefully whatever you choose
@jgsogo I have followed your suggestion and I think the code is cleaner. Please check again as I have also added more tests. Thank you! |
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.
Some suggestions. Now it's much easier to follow all the conditions
Co-authored-by: Javier G. Sogo <jgsogo@gmail.com>
Co-authored-by: Javier G. Sogo <jgsogo@gmail.com>
Co-authored-by: Javier G. Sogo <jgsogo@gmail.com>
Co-authored-by: Javier G. Sogo <jgsogo@gmail.com>
Co-authored-by: Javier G. Sogo <jgsogo@gmail.com>
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.
This is much better structured and understandable, and likely to be more robust. Well done.
Changelog: Fix: Set username or password individually in git SCM with ssh.
Docs: omit
develop
branch, documenting this one.Note: By default this PR will skip the slower tests and will use a limited set of python versions. Check here how to increase the testing level by writing some tags in the current PR body text.