diff --git a/bags.go b/bags.go index 9da059a..05d4bd4 100644 --- a/bags.go +++ b/bags.go @@ -8,6 +8,7 @@ import ( "fmt" "io" "net/http" + "regexp" "strings" "github.com/cyverse-de/queries" @@ -45,16 +46,11 @@ func NewBagsApp(db *sql.DB, router *mux.Router, userDomain string) *BagsApp { return bagsApp } -// AddUsernameSuffix appends the @iplantcollaborative.org string to the +// AddUsernameSuffix appends the user domain string to the // username if it's not already there. func (b *BagsApp) AddUsernameSuffix(username string) string { - var retval string - if !strings.Contains(username, "@") { - retval = fmt.Sprintf("%s%s", username, IplantSuffix) - } else { - retval = username - } - return retval + re, _ := regexp.Compile(`@.*$`) + return fmt.Sprintf("%s@%s", re.ReplaceAllString(username, ""), strings.Trim(b.userDomain, "@")) } // Greeting prints out a greeting for the bags endpoints. diff --git a/main.go b/main.go index fb59ebe..ccfadb5 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "flag" "net/http" "os" + "strings" "github.com/cyverse-de/configurate" "github.com/cyverse-de/dbutil" @@ -18,7 +19,7 @@ import ( const serviceName = "user-info" // IplantSuffix is what is appended to a username in the database. -const IplantSuffix = "@iplantcollaborative.org" +const IplantSuffix = "iplantcollaborative.org" func main() { var ( @@ -68,7 +69,7 @@ func main() { } log.Info("Successfully pinged the database") - userDomain := cfg.GetString("users.domain") + userDomain := strings.Trim(cfg.GetString("users.domain"), "@") if userDomain == "" { userDomain = IplantSuffix }