mirror of
https://github.com/portainer/portainer.git
synced 2025-07-25 08:19:40 +02:00
fix(pendingactions): refactor pending actions [EE-7011] (#11780)
Some checks are pending
ci / build_images (map[arch:amd64 platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
ci / build_images (map[arch:arm platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:arm64 platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:ppc64le platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:s390x platform:linux version:]) (push) Waiting to run
ci / build_manifests (push) Blocked by required conditions
/ triage (push) Waiting to run
Lint / Run linters (push) Waiting to run
Test / test-client (push) Waiting to run
Test / test-server (map[arch:amd64 platform:linux]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
Test / test-server (map[arch:arm64 platform:linux]) (push) Waiting to run
Some checks are pending
ci / build_images (map[arch:amd64 platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
ci / build_images (map[arch:arm platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:arm64 platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:ppc64le platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:s390x platform:linux version:]) (push) Waiting to run
ci / build_manifests (push) Blocked by required conditions
/ triage (push) Waiting to run
Lint / Run linters (push) Waiting to run
Test / test-client (push) Waiting to run
Test / test-server (map[arch:amd64 platform:linux]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
Test / test-server (map[arch:arm64 platform:linux]) (push) Waiting to run
This commit is contained in:
parent
9685e260ea
commit
5a5a10821d
20 changed files with 380 additions and 293 deletions
50
api/pending_action.go
Normal file
50
api/pending_action.go
Normal file
|
@ -0,0 +1,50 @@
|
|||
package portainer
|
||||
|
||||
import "github.com/segmentio/encoding/json"
|
||||
|
||||
type (
|
||||
PendingActionID int
|
||||
PendingAction struct {
|
||||
ID PendingActionID `json:"ID"`
|
||||
EndpointID EndpointID `json:"EndpointID"`
|
||||
Action string `json:"Action"`
|
||||
ActionData any `json:"ActionData"`
|
||||
CreatedAt int64 `json:"CreatedAt"`
|
||||
}
|
||||
|
||||
PendingActionHandler interface {
|
||||
Execute(PendingAction, *Endpoint) error
|
||||
}
|
||||
)
|
||||
|
||||
// MarshalJSON marshals the PendingAction struct to JSON
|
||||
// and converts the ActionData field to an embedded json string
|
||||
// This makes unmarshalling the ActionData field easier
|
||||
func (pa PendingAction) MarshalJSON() ([]byte, error) {
|
||||
// Create a map to hold the marshalled fields
|
||||
data := map[string]any{
|
||||
"ID": pa.ID,
|
||||
"EndpointID": pa.EndpointID,
|
||||
"Action": pa.Action,
|
||||
"CreatedAt": pa.CreatedAt,
|
||||
}
|
||||
|
||||
actionDataBytes, err := json.Marshal(pa.ActionData)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
data["ActionData"] = string(actionDataBytes)
|
||||
|
||||
// Marshal the map
|
||||
return json.Marshal(data)
|
||||
}
|
||||
|
||||
// Unmarshal the ActionData field from a string to a specific type.
|
||||
func (pa PendingAction) UnmarshallActionData(v any) error {
|
||||
s, ok := pa.ActionData.(string)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
return json.Unmarshal([]byte(s), v)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue