Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions pkg/app/pipedv1/plugin/analysis/executestage/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"maps"
"time"

"github.com/creasty/defaults"
sdk "github.com/pipe-cd/piped-plugin-sdk-go"
"go.uber.org/zap"
"golang.org/x/sync/errgroup"
Expand Down Expand Up @@ -51,9 +52,25 @@ type executor struct {
previousElapsedTime time.Duration
}

// decodeStageConfig decodes the raw JSON data and validates it.
func decodeStageConfig(data json.RawMessage) (*config.AnalysisStageOptions, error) {
var opts config.AnalysisStageOptions
if err := json.Unmarshal(data, &opts); err != nil {
return nil, fmt.Errorf("failed to unmarshal the stage config: %w", err)
}
if err := defaults.Set(&opts); err != nil {
return nil, fmt.Errorf("failed to set default values for stage config: %w", err)
}
if err := opts.Validate(); err != nil {
return nil, fmt.Errorf("failed to validate the stage config: %w", err)
}
return &opts, nil
}

func ExecuteAnalysisStage(ctx context.Context, input *sdk.ExecuteStageInput[config.AnalysisApplicationSpec], pluginCfg *config.PluginConfig) sdk.StageStatus {
stageCfg := &config.AnalysisStageOptions{}
if err := json.Unmarshal(input.Request.StageConfig, stageCfg); err != nil {
stageCfg, err := decodeStageConfig(input.Request.StageConfig)
if err != nil {
input.Client.LogPersister().Errorf("failed to decode the stage config: %v", err)
return sdk.StageStatusFailure
}
resultStore := analysisresultstore.NewStore(input.Client, input.Logger)
Expand Down
4 changes: 4 additions & 0 deletions pkg/app/pipedv1/plugin/wait/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"encoding/json"
"fmt"

"github.com/creasty/defaults"
"github.com/pipe-cd/piped-plugin-sdk-go/unit"
)

Expand All @@ -39,6 +40,9 @@ func decode(data json.RawMessage) (WaitStageOptions, error) {
if err := json.Unmarshal(data, &opts); err != nil {
return WaitStageOptions{}, fmt.Errorf("failed to unmarshal the config: %w", err)
}
if err := defaults.Set(&opts); err != nil {
return WaitStageOptions{}, fmt.Errorf("failed to set default values for stage config: %w", err)
}
if err := opts.validate(); err != nil {
return WaitStageOptions{}, fmt.Errorf("failed to validate the config: %w", err)
}
Expand Down