Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat: support render sql (#5759)
h3n4laf71344298f4
diff --git a/backend/api/v1/database_service.go b/backend/api/v1/database_service.goindex a2f89c9fc0..40f6572440 100644--- a/backend/api/v1/database_service.go+++ b/backend/api/v1/database_service.go@@ -552,8 +552,8 @@ func (s *DatabaseService) ListSecrets(ctx context.Context, request *v1pb.ListSec// UpdateSecret updates a secret of a database.func (s *DatabaseService) UpdateSecret(ctx context.Context, request *v1pb.UpdateSecretRequest) (*v1pb.Secret, error) {- if !s.licenseService.IsFeatureEnabled(api.FeatureEncryptedSecret) {- return nil, status.Errorf(codes.PermissionDenied, api.FeatureEncryptedSecret.AccessErrorMessage())+ if !s.licenseService.IsFeatureEnabled(api.FeatureEncryptedSecrets) {+ return nil, status.Errorf(codes.PermissionDenied, api.FeatureEncryptedSecrets.AccessErrorMessage())}if request.Secret == nil {@@ -665,8 +665,8 @@ func (s *DatabaseService) UpdateSecret(ctx context.Context, request *v1pb.Update// DeleteSecret deletes a secret of a database.func (s *DatabaseService) DeleteSecret(ctx context.Context, request *v1pb.DeleteSecretRequest) (*emptypb.Empty, error) {- if !s.licenseService.IsFeatureEnabled(api.FeatureEncryptedSecret) {- return nil, status.Errorf(codes.PermissionDenied, api.FeatureEncryptedSecret.AccessErrorMessage())+ if !s.licenseService.IsFeatureEnabled(api.FeatureEncryptedSecrets) {+ return nil, status.Errorf(codes.PermissionDenied, api.FeatureEncryptedSecrets.AccessErrorMessage())}environmentID, instanceID, databaseName, secretName, err := getEnvironmentInstanceDatabaseIDSecretName(request.Name)diff --git a/backend/legacyapi/plan.go b/backend/legacyapi/plan.goindex 95320cb78a..cd6ee665fa 100644--- a/backend/legacyapi/plan.go+++ b/backend/legacyapi/plan.go@@ -116,8 +116,8 @@ const (FeatureSQLReview FeatureType = "bb.feature.sql-review"// FeatureTaskScheduleTime allows user to run task at a scheduled time.FeatureTaskScheduleTime FeatureType = "bb.feature.task-schedule-time"- // FeatureEncryptedSecret is a feature that allows user to setting the secrets for the database.- FeatureEncryptedSecret FeatureType = "bb.feature.secret"+ // FeatureEncryptedSecrets is a feature that allows user to setting the encrypted secrets for the database.+ FeatureEncryptedSecrets FeatureType = "bb.feature.encrypted-secrets"// VCS Integration.@@ -209,8 +209,8 @@ func (e FeatureType) Name() string {return "SQL review"case FeatureTaskScheduleTime:return "Task schedule time"- case FeatureEncryptedSecret:- return "Encrypted secret"+ case FeatureEncryptedSecrets:+ return "Encrypted secrets"// VCS Integrationcase FeatureVCSSchemaWriteBack:return "Schema write-back"@@ -286,7 +286,7 @@ var FeatureMatrix = map[FeatureType][3]bool{FeatureSchemaDrift: {false, false, true},FeatureSQLReview: {true, true, true},FeatureTaskScheduleTime: {false, true, true},- FeatureEncryptedSecret: {false, true, true},+ FeatureEncryptedSecrets: {false, true, true},// VCS IntegrationFeatureVCSSchemaWriteBack: {false, true, true},FeatureVCSSheetSync: {false, true, true},diff --git a/backend/runner/taskcheck/ghost_sync_executor.go b/backend/runner/taskcheck/ghost_sync_executor.goindex 1f57cac2eb..968b5d92c5 100644--- a/backend/runner/taskcheck/ghost_sync_executor.go+++ b/backend/runner/taskcheck/ghost_sync_executor.go@@ -78,12 +78,16 @@ func (e *GhostSyncExecutor) Run(ctx context.Context, _ *store.TaskCheckRunMessagreturn nil, common.Wrapf(err, common.Internal, "invalid database schema update gh-ost sync payload")}- tableName, err := utils.GetTableNameFromStatement(payload.Statement)+ materials := utils.GetSecretMapFromDatabaseMessage(database)+ // To avoid leaking the rendered statement, the error message should use the original statement and not the rendered statement.+ renderedStatement := utils.RenderStatement(payload.Statement, materials)++ tableName, err := utils.GetTableNameFromStatement(renderedStatement)if err != nil {return nil, common.Wrapf(err, common.Internal, "failed to parse table name from statement, statement: %v", payload.Statement)}- config, err := utils.GetGhostConfig(task.ID, database, adminDataSource, e.secret, instanceUsers, tableName, payload.Statement, true, 20000000)+ config, err := utils.GetGhostConfig(task.ID, database, adminDataSource, e.secret, instanceUsers, tableName, renderedStatement, true, 20000000)if err != nil {return nil, err}diff --git a/backend/runner/taskcheck/statement_advisor_composite_executor.go b/backend/runner/taskcheck/statement_advisor_composite_executor.goindex 348b21effb..2ea9af4612 100644--- a/backend/runner/taskcheck/statement_advisor_composite_executor.go+++ b/backend/runner/taskcheck/statement_advisor_composite_executor.go@@ -12,6 +12,7 @@ import ("github.com/bytebase/bytebase/backend/plugin/advisor"advisorDB "github.com/bytebase/bytebase/backend/plugin/advisor/db""github.com/bytebase/bytebase/backend/store"+ "github.com/bytebase/bytebase/backend/utils")// SQL review policy consists of a list of SQL review rules.@@ -111,7 +112,10 @@ func (e *StatementAdvisorCompositeExecutor) Run(ctx context.Context, taskCheckRudefer driver.Close(ctx)connection := driver.GetDB()- adviceList, err := advisor.SQLReviewCheck(payload.Statement, policy.RuleList, advisor.SQLReviewCheckContext{+ materials := utils.GetSecretMapFromDatabaseMessage(database)+ // To avoid leaking the rendered statement, the error message should use the original statement and not the rendered statement.+ renderedStatement := utils.RenderStatement(payload.Statement, materials)+ adviceList, err := advisor.SQLReviewCheck(renderedStatement, policy.RuleList, advisor.SQLReviewCheckContext{Charset: dbSchema.Metadata.CharacterSet,Collation: dbSchema.Metadata.Collation,DbType: dbType,diff --git a/backend/runner/taskcheck/statement_advisor_simple_executor.go b/backend/runner/taskcheck/statement_advisor_simple_executor.goindex ca87e75650..4745315452 100644--- a/backend/runner/taskcheck/statement_advisor_simple_executor.go+++ b/backend/runner/taskcheck/statement_advisor_simple_executor.go@@ -10,6 +10,7 @@ import (advisorDB "github.com/bytebase/bytebase/backend/plugin/advisor/db""github.com/bytebase/bytebase/backend/plugin/db""github.com/bytebase/bytebase/backend/store"+ "github.com/bytebase/bytebase/backend/utils")// NewStatementAdvisorSimpleExecutor creates a task check statement simple advisor executor.@@ -74,6 +75,10 @@ func (e *StatementAdvisorSimpleExecutor) Run(ctx context.Context, taskCheckRun *return nil, err}+ materials := utils.GetSecretMapFromDatabaseMessage(database)+ // To avoid leaking the rendered statement, the error message should use the original statement and not the rendered statement.+ renderedStatement := utils.RenderStatement(payload.Statement, materials)+adviceList, err := advisor.Check(dbType,advisorType,@@ -82,7 +87,7 @@ func (e *StatementAdvisorSimpleExecutor) Run(ctx context.Context, taskCheckRun *Collation: dbSchema.Metadata.Collation,SyntaxMode: task.GetSyntaxMode(),},- payload.Statement,+ renderedStatement,)if err != nil {return nil, common.Wrapf(err, common.Internal, "failed to check statement")diff --git a/backend/runner/taskcheck/statement_affected_rows_report_executor.go b/backend/runner/taskcheck/statement_affected_rows_report_executor.goindex 9e5f5c535d..ce94f08cf3 100644--- a/backend/runner/taskcheck/statement_affected_rows_report_executor.go+++ b/backend/runner/taskcheck/statement_affected_rows_report_executor.go@@ -21,6 +21,7 @@ import ("github.com/bytebase/bytebase/backend/plugin/parser""github.com/bytebase/bytebase/backend/plugin/parser/ast""github.com/bytebase/bytebase/backend/store"+ "github.com/bytebase/bytebase/backend/utils")// NewStatementAffectedRowsReportExecutor creates a task check statement affected rows report executor.@@ -78,12 +79,16 @@ func (s *StatementAffectedRowsReportExecutor) Run(ctx context.Context, _ *store.}defer driver.Close(ctx)+ materials := utils.GetSecretMapFromDatabaseMessage(database)+ // To avoid leaking the rendered statement, the error message should use the original statement and not the rendered statement.+ renderedStatement := utils.RenderStatement(payload.Statement, materials)+sqlDB := driver.GetDB()switch instance.Engine {case db.Postgres:- return reportStatementAffectedRowsForPostgres(ctx, sqlDB, payload.Statement)+ return reportStatementAffectedRowsForPostgres(ctx, sqlDB, renderedStatement)case db.MySQL:- return reportStatementAffectedRowsForMySQL(ctx, sqlDB, payload.Statement, dbSchema.Metadata.CharacterSet, dbSchema.Metadata.Collation)+ return reportStatementAffectedRowsForMySQL(ctx, sqlDB, renderedStatement, dbSchema.Metadata.CharacterSet, dbSchema.Metadata.Collation)default:return nil, errors.New("unsupported db type")}diff --git a/backend/runner/taskcheck/statement_type_executor.go b/backend/runner/taskcheck/statement_type_executor.goindex e520af2a4a..935bcebed3 100644--- a/backend/runner/taskcheck/statement_type_executor.go+++ b/backend/runner/taskcheck/statement_type_executor.go@@ -18,6 +18,7 @@ import ("github.com/bytebase/bytebase/backend/plugin/parser/ast""github.com/bytebase/bytebase/backend/runner/utils""github.com/bytebase/bytebase/backend/store"+ backendutils "github.com/bytebase/bytebase/backend/utils")// NewStatementTypeExecutor creates a task check DML executor.@@ -64,19 +65,23 @@ func (exec *StatementTypeExecutor) Run(ctx context.Context, _ *store.TaskCheckRu}, nil}+ materials := backendutils.GetSecretMapFromDatabaseMessage(database)+ // To avoid leaking the rendered statement, the error message should use the original statement and not the rendered statement.+ renderedStatement := backendutils.RenderStatement(payload.Statement, materials)+switch instance.Engine {case db.Postgres:- result, err = postgresqlStatementTypeCheck(payload.Statement, task.Type)+ result, err = postgresqlStatementTypeCheck(renderedStatement, task.Type)if err != nil {return nil, err}case db.MySQL, db.TiDB, db.MariaDB, db.OceanBase:- result, err = mysqlStatementTypeCheck(payload.Statement, dbSchema.Metadata.CharacterSet, dbSchema.Metadata.Collation, task.Type)+ result, err = mysqlStatementTypeCheck(renderedStatement, dbSchema.Metadata.CharacterSet, dbSchema.Metadata.Collation, task.Type)if err != nil {return nil, err}if task.Type == api.TaskDatabaseSchemaUpdateSDL {- sdlAdvice, err := exec.mysqlSDLTypeCheck(ctx, payload.Statement, task)+ sdlAdvice, err := exec.mysqlSDLTypeCheck(ctx, renderedStatement, task)if err != nil {return nil, err}diff --git a/backend/runner/taskcheck/statement_type_report_executor.go b/backend/runner/taskcheck/statement_type_report_executor.goindex 088b17156f..07cd70a8f0 100644--- a/backend/runner/taskcheck/statement_type_report_executor.go+++ b/backend/runner/taskcheck/statement_type_report_executor.go@@ -15,6 +15,7 @@ import ("github.com/bytebase/bytebase/backend/plugin/parser""github.com/bytebase/bytebase/backend/plugin/parser/ast""github.com/bytebase/bytebase/backend/store"+ "github.com/bytebase/bytebase/backend/utils")// NewStatementTypeReportExecutor creates a task check statement type report executor.@@ -66,11 +67,19 @@ func (s *StatementTypeReportExecutor) Run(ctx context.Context, _ *store.TaskCheccollation = dbSchema.Metadata.Collation}+ database, err := s.store.GetDatabaseV2(ctx, &store.FindDatabaseMessage{UID: task.DatabaseID})+ if err != nil {+ return nil, err+ }+ materials := utils.GetSecretMapFromDatabaseMessage(database)+ // To avoid leaking the rendered statement, the error message should use the original statement and not the rendered statement.+ renderedStatement := utils.RenderStatement(payload.Statement, materials)+switch instance.Engine {case db.Postgres:- return reportStatementTypeForPostgres(payload.Statement)+ return reportStatementTypeForPostgres(renderedStatement)case db.MySQL:- return reportStatementTypeForMySQL(payload.Statement, charset, collation)+ return reportStatementTypeForMySQL(renderedStatement, charset, collation)default:return nil, errors.New("unsupported db type")}diff --git a/backend/runner/taskrun/executor.go b/backend/runner/taskrun/executor.goindex bc5cb59edb..75c35b5b25 100644--- a/backend/runner/taskrun/executor.go+++ b/backend/runner/taskrun/executor.go@@ -567,6 +567,7 @@ func runMigration(ctx context.Context, store *store.Store, dbFactory *dbfactory.if err != nil {return true, nil, err}+migrationID, schema, err := executeMigration(ctx, store, dbFactory, stateCfg, task, statement, mi)if err != nil {return true, nil, errdiff --git a/backend/runner/taskrun/schema_update_ghost_cutover_executor.go b/backend/runner/taskrun/schema_update_ghost_cutover_executor.goindex 0c12209bfc..29800352e1 100644--- a/backend/runner/taskrun/schema_update_ghost_cutover_executor.go+++ b/backend/runner/taskrun/schema_update_ghost_cutover_executor.go@@ -123,7 +123,7 @@ func cutover(ctx context.Context, stores *store.Store, dbFactory *dbfactory.DBFareturn true, nil, err}- execFunc := func() error {+ execFunc := func(_ string) error {if err := os.Remove(postponeFilename); err != nil {return errors.Wrap(err, "failed to remove postpone flag file")}diff --git a/backend/runner/taskrun/schema_update_ghost_sync_executor.go b/backend/runner/taskrun/schema_update_ghost_sync_executor.goindex 5a73f51253..010332ea54 100644--- a/backend/runner/taskrun/schema_update_ghost_sync_executor.go+++ b/backend/runner/taskrun/schema_update_ghost_sync_executor.go@@ -53,6 +53,7 @@ func (exec *SchemaUpdateGhostSyncExecutor) RunOnce(ctx context.Context, task *st}statement = sheet.Statement}+return exec.runGhostMigration(ctx, exec.store, task, statement)}@@ -99,7 +100,11 @@ func (exec *SchemaUpdateGhostSyncExecutor) runGhostMigration(ctx context.Contextreturn true, nil, common.Errorf(common.Internal, "failed to find instance user by instanceID %d", task.InstanceID)}- config, err := utils.GetGhostConfig(task.ID, database, adminDataSource, exec.secret, instanceUsers, tableName, statement, false, 10000000)+ materials := utils.GetSecretMapFromDatabaseMessage(database)+ // To avoid leaking the rendered statement, the error message should use the original statement and not the rendered statement.+ renderedStatement := utils.RenderStatement(statement, materials)++ config, err := utils.GetGhostConfig(task.ID, database, adminDataSource, exec.secret, instanceUsers, tableName, renderedStatement, false, 10000000)if err != nil {return true, nil, err}diff --git a/backend/runner/taskrun/schema_update_sdl_executor.go b/backend/runner/taskrun/schema_update_sdl_executor.goindex f446e3d648..5f20b88568 100644--- a/backend/runner/taskrun/schema_update_sdl_executor.go+++ b/backend/runner/taskrun/schema_update_sdl_executor.go@@ -18,6 +18,7 @@ import ("github.com/bytebase/bytebase/backend/runner/schemasync""github.com/bytebase/bytebase/backend/runner/utils""github.com/bytebase/bytebase/backend/store"+ backendutils "github.com/bytebase/bytebase/backend/utils")// NewSchemaUpdateSDLExecutor creates a schema update (SDL) task executor.@@ -72,7 +73,11 @@ func (exec *SchemaUpdateSDLExecutor) RunOnce(ctx context.Context, task *store.Tareturn true, nil, err}- ddl, err := utils.ComputeDatabaseSchemaDiff(ctx, instance, database.DatabaseName, exec.dbFactory, statement)+ materials := backendutils.GetSecretMapFromDatabaseMessage(database)+ // To avoid leaking the rendered statement, the error message should use the original statement and not the rendered statement.+ renderedStatement := backendutils.RenderStatement(statement, materials)++ ddl, err := utils.ComputeDatabaseSchemaDiff(ctx, instance, database.DatabaseName, exec.dbFactory, renderedStatement)if err != nil {return true, nil, errors.Wrap(err, "invalid database schema diff")}diff --git a/backend/utils/utils.go b/backend/utils/utils.goindex e6c1f2664d..bdddbf4365 100644--- a/backend/utils/utils.go+++ b/backend/utils/utils.go@@ -7,6 +7,7 @@ import ("database/sql""encoding/json""fmt"+ "regexp""sort""strconv""strings"@@ -475,17 +476,17 @@ func passCheck(taskCheckRunList []*store.TaskCheckRunMessage, checkType api.Task// ExecuteMigrationDefault executes migration.func ExecuteMigrationDefault(ctx context.Context, store *store.Store, driver db.Driver, mi *db.MigrationInfo, statement string, executeBeforeCommitTx func(tx *sql.Tx) error) (migrationHistoryID string, updatedSchema string, resErr error) {- execFunc := func() error {+ execFunc := func(execStatement string) error {if driver.GetType() == db.Oracle && executeBeforeCommitTx != nil {oracleDriver, ok := driver.(*oracle.Driver)if !ok {return errors.New("failed to cast driver to oracle driver")}- if _, _, err := oracleDriver.ExecuteMigrationWithBeforeCommitTxFunc(ctx, statement, executeBeforeCommitTx); err != nil {+ if _, _, err := oracleDriver.ExecuteMigrationWithBeforeCommitTxFunc(ctx, execStatement, executeBeforeCommitTx); err != nil {return err}} else {- if _, err := driver.Execute(ctx, statement, false /* createDatabase */); err != nil {+ if _, err := driver.Execute(ctx, execStatement, false /* createDatabase */); err != nil {return err}}@@ -495,7 +496,7 @@ func ExecuteMigrationDefault(ctx context.Context, store *store.Store, driver db.}// ExecuteMigrationWithFunc executes the migration with custom migration function.-func ExecuteMigrationWithFunc(ctx context.Context, store *store.Store, driver db.Driver, m *db.MigrationInfo, statement string, execFunc func() error) (migrationHistoryID string, updatedSchema string, resErr error) {+func ExecuteMigrationWithFunc(ctx context.Context, s *store.Store, driver db.Driver, m *db.MigrationInfo, statement string, execFunc func(execStatement string) error) (migrationHistoryID string, updatedSchema string, resErr error) {var prevSchemaBuf bytes.Buffer// Don't record schema if the database hasn't existed yet or is schemaless, e.g. MongoDB.// For baseline migration, we also record the live schema to detect the schema drift.@@ -504,7 +505,7 @@ func ExecuteMigrationWithFunc(ctx context.Context, store *store.Store, driver dbreturn "", "", err}- insertedID, err := BeginMigration(ctx, store, m, prevSchemaBuf.String(), statement)+ insertedID, err := BeginMigration(ctx, s, m, prevSchemaBuf.String(), statement)if err != nil {if common.ErrorCode(err) == common.MigrationAlreadyApplied {return insertedID, prevSchemaBuf.String(), nil@@ -515,7 +516,7 @@ func ExecuteMigrationWithFunc(ctx context.Context, store *store.Store, driver dbstartedNs := time.Now().UnixNano()defer func() {- if err := EndMigration(ctx, store, startedNs, insertedID, updatedSchema, resErr == nil /* isDone */); err != nil {+ if err := EndMigration(ctx, s, startedNs, insertedID, updatedSchema, resErr == nil /* isDone */); err != nil {log.Error("Failed to update migration history record",zap.Error(err),zap.String("migration_id", migrationHistoryID),@@ -532,7 +533,23 @@ func ExecuteMigrationWithFunc(ctx context.Context, store *store.Store, driver dbdoMigrate = false}if doMigrate {- if err := execFunc(); err != nil {+ var renderedStatement = statement+ // The m.DatabaseID is nil means the migration is a instance level migration+ if m.DatabaseID != nil {+ database, err := s.GetDatabaseV2(ctx, &store.FindDatabaseMessage{+ UID: m.DatabaseID,+ })+ if err != nil {+ return "", "", err+ }+ if database == nil {+ return "", "", errors.Errorf("database %d not found", *m.DatabaseID)+ }+ materials := GetSecretMapFromDatabaseMessage(database)+ // To avoid leak the rendered statement, the error message should use the original statement and not the rendered statement.+ renderedStatement = RenderStatement(statement, materials)+ }+ if err := execFunc(renderedStatement); err != nil {return "", "", err}}@@ -768,3 +785,47 @@ func userCanApprove(step *storepb.ApprovalStep, users []*store.UserMessage, polifunc convertToRoleName(role api.Role) string {return fmt.Sprintf("roles/%s", role)}++// RenderStatement renders the given template statement with the given key-value map.+func RenderStatement(templateStatement string, secrets map[string]string) string {+ // Happy path for empty template statement.+ if templateStatement == "" {+ return ""+ }+ // Optimizations for databases without secrets.+ if len(secrets) == 0 {+ return templateStatement+ }+ // Don't render statement larger than 1MB.+ if len(templateStatement) > 1024*1024 {+ return templateStatement+ }++ // The regular expression consists of:+ // \${{: matches the string ${{, where $ is escaped with a backslash.+ // \s*: matches zero or more whitespace characters.+ // secrets\.: matches the string secrets., where . is escaped with a backslash.+ // (?P<name>[A-Z0-9_]+): uses a named capture group name to match the secret name. The capture group is defined using the syntax (?P<name>) and matches one or more uppercase letters, digits, or underscores.+ re := regexp.MustCompile(`\${{\s*secrets\.(?P<name>[A-Z0-9_]+)\s*}}`)+ matches := re.FindAllStringSubmatch(templateStatement, -1)+ for _, match := range matches {+ name := match[1]+ if value, ok := secrets[name]; ok {+ templateStatement = strings.ReplaceAll(templateStatement, match[0], value)+ }+ }+ return templateStatement+}++// GetSecretMapFromDatabaseMessage extracts the secret map from the given database message.+func GetSecretMapFromDatabaseMessage(databaseMessage *store.DatabaseMessage) map[string]string {+ materials := make(map[string]string)+ if databaseMessage.Secrets == nil || len(databaseMessage.Secrets.Items) == 0 {+ return materials+ }++ for _, item := range databaseMessage.Secrets.Items {+ materials[item.Name] = item.Value+ }+ return materials+}diff --git a/backend/utils/utils_test.go b/backend/utils/utils_test.goindex 09bff6fa70..74c8745d31 100644--- a/backend/utils/utils_test.go+++ b/backend/utils/utils_test.go@@ -364,3 +364,56 @@ func TestMergeTaskCreateLists(t *testing.T) {})}}++func TestGetRenderedStatement(t *testing.T) {+ testCases := []struct {+ material map[string]string+ template string+ expected string+ }{+ {+ material: map[string]string{+ "PASSWORD": "123",+ },+ template: "select * from table where password = ${{ secrets.PASSWORD }}",+ expected: "select * from table where password = 123",+ },+ {+ material: map[string]string{+ "PASSWORD": "123",+ "USER": `"abc"`,+ },+ template: "INSERT INTO table (user, password) VALUES (${{ secrets.USER }}, ${{ secrets.PASSWORD }})",+ expected: `INSERT INTO table (user, password) VALUES ("abc", 123)`,+ },+ // Replace recursively case.+ {+ material: map[string]string{+ "PASSWORD": "${{ secrets.USER }}",+ "USER": `"abc"`,+ },+ template: "INSERT INTO table (user, password) VALUES (${{ secrets.USER }}, ${{ secrets.PASSWORD }})",+ expected: `INSERT INTO table (user, password) VALUES ("abc", ${{ secrets.USER }})`,+ },+ {+ material: map[string]string{+ "PASSWORD": "123",+ "USER": `"${{ secrets.PASSWORD }}"`,+ },+ template: "INSERT INTO table (user, password) VALUES (${{ secrets.USER }}, ${{ secrets.PASSWORD }})",+ expected: `INSERT INTO table (user, password) VALUES ("123", 123)`,+ },+ {+ material: map[string]string{+ "USER": `"abc"`,+ },+ template: "select * from table where password = ${{ secrets.PASSWORD }}",+ expected: "select * from table where password = ${{ secrets.PASSWORD }}",+ },+ }++ for _, tc := range testCases {+ actual := RenderStatement(tc.template, tc.material)+ assert.Equal(t, tc.expected, actual)+ }+}