Skip to content

Commit

Permalink
Update user suffix handling in bags code
Browse files Browse the repository at this point in the history
  • Loading branch information
ianmcorvidae committed Jul 30, 2024
1 parent 1db12bc commit 8044893
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
12 changes: 4 additions & 8 deletions bags.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"io"
"net/http"
"regexp"
"strings"

"github.com/cyverse-de/queries"
Expand Down Expand Up @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"flag"
"net/http"
"os"
"strings"

"github.com/cyverse-de/configurate"
"github.com/cyverse-de/dbutil"
Expand All @@ -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 (
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 8044893

Please sign in to comment.