From 9cf3dbe686302708f8d1afa4fc1f3cd89e2c49e3 Mon Sep 17 00:00:00 2001 From: Andrew Nester Date: Mon, 25 Mar 2024 12:32:45 +0100 Subject: [PATCH] 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 --- internal/init_test.go | 2 +- libs/auth/service_principal.go | 8 ++++---- libs/template/helpers.go | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/init_test.go b/internal/init_test.go index bed1119f..c3cb0127 100644 --- a/internal/init_test.go +++ b/internal/init_test.go @@ -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}}", diff --git a/libs/auth/service_principal.go b/libs/auth/service_principal.go index cb488d16..5f1854e3 100644 --- a/libs/auth/service_principal.go +++ b/libs/auth/service_principal.go @@ -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 } diff --git a/libs/template/helpers.go b/libs/template/helpers.go index 56710dfb..d15a801d 100644 --- a/libs/template/helpers.go +++ b/libs/template/helpers.go @@ -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 },