wings/api/sftp_endpoints.go

39 lines
786 B
Go
Raw Normal View History

2019-12-07 23:53:07 +00:00
package api
import (
"encoding/json"
"github.com/pkg/errors"
"github.com/pterodactyl/sftp-server"
)
func (r *PanelRequest) ValidateSftpCredentials(request sftp_server.AuthenticationRequest) (*sftp_server.AuthenticationResponse, error) {
b, err := json.Marshal(request)
if err != nil {
return nil, err
}
2019-12-07 23:58:22 +00:00
resp, err := r.Post("/sftp/auth", b)
2019-12-07 23:53:07 +00:00
if err != nil {
return nil, err
}
defer resp.Body.Close()
r.Response = resp
if r.HasError() {
if r.HttpResponseCode() == 403 {
return nil, sftp_server.InvalidCredentialsError{}
}
return nil, errors.WithStack(errors.New(r.Error()))
}
response := new(sftp_server.AuthenticationResponse)
body, _ := r.ReadBody()
if err := json.Unmarshal(body, response); err != nil {
return nil, err
}
return response, nil
}