Skip to content

Commit

Permalink
fix (api): remove persistent session token migration code (#908)
Browse files Browse the repository at this point in the history
  • Loading branch information
fsamin authored and bnjjj committed Aug 2, 2017
1 parent 05dc13c commit b34e2db
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 62 deletions.
58 changes: 1 addition & 57 deletions engine/api/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@ package bootstrap

import (
"strings"
"time"

"github.com/go-gorp/gorp"

"github.com/ovh/cds/engine/api/action"
"github.com/ovh/cds/engine/api/environment"
"github.com/ovh/cds/engine/api/group"
"github.com/ovh/cds/engine/api/token"
"github.com/ovh/cds/engine/api/user"
"github.com/ovh/cds/sdk"
"github.com/ovh/cds/sdk/log"
)

// DefaultValues contains default user values for init DB
Expand Down Expand Up @@ -55,58 +52,5 @@ func InitiliazeDB(defaultValues DefaultValues, DBFunc func() *gorp.DbMap) error
return sdk.WrapError(err, "InitiliazeDB> Cannot setup builtin environments")
}

return migratePersistentSessionToken(DBFunc)
}

func migratePersistentSessionToken(DBFunc func() *gorp.DbMap) error {
tx, err := DBFunc().Begin()
if err != nil {
return err
}
defer tx.Rollback()

_, err = tx.Exec("LOCK TABLE user_persistent_session IN ACCESS EXCLUSIVE MODE NOWAIT")
count, err := tx.SelectInt("select count(1) from user_persistent_session")
if err != nil {
return err
}

if count != 0 {
log.Debug("migratePersistentSession> Nothing to do")
return nil
}

log.Info("migratePersistentSession> Begin")
defer log.Info("migratePersistentSession> End")

users, err := user.LoadUsers(tx)
if err != nil {
return err
}

for _, utmp := range users {
u, err := user.LoadUserAndAuth(tx, utmp.Username)
if err != nil {
log.Error("migratePersistentSession> %v", err)
break
}

for _, t := range u.Auth.Tokens {
t.CreationDate = time.Now()
t.LastConnectionDate = time.Now()
t.UserID = u.ID
t.Comment = "Automatic migration"
if err := user.InsertPersistentSessionToken(tx, t); err != nil {
log.Error("migratePersistentSession> %v", err)
break
}
}

u.Auth.Tokens = nil
if err := user.UpdateUserAndAuth(tx, *u); err != nil {
return err
}
}

return tx.Commit()
return nil
}
9 changes: 4 additions & 5 deletions sdk/authentification.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import "time"

// Auth Authentifaction Struct for user
type Auth struct {
HashedPassword string `json:"hashedPassword"`
HashedTokenVerify string `json:"hashedTokenVerify"`
EmailVerified bool `json:"emailVerified"`
DateReset int64 `json:"dateReset"`
Tokens []UserToken `json:"tokens,omitempty"`
HashedPassword string `json:"hashedPassword"`
HashedTokenVerify string `json:"hashedTokenVerify"`
EmailVerified bool `json:"emailVerified"`
DateReset int64 `json:"dateReset"`
}

// UserToken for user persistent session
Expand Down

0 comments on commit b34e2db

Please sign in to comment.