Use UserName field to identify if service principal is used (#1310)

## Changes
Use UserName field to identify if service principal is used

## Tests
Integration test passed
This commit is contained in:
Andrew Nester 2024-03-25 12:32:45 +01:00 committed by GitHub
parent 26094f01a0
commit 9cf3dbe686
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 6 deletions

View File

@ -138,7 +138,7 @@ func TestAccBundleInitHelpers(t *testing.T) {
}, },
{ {
funcName: "{{is_service_principal}}", funcName: "{{is_service_principal}}",
expected: strconv.FormatBool(auth.IsServicePrincipal(me.Id)), expected: strconv.FormatBool(auth.IsServicePrincipal(me.UserName)),
}, },
{ {
funcName: "{{smallest_node_type}}", funcName: "{{smallest_node_type}}",

View File

@ -4,12 +4,12 @@ import (
"github.com/google/uuid" "github.com/google/uuid"
) )
// Determines whether a given user id is a service principal. // Determines whether a given user name is a service principal.
// This function uses a heuristic: if the user id is a UUID, then we assume // This function uses a heuristic: if the user name is a UUID, then we assume
// it's a service principal. Unfortunately, the service principal listing API is too // 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 // slow for our purposes. And the "users" and "service principals get" APIs
// only allow access by workspace admins. // only allow access by workspace admins.
func IsServicePrincipal(userId string) bool { func IsServicePrincipal(userName string) bool {
_, err := uuid.Parse(userId) _, err := uuid.Parse(userName)
return err == nil return err == nil
} }

View File

@ -140,7 +140,7 @@ func loadHelpers(ctx context.Context) template.FuncMap {
return false, err return false, err
} }
} }
result := auth.IsServicePrincipal(cachedUser.Id) result := auth.IsServicePrincipal(cachedUser.UserName)
cachedIsServicePrincipal = &result cachedIsServicePrincipal = &result
return result, nil return result, nil
}, },