-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathremoteConnectionConfigRepository.go
More file actions
49 lines (43 loc) · 1.6 KB
/
remoteConnectionConfigRepository.go
File metadata and controls
49 lines (43 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package sql
import (
"github.com/devtron-labs/common-lib/securestore"
"github.com/go-pg/pg"
"go.uber.org/zap"
)
type RemoteConnectionConfig struct {
tableName struct{} `sql:"remote_connection_config" pg:",discard_unknown_columns"`
Id int `sql:"id,pk"`
ConnectionMethod string `sql:"connection_method"`
ProxyUrl string `sql:"proxy_url"`
SSHServerAddress string `sql:"ssh_server_address"`
SSHUsername string `sql:"ssh_username"`
SSHPassword securestore.EncryptedString `sql:"ssh_password"`
SSHAuthKey securestore.EncryptedString `sql:"ssh_auth_key"`
Deleted bool `sql:"deleted,notnull"`
AuditLog
}
type RemoteConnectionRepository interface {
GetById(id int) (*RemoteConnectionConfig, error)
}
type RemoteConnectionRepositoryImpl struct {
logger *zap.SugaredLogger
dbConnection *pg.DB
}
func NewRemoteConnectionRepositoryImpl(dbConnection *pg.DB, logger *zap.SugaredLogger) *RemoteConnectionRepositoryImpl {
return &RemoteConnectionRepositoryImpl{
logger: logger,
dbConnection: dbConnection,
}
}
func (repo *RemoteConnectionRepositoryImpl) GetById(id int) (*RemoteConnectionConfig, error) {
model := &RemoteConnectionConfig{}
err := repo.dbConnection.Model(model).
Where("id = ?", id).
Where("deleted = ?", false).
Select()
if err != nil && err != pg.ErrNoRows {
repo.logger.Errorw("error in getting remote connection config", "err", err, "id", id)
return nil, err
}
return model, nil
}