@@ -22,6 +22,7 @@ import (
2222 "maps"
2323 "time"
2424
25+ "github.com/creasty/defaults"
2526 sdk "github.com/pipe-cd/piped-plugin-sdk-go"
2627 "go.uber.org/zap"
2728 "golang.org/x/sync/errgroup"
@@ -51,9 +52,25 @@ type executor struct {
5152 previousElapsedTime time.Duration
5253}
5354
55+ // decodeStageConfig decodes the raw JSON data and validates it.
56+ func decodeStageConfig (data json.RawMessage ) (* config.AnalysisStageOptions , error ) {
57+ var opts config.AnalysisStageOptions
58+ if err := json .Unmarshal (data , & opts ); err != nil {
59+ return nil , fmt .Errorf ("failed to unmarshal the stage config: %w" , err )
60+ }
61+ if err := defaults .Set (& opts ); err != nil {
62+ return nil , fmt .Errorf ("failed to set default values for stage config: %w" , err )
63+ }
64+ if err := opts .Validate (); err != nil {
65+ return nil , fmt .Errorf ("failed to validate the stage config: %w" , err )
66+ }
67+ return & opts , nil
68+ }
69+
5470func ExecuteAnalysisStage (ctx context.Context , input * sdk.ExecuteStageInput [config.AnalysisApplicationSpec ], pluginCfg * config.PluginConfig ) sdk.StageStatus {
55- stageCfg := & config.AnalysisStageOptions {}
56- if err := json .Unmarshal (input .Request .StageConfig , stageCfg ); err != nil {
71+ stageCfg , err := decodeStageConfig (input .Request .StageConfig )
72+ if err != nil {
73+ input .Client .LogPersister ().Errorf ("failed to decode the stage config: %v" , err )
5774 return sdk .StageStatusFailure
5875 }
5976 resultStore := analysisresultstore .NewStore (input .Client , input .Logger )
0 commit comments