diff --git a/core/services/job/models.go b/core/services/job/models.go index e7c88d1822c..c35548041dc 100644 --- a/core/services/job/models.go +++ b/core/services/job/models.go @@ -883,6 +883,7 @@ type WorkflowSpec struct { SpecType WorkflowSpecType `toml:"spec_type" db:"spec_type"` sdkWorkflow *sdk.WorkflowSpec rawSpec []byte + config []byte } var ( @@ -949,6 +950,25 @@ func (w *WorkflowSpec) RawSpec(ctx context.Context) ([]byte, error) { return rs, nil } +func (w *WorkflowSpec) GetConfig(ctx context.Context) ([]byte, error) { + if w.config != nil { + return w.config, nil + } + + workflowSpecFactory, ok := workflowSpecFactories[w.SpecType] + if !ok { + return nil, fmt.Errorf("unknown spec type %s", w.SpecType) + } + + rs, err := workflowSpecFactory.Config(ctx, w.Config) + if err != nil { + return nil, err + } + + w.config = rs + return rs, nil +} + type OracleFactoryConfig struct { Enabled bool `toml:"enabled"` BootstrapPeers []string `toml:"bootstrap_peers"` // e.g.,["12D3KooWEBVwbfdhKnicois7FTYVsBFGFcoMhMCKXQC57BQyZMhz@localhost:6690"] diff --git a/core/services/job/wasm_file_spec_factory.go b/core/services/job/wasm_file_spec_factory.go index 247cd057582..eb952a47c89 100644 --- a/core/services/job/wasm_file_spec_factory.go +++ b/core/services/job/wasm_file_spec_factory.go @@ -22,7 +22,7 @@ import ( type WasmFileSpecFactory struct{} func (w WasmFileSpecFactory) Spec(ctx context.Context, workflow, configLocation string) (sdk.WorkflowSpec, []byte, string, error) { - config, err := os.ReadFile(configLocation) + config, err := w.Config(ctx, configLocation) if err != nil { return sdk.WorkflowSpec{}, nil, "", err } @@ -43,8 +43,8 @@ func (w WasmFileSpecFactory) Spec(ctx context.Context, workflow, configLocation return *spec, compressedBinary, sha, nil } -func (w WasmFileSpecFactory) RawSpec(_ context.Context, workflow, configLocation string) ([]byte, error) { - config, err := os.ReadFile(configLocation) +func (w WasmFileSpecFactory) RawSpec(ctx context.Context, workflow, configLocation string) ([]byte, error) { + config, err := w.Config(ctx, configLocation) if err != nil { return nil, err } @@ -53,6 +53,15 @@ func (w WasmFileSpecFactory) RawSpec(_ context.Context, workflow, configLocation return raw, err } +func (w WasmFileSpecFactory) Config(_ context.Context, configLocation string) ([]byte, error) { + config, err := os.ReadFile(configLocation) + if err != nil { + return nil, err + } + + return config, nil +} + // rawSpecAndSha returns the brotli compressed version of the raw wasm file, alongside the sha256 hash of the raw wasm file func (w WasmFileSpecFactory) rawSpecAndSha(wf string, config []byte) ([]byte, string, error) { read, err := os.ReadFile(wf) diff --git a/core/services/job/wasm_file_spec_factory_test.go b/core/services/job/wasm_file_spec_factory_test.go index cbc4cb6b32e..bf078a8026e 100644 --- a/core/services/job/wasm_file_spec_factory_test.go +++ b/core/services/job/wasm_file_spec_factory_test.go @@ -77,6 +77,14 @@ func TestWasmFileSpecFactory(t *testing.T) { assert.Equal(t, b.Bytes(), rawSpec) }) + + t.Run("Config", func(t *testing.T) { + factory := job.WasmFileSpecFactory{} + actual, err3 := factory.Config(testutils.Context(t), configLocation) + require.NoError(t, err3) + + assert.Equal(t, config, actual) + }) } func createTestBinary(t *testing.T) string { diff --git a/core/services/job/workflow_spec_factory.go b/core/services/job/workflow_spec_factory.go index 031e62a3c26..c799b69823e 100644 --- a/core/services/job/workflow_spec_factory.go +++ b/core/services/job/workflow_spec_factory.go @@ -9,6 +9,7 @@ import ( type WorkflowSpecFactory interface { Spec(ctx context.Context, workflow, config string) (sdk.WorkflowSpec, []byte, string, error) RawSpec(ctx context.Context, workflow, config string) ([]byte, error) + Config(ctx context.Context, config string) ([]byte, error) } var workflowSpecFactories = map[WorkflowSpecType]WorkflowSpecFactory{ diff --git a/core/services/job/yaml_spec_factory.go b/core/services/job/yaml_spec_factory.go index 41548968cf6..92df8a6ed0c 100644 --- a/core/services/job/yaml_spec_factory.go +++ b/core/services/job/yaml_spec_factory.go @@ -21,3 +21,7 @@ func (y YAMLSpecFactory) Spec(_ context.Context, workflow, _ string) (sdk.Workfl func (y YAMLSpecFactory) RawSpec(_ context.Context, workflow, _ string) ([]byte, error) { return []byte(workflow), nil } + +func (y YAMLSpecFactory) Config(_ context.Context, config string) ([]byte, error) { + return []byte(config), nil +} diff --git a/core/services/job/yaml_spec_factory_test.go b/core/services/job/yaml_spec_factory_test.go index ac127b321a0..91b1257a6b6 100644 --- a/core/services/job/yaml_spec_factory_test.go +++ b/core/services/job/yaml_spec_factory_test.go @@ -77,3 +77,12 @@ func TestYamlSpecFactory_GetSpec(t *testing.T) { assert.Equal(t, fmt.Sprintf("%x", sha256.Sum256([]byte(anyYamlSpec))), actualSha) assert.Equal(t, anyYamlSpec, string(raw)) } + +func TestYamlSpecFactory_Config(t *testing.T) { + t.Parallel() + + config := "config" + actual, err := job.YAMLSpecFactory{}.Config(testutils.Context(t), config) + require.NoError(t, err) + assert.Equal(t, []byte(config), actual) +} diff --git a/core/services/workflows/delegate.go b/core/services/workflows/delegate.go index 266402c9afb..8289671916e 100644 --- a/core/services/workflows/delegate.go +++ b/core/services/workflows/delegate.go @@ -47,6 +47,11 @@ func (d *Delegate) ServicesForSpec(ctx context.Context, spec job.Job) ([]job.Ser return nil, err } + config, err := spec.WorkflowSpec.GetConfig(ctx) + if err != nil { + return nil, err + } + cfg := Config{ Lggr: d.logger, Workflow: sdkSpec, @@ -55,7 +60,7 @@ func (d *Delegate) ServicesForSpec(ctx context.Context, spec job.Job) ([]job.Ser WorkflowName: spec.WorkflowSpec.WorkflowName, Registry: d.registry, Store: d.store, - Config: []byte(spec.WorkflowSpec.Config), + Config: config, Binary: binary, SecretsFetcher: d.secretsFetcher, }