Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit 10af0b9

Browse files
committed
oneclickexport: add code host configs export functionality.
1 parent e9fa12c commit 10af0b9

File tree

3 files changed

+437
-36
lines changed

3 files changed

+437
-36
lines changed

cmd/frontend/oneclickexport/export.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package oneclickexport
33
import (
44
"archive/zip"
55
"bytes"
6+
"context"
67
"io"
78
"io/ioutil"
89
"os"
@@ -14,7 +15,7 @@ import (
1415
type Exporter interface {
1516
// Export function accepts an ExportRequest and returns bytes of a zip archive
1617
// with requested data
17-
Export(request *ExportRequest) ([]byte, error)
18+
Export(ctx context.Context, request *ExportRequest) ([]byte, error)
1819
}
1920

2021
var _ Exporter = &OneClickExporter{}
@@ -25,15 +26,16 @@ type OneClickExporter struct {
2526
}
2627

2728
type ExportRequest struct {
28-
IncludeSiteConfig bool `json:"includeSiteConfig"`
29+
IncludeSiteConfig bool `json:"includeSiteConfig"`
30+
IncludeCodeHostConfig bool `json:"includeCodeHostConfig"`
2931
}
3032

3133
// Export generates and returns a ZIP archive with the data, specified in request.
3234
// It works like this:
3335
// 1) tmp directory is created (exported files will end up in this directory and this directory is zipped in the end)
3436
// 2) ExportRequest is read and each corresponding processor is invoked
3537
// 3) Tmp directory is zipped after all the Processors finished their job
36-
func (e *OneClickExporter) Export(request *ExportRequest) ([]byte, error) {
38+
func (e *OneClickExporter) Export(ctx context.Context, request *ExportRequest) ([]byte, error) {
3739
// 1) creating a tmp dir
3840
dir, err := ioutil.TempDir(os.TempDir(), "export-*")
3941
if err != nil {
@@ -43,7 +45,10 @@ func (e *OneClickExporter) Export(request *ExportRequest) ([]byte, error) {
4345

4446
// 2) tmp dir is passed to every processor
4547
if request.IncludeSiteConfig {
46-
e.cfgProcessors["siteConfig"].Process(&ConfigRequest{}, dir)
48+
e.cfgProcessors["siteConfig"].Process(ctx, &ConfigRequest{}, dir)
49+
}
50+
if request.IncludeCodeHostConfig {
51+
e.cfgProcessors["codeHostConfig"].Process(ctx, &ConfigRequest{}, dir)
4752
}
4853

4954
// 3) after all request parts are processed, zip the tmp dir and return its bytes

0 commit comments

Comments
 (0)