mirror of
https://github.com/openziti/ziti.git
synced 2026-10-22 11:46:01 +00:00
55 lines
1.7 KiB
Go
55 lines
1.7 KiB
Go
/*
|
|
Copyright 2019 Netfoundry, Inc.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package model
|
|
|
|
import (
|
|
"github.com/netfoundry/ziti-edge/edge/controller/persistence"
|
|
"github.com/netfoundry/ziti-foundation/storage/boltz"
|
|
"github.com/pkg/errors"
|
|
"go.etcd.io/bbolt"
|
|
"reflect"
|
|
)
|
|
|
|
type Cluster struct {
|
|
BaseModelEntityImpl
|
|
Name string `json:"name"`
|
|
}
|
|
|
|
func (entity *Cluster) ToBoltEntityForCreate(tx *bbolt.Tx, handler Handler) (persistence.BaseEdgeEntity, error) {
|
|
return &persistence.Cluster{
|
|
BaseEdgeEntityImpl: *persistence.NewBaseEdgeEntity(entity.Id, entity.Tags),
|
|
Name: entity.Name,
|
|
}, nil
|
|
}
|
|
|
|
func (entity *Cluster) ToBoltEntityForUpdate(tx *bbolt.Tx, handler Handler) (persistence.BaseEdgeEntity, error) {
|
|
return entity.ToBoltEntityForCreate(tx, handler)
|
|
}
|
|
|
|
func (entity *Cluster) ToBoltEntityForPatch(tx *bbolt.Tx, handler Handler) (persistence.BaseEdgeEntity, error) {
|
|
return entity.ToBoltEntityForCreate(tx, handler)
|
|
}
|
|
|
|
func (entity *Cluster) FillFrom(handler Handler, tx *bbolt.Tx, boltEntity boltz.BaseEntity) error {
|
|
boltCluster, ok := boltEntity.(*persistence.Cluster)
|
|
if !ok {
|
|
return errors.Errorf("unexpected type %v when filling model cluster", reflect.TypeOf(boltEntity))
|
|
}
|
|
entity.fillCommon(boltCluster)
|
|
entity.Name = boltCluster.Name
|
|
return nil
|
|
} |