Send key correctly; don't retry 4xx errors
This commit is contained in:
parent
5bcf4164fb
commit
1927a59cd0
|
@ -142,12 +142,10 @@ func (c *client) request(ctx context.Context, method, path string, body io.Reade
|
||||||
if r.HasError() {
|
if r.HasError() {
|
||||||
// Close the request body after returning the error to free up resources.
|
// Close the request body after returning the error to free up resources.
|
||||||
defer r.Body.Close()
|
defer r.Body.Close()
|
||||||
// Don't keep spamming the endpoint if we've already made too many requests or
|
// Don't keep attempting to access this endpoint if the response is a 4XX
|
||||||
// if we're not even authenticated correctly. Retrying generally won't fix either
|
// level error which indicates a client mistake. Only retry when the error
|
||||||
// of these issues.
|
// is due to a server issue (5XX error).
|
||||||
if r.StatusCode == http.StatusForbidden ||
|
if r.StatusCode >= 400 && r.StatusCode < 500 {
|
||||||
r.StatusCode == http.StatusTooManyRequests ||
|
|
||||||
r.StatusCode == http.StatusUnauthorized {
|
|
||||||
return backoff.Permanent(r.Error())
|
return backoff.Permanent(r.Error())
|
||||||
}
|
}
|
||||||
return r.Error()
|
return r.Error()
|
||||||
|
|
|
@ -74,7 +74,7 @@ func (c *SFTPServer) Run() error {
|
||||||
return c.makeCredentialsRequest(conn, remote.SftpAuthPassword, string(password))
|
return c.makeCredentialsRequest(conn, remote.SftpAuthPassword, string(password))
|
||||||
},
|
},
|
||||||
PublicKeyCallback: func(conn ssh.ConnMetadata, key ssh.PublicKey) (*ssh.Permissions, error) {
|
PublicKeyCallback: func(conn ssh.ConnMetadata, key ssh.PublicKey) (*ssh.Permissions, error) {
|
||||||
return c.makeCredentialsRequest(conn, remote.SftpAuthPublicKey, string(key.Marshal()))
|
return c.makeCredentialsRequest(conn, remote.SftpAuthPublicKey, string(ssh.MarshalAuthorizedKey(key)))
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
conf.AddHostKey(private)
|
conf.AddHostKey(private)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user