Skip to content

Commit

Permalink
Merge pull request #336 from teharrison/master
Browse files Browse the repository at this point in the history
updates
  • Loading branch information
teharrison authored Jul 26, 2017
2 parents faada30 + caca714 commit 3ff7943
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 50 deletions.
1 change: 0 additions & 1 deletion shock-server/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package auth

import (
"errors"
//"github.com/MG-RAST/Shock/shock-server/auth/basic"
"github.com/MG-RAST/Shock/shock-server/auth/globus"
"github.com/MG-RAST/Shock/shock-server/auth/oauth"
"github.com/MG-RAST/Shock/shock-server/conf"
Expand Down
39 changes: 15 additions & 24 deletions shock-server/auth/globus/globus.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/MG-RAST/Shock/shock-server/auth/basic"
"github.com/MG-RAST/Shock/shock-server/conf"
e "github.com/MG-RAST/Shock/shock-server/errors"
"github.com/MG-RAST/Shock/shock-server/logger"
"github.com/MG-RAST/Shock/shock-server/user"
"io/ioutil"
"net/http"
Expand Down Expand Up @@ -94,13 +93,14 @@ func fetchProfile(t string) (u *user.User, err error) {
client := &http.Client{
Transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}},
}
//logger.Error("got here")
req, err := http.NewRequest("GET", conf.AUTH_GLOBUS_PROFILE_URL+"/"+clientId(t), nil)
//logger.Error("URL: " + conf.AUTH_GLOBUS_PROFILE_URL+"/"+clientId(t))
cid, err := clientId(t)
if err != nil {
return nil, err
}
req, err := http.NewRequest("GET", conf.AUTH_GLOBUS_PROFILE_URL+"/"+cid, nil)
if err != nil {
return nil, errors.New("HTTP GET: " + err.Error())
}
//req.Header.Add("Authorization", t)
req.Header.Add("Authorization", "Globus-Goauthtoken "+t)
if resp, err := client.Do(req); err == nil {
defer resp.Body.Close()
Expand Down Expand Up @@ -129,10 +129,11 @@ func fetchProfile(t string) (u *user.User, err error) {
return
}

func clientId(t string) string {
func clientId(t string) (c string, err error) {
// test for old format first
for _, part := range strings.Split(t, "|") {
if kv := strings.Split(part, "="); kv[0] == "client_id" {
return kv[1]
return kv[1], nil
}
}
//if we get here then we have a new style token and need to make a call to look up the
Expand All @@ -141,38 +142,28 @@ func clientId(t string) string {
Transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}},
}
req, err := http.NewRequest("GET", conf.AUTH_GLOBUS_TOKEN_URL, nil)
//logger.Error("URL: " + conf.AUTH_GLOBUS_TOKEN_URL)

if err != nil {
logger.Error("Failed contact with auth server")
return ""
return "", errors.New("HTTP GET: " + err.Error())
}
req.Header.Add("X-Globus-Goauthtoken", t)
if resp, err := client.Do(req); err == nil {
//logger.Error("resp: " + resp.Status)
defer resp.Body.Close()
if resp.StatusCode == http.StatusCreated || resp.StatusCode == http.StatusOK {
if body, err := ioutil.ReadAll(resp.Body); err == nil {
var dat map[string]interface{}
if err = json.Unmarshal(body, &dat); err != nil {
logger.Error("Unable to parse response from auth server")
return ""
return "", errors.New("JSON Unmarshal: " + err.Error())
} else {
return dat["client_id"].(string)
return dat["client_id"].(string), nil
}
}
} else if resp.StatusCode == http.StatusForbidden {
logger.Error("Auth request rejected as Forbidden")
return ""
return "", errors.New(e.InvalidAuth)
} else {
err_str := "Authentication failed in clientID: Unexpected response status: " + resp.Status
logger.Error(err_str)
return ""
return "", errors.New("Authentication failed: Unexpected response status: " + resp.Status)
}
} else {
logger.Error("Undefined auth error 1")
return ""
return "", err
}
logger.Error("Undefined auth error 2")
return ""
return
}
50 changes: 32 additions & 18 deletions shock-server/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
package conf

import (
//"flag"
"errors"
"fmt"
"github.com/MG-RAST/golib/goconfig/config"
"os"
"path/filepath"
"strconv"
"strings"
)
Expand All @@ -19,6 +19,12 @@ type idxOpts struct {

const VERSION string = "[% VERSION %]"

var VERSIONS = map[string]int{
"ACL": 2,
"Auth": 1,
"Node": 4,
}

var LOG_OUTPUTS = [3]string{"file", "console", "both"}

var (
Expand Down Expand Up @@ -88,9 +94,6 @@ var (
SSL_KEY string
SSL_CERT string

// Versions
VERSIONS = make(map[string]int)

PRINT_HELP bool // full usage
SHOW_HELP bool // simple usage
SHOW_VERSION bool
Expand Down Expand Up @@ -207,11 +210,6 @@ func getConfiguration(c *config.Config) (c_store *Config_store, err error) {
// Admin
c_store.AddString(&ADMIN_EMAIL, "", "Admin", "email", "", "")
c_store.AddString(&ADMIN_USERS, "", "Admin", "users", "", "")
if ADMIN_USERS != "" {
for _, name := range strings.Split(ADMIN_USERS, ",") {
AdminUsers = append(AdminUsers, strings.TrimSpace(name))
}
}

// Access-Control
c_store.AddBool(&ANON_READ, true, "Anonymous", "read", "", "")
Expand Down Expand Up @@ -290,10 +288,8 @@ func getConfiguration(c *config.Config) (c_store *Config_store, err error) {

// SSL
c_store.AddBool(&SSL, false, "SSL", "enable", "", "")
if SSL {
c_store.AddString(&SSL_KEY, "", "SSL", "key", "", "")
c_store.AddString(&SSL_CERT, "", "SSL", "cert", "", "")
}
c_store.AddString(&SSL_KEY, "", "SSL", "key", "", "")
c_store.AddString(&SSL_CERT, "", "SSL", "cert", "", "")

// Other - thses option are CLI only
c_store.AddString(&RELOAD, "", "Other", "reload", "path or url to shock data. WARNING this will drop all current data.", "")
Expand All @@ -303,16 +299,18 @@ func getConfiguration(c *config.Config) (c_store *Config_store, err error) {
c_store.AddBool(&PRINT_HELP, false, "Other", "fullhelp", "show detailed usage without \"--\"-prefixes", "")
c_store.AddBool(&SHOW_HELP, false, "Other", "help", "show usage", "")

VERSIONS["ACL"] = 2
VERSIONS["Auth"] = 1
VERSIONS["Node"] = 4

c_store.Parse()

return
}

func parseConfiguration() (err error) {
// get admin users
if ADMIN_USERS != "" {
for _, name := range strings.Split(ADMIN_USERS, ",") {
AdminUsers = append(AdminUsers, strings.TrimSpace(name))
}
}

// parse OAuth settings if used
if AUTH_OAUTH_URL_STR != "" && AUTH_OAUTH_BEARER_STR != "" {
ou := strings.Split(AUTH_OAUTH_URL_STR, ",")
Expand All @@ -325,6 +323,7 @@ func parseConfiguration() (err error) {
}
OAUTH_DEFAULT = ou[0] // first url is default for "oauth" bearer token
}

// validate LOG_OUTPUT
vaildLogout := false
for _, logout := range LOG_OUTPUTS {
Expand All @@ -335,5 +334,20 @@ func parseConfiguration() (err error) {
if !vaildLogout {
return errors.New("invalid option for logoutput, use one of: file, console, both")
}

// clean paths
PATH_SITE = cleanPath(PATH_SITE)
PATH_DATA = cleanPath(PATH_DATA)
PATH_LOGS = cleanPath(PATH_LOGS)
PATH_LOCAL = cleanPath(PATH_LOCAL)
PATH_PIDFILE = cleanPath(PATH_PIDFILE)

return
}

func cleanPath(p string) string {
if p != "" {
p, _ = filepath.Abs(p)
}
return p
}
14 changes: 7 additions & 7 deletions shock-server/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ func Initialize() (err error) {
return err
}

// This config parameter contains a string that should be a comma-separated list of users that are Admins.
// process list of amin users from config, create those that are missing
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 {
info, err := c.UpdateAll(bson.M{"username": v}, bson.M{"$set": bson.M{"shock_admin": true}})
if err != nil {
return err
}
if info.Updated == 0 {
if _, err := New(v, "", true); err != nil {
return err
} else if info.Updated == 0 {
if _, err := New(v, "", true); err != nil {
return err
}
}
}
}
Expand Down

0 comments on commit 3ff7943

Please sign in to comment.