REST API dumpdata: allow to specify the resources to dump

Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
Nicola Murino
2023-04-18 18:11:23 +02:00
parent 54462c26f2
commit 712f2053a4
15 changed files with 363 additions and 91 deletions

View File

@@ -51,6 +51,7 @@ func validateBackupFile(outputFile string) (string, error) {
func dumpData(w http.ResponseWriter, r *http.Request) {
r.Body = http.MaxBytesReader(w, r.Body, maxRequestSize)
var outputFile, outputData, indent string
var scopes []string
if _, ok := r.URL.Query()["output-file"]; ok {
outputFile = strings.TrimSpace(r.URL.Query().Get("output-file"))
}
@@ -60,6 +61,9 @@ func dumpData(w http.ResponseWriter, r *http.Request) {
if _, ok := r.URL.Query()["indent"]; ok {
indent = strings.TrimSpace(r.URL.Query().Get("indent"))
}
if _, ok := r.URL.Query()["scopes"]; ok {
scopes = getCommaSeparatedQueryParam(r, "scopes")
}
if outputData != "1" {
var err error
@@ -78,7 +82,7 @@ func dumpData(w http.ResponseWriter, r *http.Request) {
logger.Debug(logSender, "", "dumping data to: %q", outputFile)
}
backup, err := dataprovider.DumpData()
backup, err := dataprovider.DumpData(scopes)
if err != nil {
logger.Error(logSender, "", "dumping data error: %v, output file: %q", err, outputFile)
sendAPIResponse(w, r, err, "", getRespStatus(err))