Skip to content

Commit 9cf3dbe

Browse files
authored
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
1 parent 26094f0 commit 9cf3dbe

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

internal/init_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func TestAccBundleInitHelpers(t *testing.T) {
138138
},
139139
{
140140
funcName: "{{is_service_principal}}",
141-
expected: strconv.FormatBool(auth.IsServicePrincipal(me.Id)),
141+
expected: strconv.FormatBool(auth.IsServicePrincipal(me.UserName)),
142142
},
143143
{
144144
funcName: "{{smallest_node_type}}",

libs/auth/service_principal.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import (
44
"github.com/google/uuid"
55
)
66

7-
// Determines whether a given user id is a service principal.
8-
// This function uses a heuristic: if the user id is a UUID, then we assume
7+
// Determines whether a given user name is a service principal.
8+
// This function uses a heuristic: if the user name is a UUID, then we assume
99
// it's a service principal. Unfortunately, the service principal listing API is too
1010
// slow for our purposes. And the "users" and "service principals get" APIs
1111
// only allow access by workspace admins.
12-
func IsServicePrincipal(userId string) bool {
13-
_, err := uuid.Parse(userId)
12+
func IsServicePrincipal(userName string) bool {
13+
_, err := uuid.Parse(userName)
1414
return err == nil
1515
}

libs/template/helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func loadHelpers(ctx context.Context) template.FuncMap {
140140
return false, err
141141
}
142142
}
143-
result := auth.IsServicePrincipal(cachedUser.Id)
143+
result := auth.IsServicePrincipal(cachedUser.UserName)
144144
cachedIsServicePrincipal = &result
145145
return result, nil
146146
},

0 commit comments

Comments
 (0)