diff --git a/common/configuration/dal/dal_test.go b/common/configuration/dal/dal_test.go index 6b4434cedb..4016e51720 100644 --- a/common/configuration/dal/dal_test.go +++ b/common/configuration/dal/dal_test.go @@ -101,3 +101,16 @@ func TestModuleConfiguration(t *testing.T) { } }) } + +func TestModuleSecrets(t *testing.T) { + ctx := log.ContextWithNewDefaultLogger(context.Background()) + conn := sqltest.OpenForTesting(ctx, t) + dal, err := New(ctx, conn) + assert.NoError(t, err) + assert.NotZero(t, dal) + + err = dal.SetModuleSecretURL(ctx, optional.Some("echo"), "my_secret", "asm://echo.my_secret") + assert.NoError(t, err) + err = dal.SetModuleSecretURL(ctx, optional.Some("echo"), "my_secret", "asm://echo.my_secret") + assert.NoError(t, err) +} diff --git a/common/configuration/sql/queries.sql b/common/configuration/sql/queries.sql index d90ffbd02e..9bcbaed4e2 100644 --- a/common/configuration/sql/queries.sql +++ b/common/configuration/sql/queries.sql @@ -36,8 +36,9 @@ ORDER BY module, name; -- name: SetModuleSecretURL :exec INSERT INTO module_secrets (module, name, url) -VALUES ($1, $2, $3); +VALUES ($1, $2, $3) +ON CONFLICT (module, name) DO UPDATE SET url = $3; -- name: UnsetModuleSecret :exec DELETE FROM module_secrets -WHERE module = @module AND name = @name; \ No newline at end of file +WHERE module = @module AND name = @name; diff --git a/common/configuration/sql/queries.sql.go b/common/configuration/sql/queries.sql.go index 35850ae4e5..5086e3f57e 100644 --- a/common/configuration/sql/queries.sql.go +++ b/common/configuration/sql/queries.sql.go @@ -122,6 +122,7 @@ func (q *Queries) SetModuleConfiguration(ctx context.Context, module optional.Op const setModuleSecretURL = `-- name: SetModuleSecretURL :exec INSERT INTO module_secrets (module, name, url) VALUES ($1, $2, $3) +ON CONFLICT (module, name) DO UPDATE SET url = $3 ` func (q *Queries) SetModuleSecretURL(ctx context.Context, module optional.Option[string], name string, url string) error {