2024-10-10 13:02:25 +00:00
|
|
|
package iamutil
|
2024-02-01 16:46:07 +00:00
|
|
|
|
|
|
|
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
|
2024-10-10 13:02:25 +00:00
|
|
|
if IsServicePrincipal(user) && user.DisplayName != "" {
|
2024-09-16 18:35:07 +00:00
|
|
|
name = user.DisplayName
|
|
|
|
}
|
|
|
|
local, _, _ := strings.Cut(name, "@")
|
2024-02-01 16:46:07 +00:00
|
|
|
return textutil.NormalizeString(local)
|
|
|
|
}
|