diff --git a/cmd/utask/root.go b/cmd/utask/root.go index 7bf2ad03..c9b100a1 100644 --- a/cmd/utask/root.go +++ b/cmd/utask/root.go @@ -181,7 +181,7 @@ var rootCmd = &cobra.Command{ server.SetDashboardSentryDSN(cfg.DashboardSentryDSN) server.SetMaxBodyBytes(cfg.ServerOptions.MaxBodyBytes) - utask.StepsCompressionAlg = cfg.StepsCompression + utask.StepsCompressionAlg = cfg.StepsCompressionAlg if utask.FDebug { log.SetLevel(log.DebugLevel) diff --git a/db/migration.go b/db/migration.go index 46fce375..92b65481 100644 --- a/db/migration.go +++ b/db/migration.go @@ -13,7 +13,7 @@ import ( ) const ( - expectedVersion = "v1.20.0-migration008" + expectedVersion = "v1.21.0-migration009" ) var ( diff --git a/models/resolution/resolution.go b/models/resolution/resolution.go index 618a6757..34fd7645 100644 --- a/models/resolution/resolution.go +++ b/models/resolution/resolution.go @@ -1,6 +1,7 @@ package resolution import ( + "bytes" "encoding/json" "time" @@ -14,6 +15,7 @@ import ( "github.com/ovh/utask/models/tasktemplate" "github.com/ovh/utask/pkg/compress" "github.com/ovh/utask/pkg/now" + "github.com/ovh/utask/pkg/utils" "github.com/Masterminds/squirrel" "github.com/gofrs/uuid" @@ -143,22 +145,28 @@ func Create(dbp zesty.DBProvider, t *task.Task, resolverInputs map[string]interf r.BaseConfigurations = tt.BaseConfigurations - encrSteps, err := models.EncryptionKey.EncryptMarshal(r.Steps, []byte(r.PublicID)) + c, err := compress.Get(utask.StepsCompressionAlg) if err != nil { return nil, err } - c, err := compress.Get(utask.StepsCompressionAlg) + r.StepsCompressionAlg = utask.StepsCompressionAlg + + jsonSteps, err := json.Marshal(r.Steps) if err != nil { return nil, err } - r.StepsCompressionAlg = utask.StepsCompressionAlg + compressedSteps, err := c.Compress(jsonSteps) + if err != nil { + return nil, err + } - r.EncryptedSteps, err = c.Compress([]byte(encrSteps)) + encryptedSteps, err := models.EncryptionKey.Encrypt(compressedSteps, []byte(r.PublicID)) if err != nil { return nil, err } + r.EncryptedSteps = encryptedSteps err = tt.ValidateResolverInputs(resolverInputs) if err != nil { @@ -239,16 +247,20 @@ func load(dbp zesty.DBProvider, publicID string, locked bool, lockNoWait bool) ( return nil, err } - encryptSteps, err := c.Decompress(r.EncryptedSteps) + compressedSteps, err := models.EncryptionKey.Decrypt(r.EncryptedSteps, []byte(r.PublicID)) if err != nil { return nil, err } - st := make(map[string]*step.Step) - err = models.EncryptionKey.DecryptMarshal(string(encryptSteps), &st, []byte(r.PublicID)) + jsonSteps, err := c.Decompress(compressedSteps) if err != nil { return nil, err } + + st := make(map[string]*step.Step) + if err := utils.JSONnumberUnmarshal(bytes.NewReader(jsonSteps), &st); err != nil { + return nil, err + } r.setSteps(st) input := make(map[string]interface{}) @@ -350,22 +362,26 @@ func (r *Resolution) Update(dbp zesty.DBProvider) (err error) { // TODO tasktemplate.ValidateResolverInput !! - encrSteps, err := models.EncryptionKey.EncryptMarshal(r.Steps, []byte(r.PublicID)) + c, err := compress.Get(r.StepsCompressionAlg) if err != nil { return err } - c, err := compress.Get(r.StepsCompressionAlg) + jsonSteps, err := json.Marshal(r.Steps) if err != nil { return err } - compressedSteps, err := c.Compress([]byte(encrSteps)) + compressedSteps, err := c.Compress(jsonSteps) if err != nil { return err } - r.EncryptedSteps = compressedSteps + encryptedSteps, err := models.EncryptionKey.Encrypt(compressedSteps, []byte(r.PublicID)) + if err != nil { + return err + } + r.EncryptedSteps = encryptedSteps encrInput, err := models.EncryptionKey.EncryptMarshal(r.ResolverInput, []byte(r.PublicID)) if err != nil { diff --git a/sql/schema.sql b/sql/schema.sql index c6553820..acd67989 100644 --- a/sql/schema.sql +++ b/sql/schema.sql @@ -134,6 +134,6 @@ CREATE TABLE "utask_sql_migrations" ( current_migration_applied TEXT PRIMARY KEY ); -INSERT INTO "utask_sql_migrations" VALUES ('v1.20.0-migration008'); +INSERT INTO "utask_sql_migrations" VALUES ('v1.21.0-migration009'); END;