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

View File

@ -1,6 +1,10 @@
package main package main
import "encoding/json" import (
"encoding/json"
"github.com/rosti-cz/node-api/apps"
)
// Path where authorized keys are // Path where authorized keys are
const sshPubKeysLocation = "/srv/.ssh/authorized_keys" const sshPubKeysLocation = "/srv/.ssh/authorized_keys"
@ -60,3 +64,12 @@ type QuickServices struct {
Memcached bool `json:"memcached"` Memcached bool `json:"memcached"`
Redis bool `json:"redis"` 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