Skip to content

Commit

Permalink
Use UserName field to identify if service principal is used (#1310)
Browse files Browse the repository at this point in the history
## Changes
Use UserName field to identify if service principal is used

## Tests
Integration test passed
  • Loading branch information
andrewnester authored Mar 25, 2024
1 parent 26094f0 commit 9cf3dbe
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion internal/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func TestAccBundleInitHelpers(t *testing.T) {
},
{
funcName: "{{is_service_principal}}",
expected: strconv.FormatBool(auth.IsServicePrincipal(me.Id)),
expected: strconv.FormatBool(auth.IsServicePrincipal(me.UserName)),
},
{
funcName: "{{smallest_node_type}}",
Expand Down
8 changes: 4 additions & 4 deletions libs/auth/service_principal.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"github.com/google/uuid"
)

// Determines whether a given user id is a service principal.
// This function uses a heuristic: if the user id is a UUID, then we assume
// Determines whether a given user name is a service principal.
// 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
// slow for our purposes. And the "users" and "service principals get" APIs
// only allow access by workspace admins.
func IsServicePrincipal(userId string) bool {
_, err := uuid.Parse(userId)
func IsServicePrincipal(userName string) bool {
_, err := uuid.Parse(userName)
return err == nil
}
2 changes: 1 addition & 1 deletion libs/template/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func loadHelpers(ctx context.Context) template.FuncMap {
return false, err
}
}
result := auth.IsServicePrincipal(cachedUser.Id)
result := auth.IsServicePrincipal(cachedUser.UserName)
cachedIsServicePrincipal = &result
return result, nil
},
Expand Down

0 comments on commit 9cf3dbe

Please sign in to comment.