From 49ee896e0361f49322938b8f7fbb9e04abd22767 Mon Sep 17 00:00:00 2001 From: Travis Harrison Date: Tue, 26 Jan 2016 11:06:47 -0600 Subject: [PATCH 1/7] remove double save, add admin flag when creating new admin user --- shock-server/conf/conf.go | 6 ++++++ shock-server/user/user.go | 21 ++++++++++++--------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/shock-server/conf/conf.go b/shock-server/conf/conf.go index d2189be8..cb48fdb9 100644 --- a/shock-server/conf/conf.go +++ b/shock-server/conf/conf.go @@ -20,6 +20,7 @@ var ( // Admin ADMIN_EMAIL = "" ADMIN_USERS = "" + AdminUsers []string // Permissions for anonymous user ANON_READ = true @@ -97,6 +98,11 @@ func Initialize() { // Admin ADMIN_EMAIL, _ = c.String("Admin", "email") ADMIN_USERS, _ = c.String("Admin", "users") + if ADMIN_USERS != "" { + for _, name := range strings.Split(ADMIN_USERS, ",") { + AdminUsers = append(AdminUsers, strings.TrimSpace(name)) + } + } // Access-Control ANON_READ, _ = c.Bool("Anonymous", "read") diff --git a/shock-server/user/user.go b/shock-server/user/user.go index 3163ea9d..06018554 100644 --- a/shock-server/user/user.go +++ b/shock-server/user/user.go @@ -6,7 +6,6 @@ import ( "github.com/MG-RAST/Shock/vendor/github.com/MG-RAST/golib/go-uuid/uuid" mgo "github.com/MG-RAST/Shock/vendor/gopkg.in/mgo.v2" "github.com/MG-RAST/Shock/vendor/gopkg.in/mgo.v2/bson" - "strings" ) // Array of User @@ -42,17 +41,12 @@ func Initialize() (err error) { } // This config parameter contains a string that should be a comma-separated list of users that are Admins. - adminUsers := strings.Split(conf.ADMIN_USERS, ",") - for _, v := range adminUsers { + for _, v := range conf.AdminUsers { if info, err := c.UpdateAll(bson.M{"username": v}, bson.M{"$set": bson.M{"shock_admin": true}}); err != nil { if err != nil { return err } else if info.Updated == 0 { - u, err := New(v, "", true) - if err != nil { - return err - } - if err := u.Save(); err != nil { + if _, err := New(v, "", true); err != nil { return err } } @@ -63,7 +57,8 @@ func Initialize() (err error) { func New(username string, password string, isAdmin bool) (u *User, err error) { u = &User{Uuid: uuid.New(), Username: username, Password: password, Admin: isAdmin} - if err = u.Save(); err != nil { + err = u.Save() + if err != nil { u = nil } return @@ -105,7 +100,15 @@ func (u *User) SetMongoInfo() (err error) { u.Admin = admin return nil } else { + // this is a new user u.Uuid = uuid.New() + // check if user is on admin list, if so set as true + for _, v := range conf.AdminUsers { + if v == u.Username { + u.Admin = true + break + } + } if err := u.Save(); err != nil { return err } From 1d0647d8adcff699068904b2ad16c65a01560d71 Mon Sep 17 00:00:00 2001 From: Travis Harrison Date: Tue, 26 Jan 2016 11:37:52 -0600 Subject: [PATCH 2/7] skip version updates on start if node collection is empty --- shock-server/versions/versions.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/shock-server/versions/versions.go b/shock-server/versions/versions.go index ee87d2f3..6e92621b 100644 --- a/shock-server/versions/versions.go +++ b/shock-server/versions/versions.go @@ -70,6 +70,18 @@ func RunVersionUpdates() (err error) { confVersionACL, ok1 := conf.VERSIONS["ACL"] dbVersionACL, ok2 := VersionMap["ACL"] + // skip version updates if database is empty / new shock deploy + session := db.Connection.Session.Copy() + c := session.DB(conf.MONGODB_DATABASE).C("Nodes") + num, err := c.Count() + session.Close() + if err != nil { + return err + } + if num == 0 { + return nil + } + // Upgrading databases with ACL schema before version 2 if (ok1 && confVersionACL >= 2) && (!ok2 || (ok2 && dbVersionACL < 2)) { consoleReader := bufio.NewReader(os.Stdin) From 4e11d8409e9cdb55c21b8404531859e36e7afac5 Mon Sep 17 00:00:00 2001 From: Travis Harrison Date: Tue, 26 Jan 2016 11:55:35 -0600 Subject: [PATCH 3/7] expose version parts --- shock-server/node/node.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shock-server/node/node.go b/shock-server/node/node.go index 52c2defe..62812c77 100644 --- a/shock-server/node/node.go +++ b/shock-server/node/node.go @@ -25,7 +25,7 @@ type Node struct { Attributes interface{} `bson:"attributes" json:"attributes"` Indexes Indexes `bson:"indexes" json:"indexes"` Acl acl.Acl `bson:"acl" json:"-"` - VersionParts map[string]string `bson:"version_parts" json:"-"` + VersionParts map[string]string `bson:"version_parts" json:"version_parts"` Tags []string `bson:"tags" json:"tags"` Revisions []Node `bson:"revisions" json:"-"` Linkages []linkage `bson:"linkage" json:"linkage"` From d0c6593a87556b0d40798f41906085318ec2a7c3 Mon Sep 17 00:00:00 2001 From: Travis Harrison Date: Tue, 26 Jan 2016 12:38:15 -0600 Subject: [PATCH 4/7] add a copy_attributes option to the copy node action --- shock-server/node/update.go | 5 +++++ shock-server/util/util.go | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/shock-server/node/update.go b/shock-server/node/update.go index b0ad7ecc..e2f9dd2c 100644 --- a/shock-server/node/update.go +++ b/shock-server/node/update.go @@ -209,6 +209,11 @@ func (node *Node) Update(params map[string]string, files FormFiles) (err error) node.Type = "copy" } + // Copy node attributes + if _, copyAttributes := params["copy_attributes"]; copyAttributes { + node.Attributes = n.Attributes + } + // Copy node indexes if _, copyIndex := params["copy_indexes"]; copyIndex && (len(n.Indexes) > 0) { // loop through parent indexes diff --git a/shock-server/util/util.go b/shock-server/util/util.go index 62c34907..623983b9 100644 --- a/shock-server/util/util.go +++ b/shock-server/util/util.go @@ -15,7 +15,7 @@ const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890" // Arrays to check for valid param and file form names for node creation and updating, and also acl modification. // Note: indexing and querying do not use functions that use these arrays and thus we don't have to include those field names. -var validParams = []string{"action", "all", "archive_format", "attributes_str", "copy_data", "copy_indexes", "compression", "delete", "expiration", "file_name", "format", "ids", "index_name", "linkage", "operation", "owner", "parent_index", "parent_node", "parts", "path", "preserve_acls", "read", "remove_expiration", "source", "tags", "type", "unpack_node", "users", "write"} +var validParams = []string{"action", "all", "archive_format", "attributes_str", "copy_attributes", "copy_data", "copy_indexes", "compression", "delete", "expiration", "file_name", "format", "ids", "index_name", "linkage", "operation", "owner", "parent_index", "parent_node", "parts", "path", "preserve_acls", "read", "remove_expiration", "source", "tags", "type", "unpack_node", "users", "write"} var validFiles = []string{"attributes", "subset_indices", "upload", "gzip", "bzip2"} var ValidUpload = []string{"upload", "gzip", "bzip2"} From 79c4889d2f9b5d88ff7ab1ca407380b5924a9f6d Mon Sep 17 00:00:00 2001 From: Travis Harrison Date: Tue, 26 Jan 2016 12:56:36 -0600 Subject: [PATCH 5/7] test mongo connection with short timeout on startup --- shock-server/db/db.go | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/shock-server/db/db.go b/shock-server/db/db.go index d939c773..21060ad2 100644 --- a/shock-server/db/db.go +++ b/shock-server/db/db.go @@ -10,7 +10,9 @@ import ( ) const ( - DbTimeout = time.Duration(time.Second * 1200) + DbTimeout = time.Duration(time.Second * 1200) + DialTimeout = time.Duration(time.Second * 10) + DialAttempts = 5 ) var ( @@ -27,10 +29,25 @@ type connection struct { func Initialize() (err error) { c := connection{} + + // test connection + canDial := false + for i := 0; i < DialAttempts; i++ { + s, err := mgo.DialWithTimeout(conf.MONGODB_HOSTS, DialTimeout) + s.Close() + if err == nil { + canDial = true + break + } + } + if !canDial { + return errors.New(fmt.Sprintf("no reachable mongodb server(s) at %s", conf.MONGODB_HOSTS)) + } + + // get handle s, err := mgo.DialWithTimeout(conf.MONGODB_HOSTS, DbTimeout) if err != nil { - e := errors.New(fmt.Sprintf("no reachable mongodb server(s) at %s", conf.MONGODB_HOSTS)) - return e + return errors.New(fmt.Sprintf("no reachable mongodb server(s) at %s", conf.MONGODB_HOSTS)) } c.Session = s c.DB = c.Session.DB(conf.MONGODB_DATABASE) From 6eda2f9b04348c0ac152a2f84d0c8abc3e174513 Mon Sep 17 00:00:00 2001 From: Travis Harrison Date: Tue, 26 Jan 2016 14:35:28 -0600 Subject: [PATCH 6/7] dial bug fix --- shock-server/db/db.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shock-server/db/db.go b/shock-server/db/db.go index 21060ad2..17b812b9 100644 --- a/shock-server/db/db.go +++ b/shock-server/db/db.go @@ -12,7 +12,7 @@ import ( const ( DbTimeout = time.Duration(time.Second * 1200) DialTimeout = time.Duration(time.Second * 10) - DialAttempts = 5 + DialAttempts = 3 ) var ( @@ -34,8 +34,8 @@ func Initialize() (err error) { canDial := false for i := 0; i < DialAttempts; i++ { s, err := mgo.DialWithTimeout(conf.MONGODB_HOSTS, DialTimeout) - s.Close() if err == nil { + s.Close() canDial = true break } From 0258df38a741a9527892d5fc81088ecd04b56754 Mon Sep 17 00:00:00 2001 From: Travis Harrison Date: Tue, 26 Jan 2016 15:07:17 -0600 Subject: [PATCH 7/7] version and release notes --- RELEASE_NOTES.txt | 9 +++++++++ VERSION | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt index bdb3c2a8..f1331fa4 100644 --- a/RELEASE_NOTES.txt +++ b/RELEASE_NOTES.txt @@ -1,4 +1,13 @@ +# v0.9.13 + +- added option to copy attributes when doing node copy +- added version_parts map to returned node +- test mongo connection with short timeout on startup +- add admin flag when creating new admin user +- skip version updates on start if node collection is empty + # v0.9.12 + - Fix to occasional deadlock with parts node locking # v0.9.11 diff --git a/VERSION b/VERSION index 583b27ac..62ea2590 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.9.12 +0.9.13