-
Notifications
You must be signed in to change notification settings - Fork 10
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
Support SSH endpoints and basic auth for HTTP endpoints #98
Conversation
app/scaffold/pkgs/pkgs.go
Outdated
if pkgUrl.IsRemoteEndpoint(str) { | ||
return str, true | ||
} | ||
|
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.
We check for remoteness after checking for short codes, because strings like gh:smoores-dev/scaffold
can be valid SCP endpoints, since user and password are optional and gh
is a valid host name.
In practice this is probably what folks want, anyway: if I set a short code, I would expect anything matching it to be replaced first, even if that short code is technically a valid URL itself.
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 looks great! Thanks for the PR. Super happy to get this merged, just left a few notes.
Let me know what you think about the basic auth config stuff. I think I'd also be okay merging as is and I can circle back and take a stab at the config stuff as well.
app/scaffold/pkgs/pkgs.go
Outdated
@@ -11,10 +11,12 @@ import ( | |||
"path/filepath" | |||
"strings" | |||
|
|||
pkgUrl "github.com/hay-kot/scaffold/app/scaffold/pkgs/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.
I think we can just name the package pkgurl
app/scaffold/pkgs/resolver.go
Outdated
@@ -49,7 +51,24 @@ func (r *Resolver) Resolve(arg string, checkDirs []string) (path string, err err | |||
Progress: os.Stdout, | |||
}) | |||
if err != nil { | |||
return "", fmt.Errorf("failed to clone repository: %w", err) | |||
if err.Error() == "authentication required" { |
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.
Should use the error comparison here
I think this is the one you're looking for
See This SO Issue if you're unfamiliar.
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.
Oh! Awesome, this is actually new to me, thanks so much for the link
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.
Ah, it looks like plumbing/transport/common is actually internal, so I maybe can't import ErrAuthenticationRequired
?
Ignore this, I figured it out!
username, password, err := promptHTTPAuth() | ||
if err == nil { | ||
r, err = git.PlainClone(dir, false, &git.CloneOptions{ | ||
URL: remoteRef, | ||
Progress: os.Stdout, | ||
Auth: &http.BasicAuth{ | ||
Username: username, | ||
Password: password, | ||
}, | ||
}) | ||
} |
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 must have deleted this comment on accident, whoops!
I'm wondering if this should be configuration driven in additon to being interactive? Interactive is nice, but if you're pulling down a few it would be nice to able to define these in the conf file
Here's what that could look like
auth:
- match: ^https://github.com.*
basic:
username: hay-kot
password: my-password
- match: ^https://mylocalgit.com.*
basic:
username: ${MY_LOCAL_GIT_USERNAME}
password: ${MY_LOCAL_GIT_PASSWORD}
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.
Oh very nice, yeah I think this would be great. Would you be alright with merging this as a first pass, and then adding config support as a fast follow? I'm happy to take a stab at the config work, too! But I'd also like to get this in :D
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.
Sounds good!
36c5ac9
to
f0ad218
Compare
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.
LGTM. Thanks!
At the moment, it's challenging to use private git repos as Scaffolds. This change adds two ways to do this:
[email protected]:smoores-dev/scaffold
toscaffold new
authentication required
error from the git provider.The new URL tools are ported straight from go-git, and match the way they check and parse URLs.
This fixes #97.