MCPcopy Create free account
hub / github.com/OpenAtomFoundation/SmartIDE / getRemote

Function getRemote

cli/internal/dal/remote.go:220–275  ·  view source on GitHub ↗
(remoteId int, host string, userName string)

Source from the content-addressed store, hash-verified

218}
219
220func getRemote(remoteId int, host string, userName string) (remoteInfo *workspace.RemoteInfo, err error) {
221
222 db := getDb()
223 defer db.Close()
224
225 do := remoteDO{}
226
227 var row *sql.Row
228 if len(host) > 0 {
229 row = db.QueryRow(`select r_id, r_addr, r_port, r_username, r_auth_type, r_password, r_created
230 from remote
231 where r_addr=? and r_username = ? and r_is_del = 0`, host, userName)
232 } else if remoteId > 0 {
233 row = db.QueryRow(`select r_id, r_addr, r_port, r_username, r_auth_type, r_password, r_created
234 from remote where r_id=? and r_is_del = 0`, remoteId)
235 } else {
236 return
237 }
238
239 switch err := row.Scan(&do.r_id, &do.r_addr, &do.r_port, &do.r_username, &do.r_auth_type, &do.r_password, &do.r_created); err {
240 case sql.ErrNoRows:
241 msg := fmt.Sprintf("host (%v | %v)", host, remoteId)
242 common.SmartIDELog.WarningF(i18nInstance.Common.Warn_dal_record_not_exit_condition, msg) // 不存在
243 case nil:
244 remoteInfo = &workspace.RemoteInfo{}
245 remoteInfo.ID = do.r_id
246 remoteInfo.Addr = do.r_addr
247 remoteInfo.UserName = do.r_username
248 if do.r_auth_type == string(workspace.RemoteAuthType_SSH) {
249 remoteInfo.AuthType = workspace.RemoteAuthType_SSH
250 } else if do.r_auth_type == string(workspace.RemoteAuthType_Password) {
251 remoteInfo.AuthType = workspace.RemoteAuthType_Password
252 } else {
253 panic(do.r_auth_type + i18nInstance.Common.Err_enum_error) // 不能被识别
254 }
255
256 if int(do.r_port.Int32) > 0 {
257 remoteInfo.SSHPort = int(do.r_port.Int32)
258 } else {
259 remoteInfo.SSHPort = 22
260 }
261
262 if do.r_password.Valid && len(do.r_password.String) > 0 {
263 passwordDecrypt := aes4go.Decrypt(do.r_password.String, aesDecryptKey)
264 remoteInfo.Password = passwordDecrypt
265 }
266
267 remoteInfo.CreatedTime = do.r_created
268 //remote.CreatedTime = r_id
269
270 default:
271 panic(err)
272 }
273
274 return
275}

Callers 3

GetRemoteByIdFunction · 0.85
GetRemoteByHostFunction · 0.85

Calls 2

getDbFunction · 0.85
WarningFMethod · 0.80

Tested by

no test coverage detected