-
Notifications
You must be signed in to change notification settings - Fork 416
/
application_export.go
46 lines (40 loc) · 1.04 KB
/
application_export.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package api
import (
"context"
"net/http"
"github.com/gorilla/mux"
"github.com/ovh/cds/engine/api/application"
"github.com/ovh/cds/engine/api/project"
"github.com/ovh/cds/engine/service"
"github.com/ovh/cds/sdk"
"github.com/ovh/cds/sdk/exportentities"
)
func (api *API) getApplicationExportHandler() service.Handler {
return func(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
vars := mux.Vars(r)
key := vars[permProjectKey]
appName := vars["applicationName"]
format := FormString(r, "format")
if format == "" {
format = "yaml"
}
f, err := exportentities.GetFormat(format)
if err != nil {
return err
}
app, err := application.Export(ctx, api.mustDB(), key, appName, project.EncryptWithBuiltinKey)
if err != nil {
return sdk.WithStack(err)
}
buf, err := exportentities.Marshal(app, f)
if err != nil {
return err
}
if _, err := w.Write(buf); err != nil {
return sdk.WithStack(err)
}
w.Header().Add("Content-Type", f.ContentType())
w.WriteHeader(http.StatusOK)
return nil
}
}