MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / SaveConnInfo

Method SaveConnInfo

agent/app/service/setting.go:241–275  ·  view source on GitHub ↗
(req dto.SSHConnData)

Source from the content-addressed store, hash-verified

239}
240
241func (u *SettingService) SaveConnInfo(req dto.SSHConnData) error {
242 if req.AuthMode == "password" && len(req.Password) != 0 {
243 password, err := base64.StdEncoding.DecodeString(req.Password)
244 if err != nil {
245 return err
246 }
247 req.Password = string(password)
248 }
249 if req.AuthMode == "key" && len(req.PrivateKey) != 0 {
250 privateKey, err := base64.StdEncoding.DecodeString(req.PrivateKey)
251 if err != nil {
252 return err
253 }
254 req.PrivateKey = string(privateKey)
255 }
256
257 var connInfo ssh.ConnInfo
258 _ = copier.Copy(&connInfo, &req)
259 connInfo.PrivateKey = []byte(req.PrivateKey)
260 if len(req.PassPhrase) != 0 {
261 connInfo.PassPhrase = []byte(req.PassPhrase)
262 }
263 client, err := ssh.NewClient(connInfo)
264 if err != nil {
265 return err
266 }
267 defer client.Close()
268
269 var connItem model.LocalConnInfo
270 _ = copier.Copy(&connItem, &req)
271 localConn, _ := json.Marshal(&connItem)
272 connAfterEncrypt, _ := encrypt.StringEncrypt(string(localConn))
273 _ = settingRepo.Update("LocalSSHConn", connAfterEncrypt)
274 return nil
275}
276
277func (u *SettingService) SetDefaultIsConn(req dto.SSHDefaultConn) error {
278 if req.DefaultConn == constant.StatusDisable && req.WithReset {

Callers

nothing calls this directly

Calls 3

CloseMethod · 0.95
CopyMethod · 0.80
UpdateMethod · 0.65

Tested by

no test coverage detected