2024-10-10 13:02:25 +00:00
|
|
|
package iamutil
|
2023-08-25 09:03:42 +00:00
|
|
|
|
|
|
|
import (
|
2024-10-10 13:02:25 +00:00
|
|
|
"github.com/databricks/databricks-sdk-go/service/iam"
|
2023-09-05 11:20:55 +00:00
|
|
|
"github.com/google/uuid"
|
2023-08-25 09:03:42 +00:00
|
|
|
)
|
|
|
|
|
2024-10-10 13:02:25 +00:00
|
|
|
// Determines whether a given user is a service principal.
|
2024-03-25 11:32:45 +00:00
|
|
|
// This function uses a heuristic: if the user name is a UUID, then we assume
|
2023-09-05 11:20:55 +00:00
|
|
|
// it's a service principal. Unfortunately, the service principal listing API is too
|
|
|
|
// slow for our purposes. And the "users" and "service principals get" APIs
|
|
|
|
// only allow access by workspace admins.
|
2024-10-10 13:02:25 +00:00
|
|
|
func IsServicePrincipal(user *iam.User) bool {
|
|
|
|
_, err := uuid.Parse(user.UserName)
|
2023-09-05 11:20:55 +00:00
|
|
|
return err == nil
|
2023-08-25 09:03:42 +00:00
|
|
|
}
|