53 lines
1.3 KiB
Go
53 lines
1.3 KiB
Go
package store
|
|
|
|
import (
|
|
"encoding/json"
|
|
"linkport/internal/model"
|
|
)
|
|
|
|
func (s *Store) UpdateOutboundProject(id, project string) (model.OutboundProfile, error) {
|
|
var profile model.OutboundProfile
|
|
if err := model.ValidateScope(project, ""); err != nil {
|
|
return profile, err
|
|
}
|
|
transaction, err := s.db.Begin()
|
|
if err != nil {
|
|
return profile, err
|
|
}
|
|
defer transaction.Rollback()
|
|
var blob []byte
|
|
if err = transaction.QueryRow("SELECT config FROM outbounds WHERE id=?", id).Scan(&blob); err != nil {
|
|
return profile, err
|
|
}
|
|
var config map[string]json.RawMessage
|
|
if err = s.unseal(blob, "outbound:"+id, &config); err != nil {
|
|
return profile, err
|
|
}
|
|
if err = s.recordHistory(transaction, "outbounds", id); err != nil {
|
|
return profile, err
|
|
}
|
|
config["project"], err = json.Marshal(project)
|
|
if err != nil {
|
|
return profile, err
|
|
}
|
|
blob, err = s.seal(config, "outbound:"+id)
|
|
if err != nil {
|
|
return profile, err
|
|
}
|
|
result, err := transaction.Exec("UPDATE outbounds SET config=? WHERE id=?", blob, id)
|
|
if err != nil {
|
|
return profile, err
|
|
}
|
|
count, err := result.RowsAffected()
|
|
if err != nil {
|
|
return profile, err
|
|
}
|
|
if count != 1 {
|
|
return profile, ErrConfigurationChanged
|
|
}
|
|
if err = s.unseal(blob, "outbound:"+id, &profile); err != nil {
|
|
return profile, err
|
|
}
|
|
return profile, transaction.Commit()
|
|
}
|