2022-01-23 19:48:04 +00:00
|
|
|
package fdoprofile
|
|
|
|
|
|
|
|
import (
|
|
|
|
portainer "github.com/portainer/portainer/api"
|
2023-06-20 20:51:34 +00:00
|
|
|
"github.com/portainer/portainer/api/dataservices"
|
2022-01-23 19:48:04 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
// BucketName represents the name of the bucket where this service stores data.
|
|
|
|
BucketName = "fdo_profiles"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Service represents a service for managingFDO Profiles data.
|
|
|
|
type Service struct {
|
|
|
|
connection portainer.Connection
|
|
|
|
}
|
|
|
|
|
|
|
|
func (service *Service) BucketName() string {
|
|
|
|
return BucketName
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewService creates a new instance of a service.
|
|
|
|
func NewService(connection portainer.Connection) (*Service, error) {
|
|
|
|
err := connection.SetServiceName(BucketName)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &Service{
|
|
|
|
connection: connection,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// FDOProfiles return an array containing all the FDO Profiles.
|
|
|
|
func (service *Service) FDOProfiles() ([]portainer.FDOProfile, error) {
|
|
|
|
var fdoProfiles = make([]portainer.FDOProfile, 0)
|
|
|
|
|
2023-06-20 20:51:34 +00:00
|
|
|
return fdoProfiles, service.connection.GetAll(
|
2022-01-23 19:48:04 +00:00
|
|
|
BucketName,
|
|
|
|
&portainer.FDOProfile{},
|
2023-06-20 20:51:34 +00:00
|
|
|
dataservices.AppendFn(&fdoProfiles),
|
|
|
|
)
|
2022-01-23 19:48:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// FDOProfile returns an FDO Profile by ID.
|
|
|
|
func (service *Service) FDOProfile(ID portainer.FDOProfileID) (*portainer.FDOProfile, error) {
|
|
|
|
var FDOProfile portainer.FDOProfile
|
|
|
|
identifier := service.connection.ConvertToKey(int(ID))
|
|
|
|
|
|
|
|
err := service.connection.GetObject(BucketName, identifier, &FDOProfile)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &FDOProfile, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create assign an ID to a new FDO Profile and saves it.
|
|
|
|
func (service *Service) Create(FDOProfile *portainer.FDOProfile) error {
|
|
|
|
return service.connection.CreateObjectWithId(
|
|
|
|
BucketName,
|
|
|
|
int(FDOProfile.ID),
|
|
|
|
FDOProfile,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update updates an FDO Profile.
|
|
|
|
func (service *Service) Update(ID portainer.FDOProfileID, FDOProfile *portainer.FDOProfile) error {
|
|
|
|
identifier := service.connection.ConvertToKey(int(ID))
|
|
|
|
return service.connection.UpdateObject(BucketName, identifier, FDOProfile)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete deletes an FDO Profile.
|
|
|
|
func (service *Service) Delete(ID portainer.FDOProfileID) error {
|
|
|
|
identifier := service.connection.ConvertToKey(int(ID))
|
|
|
|
return service.connection.DeleteObject(BucketName, identifier)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetNextIdentifier returns the next identifier for a FDO Profile.
|
|
|
|
func (service *Service) GetNextIdentifier() int {
|
|
|
|
return service.connection.GetNextIdentifier(BucketName)
|
|
|
|
}
|