Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update user suffix handling in bags code #13

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, "@"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}

// 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