Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
refactor: use a map to indicate required token for tenant wildcard project (#2960)
Joe Chenfb2e87bf7b6d
diff --git a/api/project.go b/api/project.goindex 11e0fe499f..90dbf2d532 100644--- a/api/project.go+++ b/api/project.go@@ -156,7 +156,7 @@ var (// TenantToken is the token for tenant.TenantToken = "{{TENANT}}"- // boolean indicates whether it's an required or optional token.+ // boolean indicates whether it's a required or optional token.repositoryFilePathTemplateTokens = map[string]bool{"{{VERSION}}": true,DBNameToken: true,@@ -164,6 +164,13 @@ var (EnvironmentToken: false,"{{DESCRIPTION}}": false,}+ tenantWildcardRepositoryFilePathTemplateTokens = map[string]bool{+ "{{VERSION}}": true,+ DBNameToken: false,+ "{{TYPE}}": true,+ EnvironmentToken: false,+ "{{DESCRIPTION}}": false,+ }schemaPathTemplateTokens = map[string]bool{DBNameToken: true,EnvironmentToken: false,@@ -188,23 +195,23 @@ func ValidateRepositoryFilePathTemplate(filePathTemplate string, tenantMode Proj}}- for token, required := range repositoryFilePathTemplateTokens {+ filePathTemplateTokens := repositoryFilePathTemplateTokens+ // Skip checking {{DB_NAME}} if it's a tenant project with empty database name template (i.e .wildcard).+ if tenantMode == TenantModeTenant && dbNameTemplate == "" {+ filePathTemplateTokens = tenantWildcardRepositoryFilePathTemplateTokens+ }+ for token, required := range filePathTemplateTokens {// Skip checking tokens that are not requiredif !required {continue}- // Skip checking {{DB_NAME}} if it's a tenant project with empty database name template (i.e .wildcard).- if tenantMode == TenantModeTenant && dbNameTemplate == "" && token == DBNameToken {- continue- }-if _, ok := tokenMap[token]; !ok {return errors.Errorf("missing %s in file path template", token)}}for token := range tokenMap {- if _, ok := repositoryFilePathTemplateTokens[token]; !ok {+ if _, ok := filePathTemplateTokens[token]; !ok {return errors.Errorf("unknown token %s in file path template", token)}}