mirror of
https://github.com/portainer/portainer.git
synced 2025-08-07 14:55:27 +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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue