Encapsulate snapshot list replies with key
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Adam Štrauch 2021-10-30 13:17:33 +02:00
parent 615029f6c0
commit 81bcdcf00c
Signed by: cx
GPG key ID: 018304FFA8988F8D
2 changed files with 41 additions and 4 deletions

View file

@ -902,8 +902,16 @@ func listSnapshotsEventHandler(m *nats.Msg, message *RequestMessage) error {
return errorReplyFormater(m, "backend error", err)
}
var output SnapshotsMetadata
for _, snapshot := range snapshots {
output = append(output, SnapshotMetadata{
Key: snapshot.KeyName(),
Metadata: snapshot,
})
}
reply := ReplyMessage{
Payload: snapshots,
Payload: output,
}
data, err := json.Marshal(reply)
@ -943,8 +951,16 @@ func listAppsSnapshotsEventHandler(m *nats.Msg, message *RequestMessage) error {
return errorReplyFormater(m, "backend error", err)
}
var output SnapshotsMetadata
for _, snapshot := range snapshots {
output = append(output, SnapshotMetadata{
Key: snapshot.KeyName(),
Metadata: snapshot,
})
}
reply := ReplyMessage{
Payload: snapshots,
Payload: output,
}
data, err := json.Marshal(reply)
@ -984,8 +1000,16 @@ func listSnapshotsByLabelEventHandler(m *nats.Msg, message *RequestMessage) erro
return errorReplyFormater(m, "backend error", err)
}
var output SnapshotsMetadata
for _, snapshot := range snapshots {
output = append(output, SnapshotMetadata{
Key: snapshot.KeyName(),
Metadata: snapshot,
})
}
reply := ReplyMessage{
Payload: snapshots,
Payload: output,
}
data, err := json.Marshal(reply)

View file

@ -1,6 +1,10 @@
package main
import "encoding/json"
import (
"encoding/json"
"github.com/rosti-cz/node-api/apps"
)
// Path where authorized keys are
const sshPubKeysLocation = "/srv/.ssh/authorized_keys"
@ -60,3 +64,12 @@ type QuickServices struct {
Memcached bool `json:"memcached"`
Redis bool `json:"redis"`
}
// SnapshotMetadata is snapshot structure encapsulation that combines key and metadata about the snapshot
type SnapshotMetadata struct {
Key string `json:"key"`
Metadata apps.Snapshot `json:"metadata"`
}
// SnapshotsMetadata is returned by handlers
type SnapshotsMetadata []SnapshotMetadata