Skip to content

Commit

Permalink
fix: db version and compress algo
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Bétrancourt <thomas@betrancourt.net>
  • Loading branch information
rclsilver committed Nov 14, 2022
1 parent bf23fbb commit bfc5cfd
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 14 deletions.
2 changes: 1 addition & 1 deletion cmd/utask/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion db/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

const (
expectedVersion = "v1.20.0-migration008"
expectedVersion = "v1.21.0-migration009"
)

var (
Expand Down
38 changes: 27 additions & 11 deletions models/resolution/resolution.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package resolution

import (
"bytes"
"encoding/json"
"time"

Expand All @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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{})
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion sql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit bfc5cfd

Please sign in to comment.