mirror of
https://github.com/cloudflare/redoctober.git
synced 2026-05-28 18:50:38 +00:00
Merge pull request #66 from cloudflare/kyle/export
Add export endpoint, permitting backing up the vault.
This commit is contained in:
29
core/core.go
29
core/core.go
@@ -85,6 +85,11 @@ type ModifyRequest struct {
|
||||
Command string
|
||||
}
|
||||
|
||||
type ExportRequest struct {
|
||||
Name string
|
||||
Password string
|
||||
}
|
||||
|
||||
// These structures map the JSON responses that will be sent from the API
|
||||
|
||||
type ResponseData struct {
|
||||
@@ -421,3 +426,27 @@ func Owners(jsonIn []byte) ([]byte, error) {
|
||||
|
||||
return json.Marshal(OwnersData{Status: "ok", Owners: names})
|
||||
}
|
||||
|
||||
// Export returns a backed up vault.
|
||||
func Export(jsonIn []byte) ([]byte, error) {
|
||||
var req ExportRequest
|
||||
err := json.Unmarshal(jsonIn, &req)
|
||||
if err != nil {
|
||||
log.Println("Error unmarshaling input:", err)
|
||||
return jsonStatusError(err)
|
||||
}
|
||||
|
||||
err = validateUser(req.Name, req.Password, true)
|
||||
if err != nil {
|
||||
log.Println("Unauthorized attempt to export disk records")
|
||||
return jsonStatusError(err)
|
||||
}
|
||||
|
||||
out, err := json.Marshal(records)
|
||||
if err != nil {
|
||||
log.Println("Error exporting vault:", err)
|
||||
return jsonStatusError(err)
|
||||
}
|
||||
|
||||
return jsonResponse(out)
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ var functions = map[string]func([]byte) ([]byte, error){
|
||||
"/decrypt": core.Decrypt,
|
||||
"/owners": core.Owners,
|
||||
"/modify": core.Modify,
|
||||
"/export": core.Export,
|
||||
}
|
||||
|
||||
type userRequest struct {
|
||||
|
||||
Reference in New Issue
Block a user