mirror of
https://github.com/drakkan/sftpgo.git
synced 2025-12-06 22:30:56 +03:00
WebAdmin: add configs section
Setting configurations is an experimental feature and is not currently supported in the REST API Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
@@ -35,7 +35,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
sqlDatabaseVersion = 27
|
||||
sqlDatabaseVersion = 28
|
||||
defaultSQLQueryTimeout = 10 * time.Second
|
||||
longSQLQueryTimeout = 60 * time.Second
|
||||
)
|
||||
@@ -81,6 +81,7 @@ func sqlReplaceAll(sql string) string {
|
||||
sql = strings.ReplaceAll(sql, "{{nodes}}", sqlTableNodes)
|
||||
sql = strings.ReplaceAll(sql, "{{roles}}", sqlTableRoles)
|
||||
sql = strings.ReplaceAll(sql, "{{ip_lists}}", sqlTableIPLists)
|
||||
sql = strings.ReplaceAll(sql, "{{configs}}", sqlTableConfigs)
|
||||
sql = strings.ReplaceAll(sql, "{{prefix}}", config.SQLTablesPrefix)
|
||||
return sql
|
||||
}
|
||||
@@ -3825,6 +3826,43 @@ func sqlCommonCleanupNodes(dbHandle *sql.DB) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func sqlCommonGetConfigs(dbHandle sqlQuerier) (Configs, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), defaultSQLQueryTimeout)
|
||||
defer cancel()
|
||||
|
||||
var result Configs
|
||||
var configs []byte
|
||||
q := getConfigsQuery()
|
||||
err := dbHandle.QueryRowContext(ctx, q).Scan(&configs)
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
err = json.Unmarshal(configs, &result)
|
||||
return result, err
|
||||
}
|
||||
|
||||
func sqlCommonSetConfigs(configs *Configs, dbHandle *sql.DB) error {
|
||||
if err := configs.validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
asJSON, err := json.Marshal(configs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), defaultSQLQueryTimeout)
|
||||
defer cancel()
|
||||
|
||||
q := getUpdateConfigsQuery()
|
||||
res, err := dbHandle.ExecContext(ctx, q, asJSON)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if config.Driver == MySQLDataProviderName {
|
||||
return nil
|
||||
}
|
||||
return sqlCommonRequireRowAffected(res)
|
||||
}
|
||||
|
||||
func sqlCommonGetDatabaseVersion(dbHandle sqlQuerier, showInitWarn bool) (schemaVersion, error) {
|
||||
var result schemaVersion
|
||||
ctx, cancel := context.WithTimeout(context.Background(), defaultSQLQueryTimeout)
|
||||
|
||||
Reference in New Issue
Block a user