Skip to content

Commit

Permalink
perf: 校验资产平台的 sftp 是否开启 (#1064)
Browse files Browse the repository at this point in the history
* perf: 校验资产平台的 sftp 是否开启

* fix: golangci-lint error

---------

Co-authored-by: Eric <[email protected]>
  • Loading branch information
fit2bot and LeeEirc authored Apr 6, 2023
1 parent 0bc7400 commit b6b0fb0
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 9 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,7 @@ pnpm-debug.log*
*.njsproj
*.sln
*.sw?
demo
assets/
ui/dist/favicon.ico
ui/dist/index.html
3 changes: 1 addition & 2 deletions pkg/common/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"mime/multipart"
"net/http"
neturl "net/url"
Expand Down Expand Up @@ -281,7 +280,7 @@ func (c *Client) UploadFile(reqUrl string, gFile string, res interface{}, params
return err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if resp.StatusCode >= 400 {
msg := fmt.Sprintf("%s %s failed, get code: %d, %s", req.Method, req.URL, resp.StatusCode, string(body))
err = errors.New(msg)
Expand Down
6 changes: 3 additions & 3 deletions pkg/common/sshutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"crypto/rsa"
"crypto/x509"
"encoding/pem"
"io/ioutil"
"os"

"golang.org/x/crypto/ssh"
)
Expand Down Expand Up @@ -42,15 +42,15 @@ func EncodePrivateKeyToPEM(privateKey *rsa.PrivateKey) []byte {
}

func WriteKeyToFile(keyBytes []byte, saveFileTo string) error {
err := ioutil.WriteFile(saveFileTo, keyBytes, 0600)
err := os.WriteFile(saveFileTo, keyBytes, 0600)
if err != nil {
return err
}
return nil
}

func GetPubKeyFromFile(keypath string) (ssh.Signer, error) {
buf, err := ioutil.ReadFile(keypath)
buf, err := os.ReadFile(keypath)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/handler/dispatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,6 @@ func (h *InteractiveHandler) displayNodeTree(nodes model.NodeList) {
_, _ = io.WriteString(h.term, tree.String())
_, err := io.WriteString(h.term, lang.T("Tips: Enter g+NodeID to display the host under the node, such as g1")+"\n\r")
if err != nil {
logger.Errorf("displayAssetNodes err:", err)
logger.Errorf("displayAssetNodes err: %s", err)
}
}
6 changes: 3 additions & 3 deletions pkg/httpd/userwebsocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,8 @@ func (userCon *UserWebsocket) CurrentUser() *model.User {
}

func (userCon *UserWebsocket) SendErrMessage(errMsg string) {
data, _ := json.Marshal(
&Message{Id: userCon.Uuid, Type: ERROR, Err: errMsg},
)
msg := Message{Id: userCon.Uuid, Type: ERROR, Err: errMsg}
data, _ := json.Marshal(msg)
if err := userCon.conn.WriteText(data, maxWriteTimeOut); err != nil {
logger.Errorf("Ws[%s] send error message err: %s", userCon.Uuid, err)
}
Expand All @@ -231,4 +230,5 @@ var (
ErrAssetIdInvalid = errors.New("asset id invalid")
ErrDisableShare = errors.New("disable share")
ErrPermissionDenied = errors.New("permission denied")
ErrSftpDisabled = errors.New("sftp disabled")
)
5 changes: 5 additions & 0 deletions pkg/httpd/webfolder.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ func (h *webFolder) CheckValidation() error {
}
if h.ws.ConnectToken != nil {
connectToken := h.ws.ConnectToken
protocol := connectToken.Platform.GetProtocol(connectToken.Protocol)
if !protocol.Setting.SftpEnabled {
logger.Errorf("Web sftp asset %s sftp disabled", connectToken.Asset.String())
return ErrSftpDisabled
}
volOpts = append(volOpts, WithConnectToken(connectToken))
}
h.volume = NewUserVolume(apiClient, volOpts...)
Expand Down

0 comments on commit b6b0fb0

Please sign in to comment.