2023-08-25 09:03:42 +00:00
|
|
|
package auth
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/databricks/databricks-sdk-go"
|
2023-08-30 14:01:08 +00:00
|
|
|
"github.com/databricks/databricks-sdk-go/apierr"
|
2023-08-25 09:03:42 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Determines whether a given user id is a service principal.
|
|
|
|
// This function uses a heuristic: if no user exists with this id, we assume
|
|
|
|
// it's a service principal. Unfortunately, the standard service principal API is too
|
|
|
|
// slow for our purposes.
|
2023-08-30 14:01:08 +00:00
|
|
|
func IsServicePrincipal(ctx context.Context, ws *databricks.WorkspaceClient, userId string) (bool, error) {
|
2023-08-25 09:03:42 +00:00
|
|
|
_, err := ws.Users.GetById(ctx, userId)
|
2023-08-30 14:01:08 +00:00
|
|
|
if apierr.IsMissing(err) {
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
return false, err
|
2023-08-25 09:03:42 +00:00
|
|
|
}
|