2023-02-20 16:11:18 -03:00
|
|
|
package snapshot
|
|
|
|
|
|
|
|
import (
|
|
|
|
portainer "github.com/portainer/portainer/api"
|
2023-06-20 17:51:34 -03:00
|
|
|
"github.com/portainer/portainer/api/dataservices"
|
2023-02-20 16:11:18 -03:00
|
|
|
)
|
|
|
|
|
|
|
|
type ServiceTx struct {
|
2023-06-22 18:28:07 -03:00
|
|
|
dataservices.BaseDataServiceTx[portainer.Snapshot, portainer.EndpointID]
|
2023-02-20 16:11:18 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (service ServiceTx) Create(snapshot *portainer.Snapshot) error {
|
2023-06-22 18:28:07 -03:00
|
|
|
return service.Tx.CreateObjectWithId(BucketName, int(snapshot.EndpointID), snapshot)
|
2023-02-20 16:11:18 -03:00
|
|
|
}
|
2025-03-24 19:33:05 -03:00
|
|
|
|
|
|
|
func (service ServiceTx) ReadWithoutSnapshotRaw(ID portainer.EndpointID) (*portainer.Snapshot, error) {
|
|
|
|
var snapshot struct {
|
|
|
|
Docker *struct {
|
|
|
|
X struct{} `json:"DockerSnapshotRaw"`
|
|
|
|
*portainer.DockerSnapshot
|
|
|
|
} `json:"Docker"`
|
|
|
|
|
|
|
|
portainer.Snapshot
|
|
|
|
}
|
|
|
|
|
|
|
|
identifier := service.Connection.ConvertToKey(int(ID))
|
|
|
|
|
|
|
|
if err := service.Tx.GetObject(service.Bucket, identifier, &snapshot); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if snapshot.Docker != nil {
|
|
|
|
snapshot.Snapshot.Docker = snapshot.Docker.DockerSnapshot
|
|
|
|
}
|
|
|
|
|
|
|
|
return &snapshot.Snapshot, nil
|
|
|
|
}
|
2025-05-23 12:42:45 +12:00
|
|
|
|
|
|
|
func (service ServiceTx) ReadRawMessage(ID portainer.EndpointID) (*portainer.SnapshotRawMessage, error) {
|
|
|
|
var snapshot = portainer.SnapshotRawMessage{}
|
|
|
|
|
|
|
|
identifier := service.Connection.ConvertToKey(int(ID))
|
|
|
|
|
|
|
|
if err := service.Tx.GetObject(service.Bucket, identifier, &snapshot); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &snapshot, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (service ServiceTx) CreateRawMessage(snapshot *portainer.SnapshotRawMessage) error {
|
|
|
|
return service.Tx.CreateObjectWithId(BucketName, int(snapshot.EndpointID), snapshot)
|
|
|
|
}
|