* Enable gossip encryption

* Fix order

* Auto-generate key

* Update gorp fork to include BeginTx

* Add a test for InsertIfExists

And point gorp to a custom branch for now

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Agniva De Sarker
2020-06-03 14:16:15 +05:30
коммит произвёл GitHub
родитель fc028e703a
Коммит e3255879ba
51 изменённых файлов: 12514 добавлений и 6755 удалений

Просмотреть файл

@@ -4,6 +4,8 @@
package sqlstore
import (
"context"
"database/sql"
"net/http"
"github.com/mattermost/mattermost-server/v5/model"
@@ -86,3 +88,37 @@ func (s SqlSystemStore) PermanentDeleteByName(name string) (*model.System, *mode
return &system, nil
}
// InsertIfExists inserts a given system value if it does not already exist. If a value
// already exists, it returns the old one, else returns the new one.
func (s SqlSystemStore) InsertIfExists(system *model.System) (*model.System, *model.AppError) {
tx, err := s.GetMaster().BeginTx(context.Background(), &sql.TxOptions{
Isolation: sql.LevelSerializable,
})
if err != nil {
return nil, model.NewAppError("SqlSystemStore.InsertIfExists", "store.sql_system.save.app_error", nil, err.Error(), http.StatusInternalServerError)
}
defer finalizeTransaction(tx)
var origSystem model.System
if err := tx.SelectOne(&origSystem, `SELECT * FROM Systems
WHERE Name = :Name`,
map[string]interface{}{"Name": system.Name}); err != nil && err != sql.ErrNoRows {
return nil, model.NewAppError("SqlSystemStore.InsertIfExists", "store.sql_system.get_by_name.app_error", nil, err.Error(), http.StatusInternalServerError)
}
if origSystem.Value != "" {
// Already a value exists, return that.
return &origSystem, nil
}
// Key does not exist, need to insert.
if err := tx.Insert(system); err != nil {
return nil, model.NewAppError("SqlSystemStore.InsertIfExists", "store.sql_system.save.app_error", nil, err.Error(), http.StatusInternalServerError)
}
if err := tx.Commit(); err != nil {
return nil, model.NewAppError("SqlSystemStore.InsertIfExists", "store.sql_system.save.commit_transaction.app_error", nil, err.Error(), http.StatusInternalServerError)
}
return system, nil
}