mirror of
https://github.com/portainer/portainer.git
synced 2025-08-05 13:55:21 +02:00
fix(pending-action): pending action data format [EE-7064] (#11766)
This commit is contained in:
parent
e75e6cb7f7
commit
f22aed34b5
4 changed files with 151 additions and 3 deletions
44
api/pendingactions/actions/converters.go
Normal file
44
api/pendingactions/actions/converters.go
Normal file
|
@ -0,0 +1,44 @@
|
|||
package actions
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
)
|
||||
|
||||
type (
|
||||
CleanNAPWithOverridePoliciesPayload struct {
|
||||
EndpointGroupID portainer.EndpointGroupID
|
||||
}
|
||||
)
|
||||
|
||||
func ConvertCleanNAPWithOverridePoliciesPayload(actionData interface{}) (*CleanNAPWithOverridePoliciesPayload, error) {
|
||||
var payload CleanNAPWithOverridePoliciesPayload
|
||||
|
||||
if actionData == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// backward compatible with old data format
|
||||
if endpointGroupId, ok := actionData.(float64); ok {
|
||||
payload.EndpointGroupID = portainer.EndpointGroupID(endpointGroupId)
|
||||
return &payload, nil
|
||||
}
|
||||
|
||||
data, ok := actionData.(map[string]interface{})
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("failed to convert actionData to map[string]interface{}")
|
||||
|
||||
}
|
||||
|
||||
for key, value := range data {
|
||||
switch key {
|
||||
case "EndpointGroupID":
|
||||
if endpointGroupID, ok := value.(float64); ok {
|
||||
payload.EndpointGroupID = portainer.EndpointGroupID(endpointGroupID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return &payload, nil
|
||||
}
|
|
@ -117,12 +117,18 @@ func (service *PendingActionsService) executePendingAction(pendingAction portain
|
|||
|
||||
switch pendingAction.Action {
|
||||
case actions.CleanNAPWithOverridePolicies:
|
||||
if (pendingAction.ActionData == nil) || (pendingAction.ActionData.(portainer.EndpointGroupID) == 0) {
|
||||
pendingActionData, err := actions.ConvertCleanNAPWithOverridePoliciesPayload(pendingAction.ActionData)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to parse pendingActionData for CleanNAPWithOverridePoliciesPayload")
|
||||
}
|
||||
|
||||
if pendingActionData == nil || pendingActionData.EndpointGroupID == 0 {
|
||||
service.authorizationService.CleanNAPWithOverridePolicies(service.dataStore, endpoint, nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
endpointGroupID := pendingAction.ActionData.(portainer.EndpointGroupID)
|
||||
endpointGroupID := pendingActionData.EndpointGroupID
|
||||
|
||||
endpointGroup, err := service.dataStore.EndpointGroup().Read(portainer.EndpointGroupID(endpointGroupID))
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msgf("Error reading environment group to clean NAP with override policies for environment %d and environment group %d", endpoint.ID, endpointGroup.ID)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue