mirror of
https://github.com/portainer/portainer.git
synced 2025-07-19 13:29:41 +02:00
* refactor(auth): move auth helpers to internal package * refactor(edge-compute): move edge helpers to internal package * refactor(tags): move tags helper to internal package * style(portainer): sort imports
45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
package endpointgroups
|
|
|
|
import (
|
|
portainer "github.com/portainer/portainer/api"
|
|
"github.com/portainer/portainer/api/internal/edge"
|
|
)
|
|
|
|
func (handler *Handler) updateEndpointRelations(endpoint *portainer.Endpoint, endpointGroup *portainer.EndpointGroup) error {
|
|
if endpoint.Type != portainer.EdgeAgentEnvironment {
|
|
return nil
|
|
}
|
|
|
|
if endpointGroup == nil {
|
|
unassignedGroup, err := handler.DataStore.EndpointGroup().EndpointGroup(portainer.EndpointGroupID(1))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
endpointGroup = unassignedGroup
|
|
}
|
|
|
|
endpointRelation, err := handler.DataStore.EndpointRelation().EndpointRelation(endpoint.ID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
edgeGroups, err := handler.DataStore.EdgeGroup().EdgeGroups()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
edgeStacks, err := handler.DataStore.EdgeStack().EdgeStacks()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
endpointStacks := edge.EndpointRelatedEdgeStacks(endpoint, endpointGroup, edgeGroups, edgeStacks)
|
|
stacksSet := map[portainer.EdgeStackID]bool{}
|
|
for _, edgeStackID := range endpointStacks {
|
|
stacksSet[edgeStackID] = true
|
|
}
|
|
endpointRelation.EdgeStacks = stacksSet
|
|
|
|
return handler.DataStore.EndpointRelation().UpdateEndpointRelation(endpoint.ID, endpointRelation)
|
|
}
|