Skip to content

Commit

Permalink
Merge pull request #298 from teharrison/master
Browse files Browse the repository at this point in the history
several minor added features and bug fixes
  • Loading branch information
teharrison committed Jan 26, 2016
2 parents 88d92bb + 0258df3 commit 1e66f15
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 15 deletions.
9 changes: 9 additions & 0 deletions RELEASE_NOTES.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.9.12
0.9.13
6 changes: 6 additions & 0 deletions shock-server/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var (
// Admin
ADMIN_EMAIL = ""
ADMIN_USERS = ""
AdminUsers []string

// Permissions for anonymous user
ANON_READ = true
Expand Down Expand Up @@ -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")
Expand Down
23 changes: 20 additions & 3 deletions shock-server/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = 3
)

var (
Expand All @@ -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)
if err == nil {
s.Close()
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)
Expand Down
2 changes: 1 addition & 1 deletion shock-server/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
5 changes: 5 additions & 0 deletions shock-server/node/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 12 additions & 9 deletions shock-server/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion shock-server/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}

Expand Down
12 changes: 12 additions & 0 deletions shock-server/versions/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1e66f15

Please sign in to comment.