diff --git a/pkg/repository/testworkflow/mongo.go b/pkg/repository/testworkflow/mongo.go index 6535316c8a..860715d6c6 100644 --- a/pkg/repository/testworkflow/mongo.go +++ b/pkg/repository/testworkflow/mongo.go @@ -64,15 +64,22 @@ type MongoRepositoryOpt func(*MongoRepository) func (r *MongoRepository) Get(ctx context.Context, id string) (result testkube.TestWorkflowExecution, err error) { err = r.Coll.FindOne(ctx, bson.M{"$or": bson.A{bson.M{"id": id}, bson.M{"name": id}}}).Decode(&result) - if result.ResolvedWorkflow != nil && result.ResolvedWorkflow.Spec != nil && result.ConfigParams != nil { - r.populateConfigParams(result.ResolvedWorkflow, result.ConfigParams) + if result.ResolvedWorkflow != nil && result.ResolvedWorkflow.Spec != nil { + result.ConfigParams = populateConfigParams(result.ResolvedWorkflow, result.ConfigParams) } return *result.UnscapeDots(), err } -func (r *MongoRepository) populateConfigParams(resolvedWorkflow *testkube.TestWorkflow, configParams map[string]testkube.TestWorkflowExecutionConfigValue) { +func populateConfigParams(resolvedWorkflow *testkube.TestWorkflow, configParams map[string]testkube.TestWorkflowExecutionConfigValue) map[string]testkube.TestWorkflowExecutionConfigValue { + if configParams == nil { + configParams = make(map[string]testkube.TestWorkflowExecutionConfigValue) + } + for k, v := range resolvedWorkflow.Spec.Config { + if v.Sensitive { + return nil + } if v.Default_ != nil { if _, ok := configParams[k]; !ok { configParams[k] = testkube.TestWorkflowExecutionConfigValue{ @@ -93,7 +100,8 @@ func (r *MongoRepository) populateConfigParams(resolvedWorkflow *testkube.TestWo } } } - return + + return configParams } func (r *MongoRepository) GetByNameAndTestWorkflow(ctx context.Context, name, workflowName string) (result testkube.TestWorkflowExecution, err error) { @@ -303,8 +311,8 @@ func (r *MongoRepository) GetExecutionsSummary(ctx context.Context, filter Filte for i := range executions { executions[i].UnscapeDots() - if executions[i].ResolvedWorkflow != nil && executions[i].ResolvedWorkflow.Spec != nil && executions[i].ConfigParams != nil { - r.populateConfigParams(executions[i].ResolvedWorkflow, executions[i].ConfigParams) + if executions[i].ResolvedWorkflow != nil && executions[i].ResolvedWorkflow.Spec != nil { + executions[i].ConfigParams = populateConfigParams(executions[i].ResolvedWorkflow, executions[i].ConfigParams) } result[i] = executions[i].TestWorkflowExecutionSummary } diff --git a/pkg/repository/testworkflow/mongo_integration_test.go b/pkg/repository/testworkflow/mongo_integration_test.go index d227f100a7..cc209f7a91 100644 --- a/pkg/repository/testworkflow/mongo_integration_test.go +++ b/pkg/repository/testworkflow/mongo_integration_test.go @@ -562,4 +562,76 @@ func TestNewMongoRepository_Get_Integration(t *testing.T) { assert.Equal(t, "default", result.ConfigParams["param1"].DefaultValue) assert.Equal(t, false, result.ConfigParams["param1"].Truncated) + execution2 := testkube.TestWorkflowExecution{ + Id: "test-id-2", + Name: "test-name-2", + Workflow: &testkube.TestWorkflow{ + Name: "test-workflow-2", + Spec: &testkube.TestWorkflowSpec{}, + }, + ResolvedWorkflow: &testkube.TestWorkflow{ + Name: "test-workflow-2", + Spec: &testkube.TestWorkflowSpec{ + Config: map[string]testkube.TestWorkflowParameterSchema{ + "param2": { + Default_: &testkube.BoxedString{ + Value: "default", + }, + }, + "param1": { + Default_: &testkube.BoxedString{ + Value: "default", + }, + Sensitive: true, + }, + }, + }, + }, + } + err = repo.Insert(ctx, execution2) + assert.NoError(t, err) + + result, err = repo.Get(ctx, "test-id-2") + assert.NoError(t, err) + + assert.Equal(t, execution2.Id, result.Id) + assert.Equal(t, execution2.Name, result.Name) + assert.Nil(t, result.ConfigParams) + + execution3 := testkube.TestWorkflowExecution{ + Id: "test-id-3", + Name: "test-name-3", + Workflow: &testkube.TestWorkflow{ + Name: "test-workflow-3", + Spec: &testkube.TestWorkflowSpec{}, + }, + ResolvedWorkflow: &testkube.TestWorkflow{ + Name: "test-workflow-2", + Spec: &testkube.TestWorkflowSpec{ + Config: map[string]testkube.TestWorkflowParameterSchema{ + "param2": { + Default_: &testkube.BoxedString{ + Value: "default", + }, + }, + "param1": { + Default_: &testkube.BoxedString{ + Value: "default", + }, + Sensitive: true, + }, + }, + }, + }, + ConfigParams: map[string]testkube.TestWorkflowExecutionConfigValue{}, + } + err = repo.Insert(ctx, execution3) + assert.NoError(t, err) + + result, err = repo.Get(ctx, "test-id-3") + assert.NoError(t, err) + + assert.Equal(t, execution3.Id, result.Id) + assert.Equal(t, execution3.Name, result.Name) + assert.Nil(t, result.ConfigParams) }