Merge pull request #34 from ywk253100/logger_refactor

refactor logger in main.go & add harbor.cfg to .gitignore
This commit is contained in:
Daniel Jiang 2016-03-23 16:30:08 +08:00
commit 7f012c4a34
7 changed files with 15 additions and 12 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@ Deploy/config/registry/config.yml
Deploy/config/ui/env Deploy/config/ui/env
Deploy/config/ui/app.conf Deploy/config/ui/app.conf
Deploy/config/db/env Deploy/config/db/env
Deploy/harbor.cfg

26
main.go
View File

@ -17,7 +17,8 @@ package main
import ( import (
"fmt" "fmt"
"log"
log "github.com/vmware/harbor/utils/log"
_ "github.com/vmware/harbor/auth/db" _ "github.com/vmware/harbor/auth/db"
_ "github.com/vmware/harbor/auth/ldap" _ "github.com/vmware/harbor/auth/ldap"
@ -38,28 +39,27 @@ func updateInitPassword(userID int, password string) error {
queryUser := models.User{UserID: userID} queryUser := models.User{UserID: userID}
user, err := dao.GetUser(queryUser) user, err := dao.GetUser(queryUser)
if err != nil { if err != nil {
log.Println("Failed to get user, userID:", userID) return fmt.Errorf("Failed to get user, userID: %d %v", userID, err)
return err
} }
if user == nil { if user == nil {
log.Printf("User id: %d does not exist.", userID)
return fmt.Errorf("User id: %d does not exist.", userID) return fmt.Errorf("User id: %d does not exist.", userID)
} else if user.Salt == "" { }
if user.Salt == "" {
salt, err := dao.GenerateRandomString() salt, err := dao.GenerateRandomString()
if err != nil { if err != nil {
log.Printf("Failed to generate salt for encrypting password, %v", err) return fmt.Errorf("Failed to generate salt for encrypting password, %v", err)
return err
} }
user.Salt = salt user.Salt = salt
user.Password = password user.Password = password
err = dao.ChangeUserPassword(*user) err = dao.ChangeUserPassword(*user)
if err != nil { if err != nil {
log.Printf("Failed to update user encrypted password, userID: %d, err: %v", userID, err) return fmt.Errorf("Failed to update user encrypted password, userID: %d, err: %v", userID, err)
return err
} }
log.Printf("User id: %d updated its encypted password successfully.", userID)
log.Infof("User id: %d updated its encypted password successfully.", userID)
} else { } else {
log.Printf("User id: %d already has its encrypted password.", userID) log.Infof("User id: %d already has its encrypted password.", userID)
} }
return nil return nil
} }
@ -68,6 +68,8 @@ func main() {
beego.BConfig.WebConfig.Session.SessionOn = true beego.BConfig.WebConfig.Session.SessionOn = true
dao.InitDB() dao.InitDB()
updateInitPassword(adminUserID, os.Getenv("HARBOR_ADMIN_PASSWORD")) if err := updateInitPassword(adminUserID, os.Getenv("HARBOR_ADMIN_PASSWORD")); err != nil {
log.Error(err)
}
beego.Run() beego.Run()
} }