From 93f0d7f9d63b71febb51a9f245d5333fe3ff1ba5 Mon Sep 17 00:00:00 2001 From: Denise Li Date: Wed, 29 May 2024 14:35:37 -0400 Subject: [PATCH] fix: query ModuleConfiguration via DAL (#1601) Fixes https://github.com/TBD54566975/ftl/pull/1570#discussion_r1618128693 --- backend/controller/dal/dal.go | 26 ++++++++++++++++++++++++++ backend/controller/dal/dal_test.go | 16 ++++++++-------- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/backend/controller/dal/dal.go b/backend/controller/dal/dal.go index 1b1ef7e324..7720c6ce42 100644 --- a/backend/controller/dal/dal.go +++ b/backend/controller/dal/dal.go @@ -1147,6 +1147,32 @@ func (d *DAL) GetActiveRunners(ctx context.Context) ([]Runner, error) { }), nil } +func (d *DAL) GetModuleConfiguration(ctx context.Context, module optional.Option[string], name string) ([]byte, error) { + b, err := d.db.GetModuleConfiguration(ctx, module, name) + if err != nil { + return nil, translatePGError(err) + } + return b, nil +} + +func (d *DAL) SetModuleConfiguration(ctx context.Context, module optional.Option[string], name string, value []byte) error { + err := d.db.SetModuleConfiguration(ctx, module, name, value) + return translatePGError(err) +} + +func (d *DAL) UnsetModuleConfiguration(ctx context.Context, module optional.Option[string], name string) error { + err := d.db.UnsetModuleConfiguration(ctx, module, name) + return translatePGError(err) +} + +func (d *DAL) ListModuleConfiguration(ctx context.Context) ([]sql.ModuleConfiguration, error) { + l, err := d.db.ListModuleConfiguration(ctx) + if err != nil { + return nil, translatePGError(err) + } + return l, nil +} + // Check if a deployment exists that exactly matches the given artefacts and schema. func (*DAL) checkForExistingDeployments(ctx context.Context, tx *sql.Tx, moduleSchema *schema.Module, artefacts []DeploymentArtefact) (model.DeploymentKey, error) { schemaBytes, err := schema.ModuleToBytes(moduleSchema) diff --git a/backend/controller/dal/dal_test.go b/backend/controller/dal/dal_test.go index 7de4d2e6e2..ab99868a2e 100644 --- a/backend/controller/dal/dal_test.go +++ b/backend/controller/dal/dal_test.go @@ -445,15 +445,15 @@ func TestModuleConfiguration(t *testing.T) { for _, test := range tests { t.Run(test.TestName, func(t *testing.T) { if test.PresetGlobal { - err := dal.db.SetModuleConfiguration(ctx, optional.None[string](), "configname", []byte(`"qwerty"`)) + err := dal.SetModuleConfiguration(ctx, optional.None[string](), "configname", []byte(`"qwerty"`)) assert.NoError(t, err) } - err := dal.db.SetModuleConfiguration(ctx, test.ModuleSet, "configname", b) + err := dal.SetModuleConfiguration(ctx, test.ModuleSet, "configname", b) assert.NoError(t, err) - gotBytes, err := dal.db.GetModuleConfiguration(ctx, test.ModuleGet, "configname") + gotBytes, err := dal.GetModuleConfiguration(ctx, test.ModuleGet, "configname") assert.NoError(t, err) assert.Equal(t, b, gotBytes) - err = dal.db.UnsetModuleConfiguration(ctx, test.ModuleGet, "configname") + err = dal.UnsetModuleConfiguration(ctx, test.ModuleGet, "configname") assert.NoError(t, err) }) } @@ -476,14 +476,14 @@ func TestModuleConfiguration(t *testing.T) { // Insert entries in a separate order from how they should be returned to // test sorting logic in the SQL query - err := dal.db.SetModuleConfiguration(ctx, sortedList[1].Module, sortedList[1].Name, []byte(`""`)) + err := dal.SetModuleConfiguration(ctx, sortedList[1].Module, sortedList[1].Name, []byte(`""`)) assert.NoError(t, err) - err = dal.db.SetModuleConfiguration(ctx, sortedList[2].Module, sortedList[2].Name, []byte(`""`)) + err = dal.SetModuleConfiguration(ctx, sortedList[2].Module, sortedList[2].Name, []byte(`""`)) assert.NoError(t, err) - err = dal.db.SetModuleConfiguration(ctx, sortedList[0].Module, sortedList[0].Name, []byte(`""`)) + err = dal.SetModuleConfiguration(ctx, sortedList[0].Module, sortedList[0].Name, []byte(`""`)) assert.NoError(t, err) - gotList, err := dal.db.ListModuleConfiguration(ctx) + gotList, err := dal.ListModuleConfiguration(ctx) assert.NoError(t, err) for i := range sortedList { assert.Equal(t, sortedList[i].Module, gotList[i].Module)