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

Check if URL contains basic auth in URL #1523

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

bkneis
Copy link
Contributor

@bkneis bkneis commented Jan 7, 2025

Fixes #1515 by checking if the URL contains basic auth (detected from the presence of : in the first part of the URL). The URL is then parsed again in case both basic auth AND a branch were specified.

If there is a fancier way of doing this with regex let me know :)

My test below shows the original problem with the URL parsed, then building my changes and testing the same URL and again with a branch (note the lines with URL: and Branch:)

➜  devpod git:(main) devpod up https://gitlab-ci-token:my-token-here@gitlab.com/my-group/my-repo.git
10:16:13 info Creating devcontainer...
10:16:14 info Clone repository
10:16:14 info URL: https://gitlab-ci-token:my-token-here
10:16:14 info Branch: gitlab.com/my-group/my-repo.git
...

➜  devpod git:(main) CGO_ENABLED=0 go build -ldflags "-s -w" -o devpod-cli

➜  devpod git:(main) ✗ ./devpod-cli up https://gitlab-ci-token:my-token-here@gitlab.com/my-group/my-repo.git 
10:23:42 info Creating devcontainer...
10:23:43 info Delete old workspace 'gitlab-com-my-group-my-repo'
10:23:43 info Clone repository
10:23:43 info URL: https://gitlab-ci-token:my-token-here@gitlab.com/my-group/my-repo.git
...

➜  devpod git:(main) ✗ ./devpod-cli up https://gitlab-ci-token:my-token-here@gitlab.com/my-group/my-repo.git@branch
10:25:30 info Creating devcontainer...
10:25:30 info Delete old workspace 'my-repo-git-branch'
10:25:30 info Clone repository
10:25:30 info URL: https://gitlab-ci-token:my-token-here@gitlab.com/my-group/my-repo.git
10:25:30 info Branch: branch
...

@bkneis bkneis requested a review from a team January 7, 2025 10:29
pkg/git/git.go Outdated Show resolved Hide resolved
repoBaseRegEx = `((?:(?:https?|git|ssh|file):\/\/)?\/?(?:[^@\/\n]+@)?(?:[^:\/\n]+)(?:[:\/][^\/\n]+)+(?:\.git)?)`
branchRegEx = regexp.MustCompile(`^` + repoBaseRegEx + `@([a-zA-Z0-9\./\-\_]+)$`)
repoBaseRegEx = `((?:(?:https?|git|ssh|file):\/\/)?(?:[^:@\/\n]+(?::[^@\/\n]+)?@)?(?:[^:\/\n]+|(?:\/[^\/\n]+)+)(?:[:\/][^\/\n]+)+(?:\.git))`
branchRegEx = regexp.MustCompile(`^` + repoBaseRegEx + `(?:@([a-zA-Z0-9\./\-\_]+))?$`)
Copy link
Contributor

Choose a reason for hiding this comment

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

does it also require updates in /desktop/src/views/Workspaces/CreateWorkspace/CreateWorkspaceInput.tsx ?

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 updated WorkspaceSourceInput.tsx but alas no luck :/ maybe a difference in go / TS regex

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.

Adding Git credentials in URL causes repo url to be mistaken for a branch
2 participants