2024-02-01 16:46:07 +00:00
|
|
|
package auth
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/databricks/cli/libs/textutil"
|
2024-09-16 18:35:07 +00:00
|
|
|
"github.com/databricks/databricks-sdk-go/service/iam"
|
2024-02-01 16:46:07 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Get a short-form username, based on the user's primary email address.
|
|
|
|
// We leave the full range of unicode letters in tact, but remove all "special" characters,
|
|
|
|
// including dots, which are not supported in e.g. experiment names.
|
2024-09-16 18:35:07 +00:00
|
|
|
func GetShortUserName(user *iam.User) string {
|
|
|
|
name := user.UserName
|
|
|
|
if IsServicePrincipal(user.UserName) && user.DisplayName != "" {
|
|
|
|
name = user.DisplayName
|
|
|
|
}
|
|
|
|
local, _, _ := strings.Cut(name, "@")
|
2024-02-01 16:46:07 +00:00
|
|
|
return textutil.NormalizeString(local)
|
|
|
|
}
|