Skip to content

Commit

Permalink
added check on the x.y format of the version
Browse files Browse the repository at this point in the history
  • Loading branch information
bsoniam committed May 17, 2019
1 parent 71b140f commit 047712b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 10 deletions.
49 changes: 41 additions & 8 deletions cmd/keycloakb/keycloak_bridge.go
Expand Up @@ -11,6 +11,7 @@ import (
"net/http/pprof"
"os"
"os/signal"
"regexp"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -203,20 +204,33 @@ func main() {
// checking that the flyway_schema_history has the minimum imposed migration version
// auditevents DB
auditMigrationVersion := c.GetString("db-audit-migration-version")
if auditMigrationEnabled && auditMigrationVersion != "" {
var err error
err = checkMigrationVersion(logger, *auditRwDbParams, auditMigrationVersion)
if err != nil {
if auditMigrationEnabled {
// DB schema versioning is enabled
if auditMigrationVersion != "" {
var err error
err = checkMigrationVersion(logger, *auditRwDbParams, auditMigrationVersion)
if err != nil {
return
}
} else {
// DB schema versioning is enabled but no minimum version was given
logger.Log("msg", "Check of DB schema is enabled, but no minimum version provided", "DB", auditRoDbParams.Database)
return
}
}

// cloudtrust_configurations DB
configMigrationVersion := c.GetString("db-config-migration-version")
if configMigrationEnabled && configMigrationVersion != "" {
var err error
err = checkMigrationVersion(logger, *configDbParams, configMigrationVersion)
if err != nil {
if configMigrationEnabled {
if configMigrationVersion != "" {
var err error
err = checkMigrationVersion(logger, *configDbParams, configMigrationVersion)
if err != nil {
return
}
} else {
// DB schema versioning is enabled but no minimum version was given
logger.Log("msg", "Check of DB schema is enabled, but no minimum version provided", "DB", configDbParams.Database)
return
}
}
Expand Down Expand Up @@ -882,6 +896,25 @@ func checkMigrationVersion(logger log.Logger, dbParams dbConfig, minMigrationVer
return err
}

//flyway version and config migration version must match the format x.y where x and y are integers
matched, err := regexp.MatchString(`^[0-9]+\.[0-9]+$`, minMigrationVersion)
if err != nil {
return err
}
if !matched {
logger.Log("msg", "the config migration version does not match the required format")
return fmt.Errorf("The config migration version does not match the required format")
}

matched, err = regexp.MatchString(`^[0-9]+\.[0-9]+$`, flywayVersion)
if err != nil {
return err
}
if !matched {
logger.Log("msg", "the flyway migration version does not match the required format")
return fmt.Errorf("The flyway migration version does not match the required format")
}

// compare the two versions of the type x.y (major.minor)
minMajorRequired := strings.Split(minMigrationVersion, ".")
minMajorFlyway := strings.Split(flywayVersion, ".")
Expand Down
4 changes: 2 additions & 2 deletions configs/keycloak_bridge.yml
Expand Up @@ -44,8 +44,8 @@ db-audit-rw-protocol: tcp
db-audit-rw-max-open-conns: 10
db-audit-rw-max-idle-conns: 2
db-audit-rw-conn-max-lifetime: 3600
db-audit-migration: false
db-audit-migration-version: 4.15
db-audit-migration: true
db-audit-migration-version:


# DB Audit RO
Expand Down

0 comments on commit 047712b

Please sign in to comment.