2022-09-22 20:05:10 +00:00
|
|
|
package snapshot
|
|
|
|
|
|
|
|
import (
|
|
|
|
portainer "github.com/portainer/portainer/api"
|
2023-06-20 20:51:34 +00:00
|
|
|
"github.com/portainer/portainer/api/dataservices"
|
2022-09-22 20:05:10 +00:00
|
|
|
)
|
|
|
|
|
2023-10-23 18:52:37 +00:00
|
|
|
const BucketName = "snapshots"
|
2022-09-22 20:05:10 +00:00
|
|
|
|
|
|
|
type Service struct {
|
2023-06-22 21:28:07 +00:00
|
|
|
dataservices.BaseDataService[portainer.Snapshot, portainer.EndpointID]
|
2022-09-22 20:05:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewService(connection portainer.Connection) (*Service, error) {
|
|
|
|
err := connection.SetServiceName(BucketName)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &Service{
|
2023-06-22 21:28:07 +00:00
|
|
|
BaseDataService: dataservices.BaseDataService[portainer.Snapshot, portainer.EndpointID]{
|
|
|
|
Bucket: BucketName,
|
|
|
|
Connection: connection,
|
|
|
|
},
|
2022-09-22 20:05:10 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2023-02-20 19:11:18 +00:00
|
|
|
func (service *Service) Tx(tx portainer.Transaction) ServiceTx {
|
|
|
|
return ServiceTx{
|
2023-06-22 21:28:07 +00:00
|
|
|
BaseDataServiceTx: dataservices.BaseDataServiceTx[portainer.Snapshot, portainer.EndpointID]{
|
|
|
|
Bucket: BucketName,
|
|
|
|
Connection: service.Connection,
|
|
|
|
Tx: tx,
|
|
|
|
},
|
2022-09-22 20:05:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (service *Service) Create(snapshot *portainer.Snapshot) error {
|
2023-06-22 21:28:07 +00:00
|
|
|
return service.Connection.CreateObjectWithId(BucketName, int(snapshot.EndpointID), snapshot)
|
2022-09-22 20:05:10 +00:00
|
|
|
}
|