mirror of
https://github.com/portainer/portainer.git
synced 2025-08-02 12:25:22 +02:00
feat(dataservices): abstract away some redundant code EE-5620 (#9110)
This commit is contained in:
parent
7dc6a1559f
commit
716c196682
33 changed files with 315 additions and 824 deletions
|
@ -1,17 +1,12 @@
|
|||
package customtemplate
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/portainer/portainer/api/dataservices"
|
||||
)
|
||||
|
||||
const (
|
||||
// BucketName represents the name of the bucket where this service stores data.
|
||||
BucketName = "customtemplates"
|
||||
)
|
||||
// BucketName represents the name of the bucket where this service stores data.
|
||||
const BucketName = "customtemplates"
|
||||
|
||||
// Service represents a service for managing custom template data.
|
||||
type Service struct {
|
||||
|
@ -38,22 +33,11 @@ func NewService(connection portainer.Connection) (*Service, error) {
|
|||
func (service *Service) CustomTemplates() ([]portainer.CustomTemplate, error) {
|
||||
var customTemplates = make([]portainer.CustomTemplate, 0)
|
||||
|
||||
err := service.connection.GetAll(
|
||||
return customTemplates, service.connection.GetAll(
|
||||
BucketName,
|
||||
&portainer.CustomTemplate{},
|
||||
func(obj interface{}) (interface{}, error) {
|
||||
//var tag portainer.Tag
|
||||
customTemplate, ok := obj.(*portainer.CustomTemplate)
|
||||
if !ok {
|
||||
log.Debug().Str("obj", fmt.Sprintf("%#v", obj)).Msg("failed to convert to CustomTemplate object")
|
||||
return nil, fmt.Errorf("Failed to convert to CustomTemplate object: %s", obj)
|
||||
}
|
||||
customTemplates = append(customTemplates, *customTemplate)
|
||||
|
||||
return &portainer.CustomTemplate{}, nil
|
||||
})
|
||||
|
||||
return customTemplates, err
|
||||
dataservices.AppendFn(&customTemplates),
|
||||
)
|
||||
}
|
||||
|
||||
// CustomTemplate returns an custom template by ID.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue