From abdbf0e56da255a90ffb876da0950ec7715dd2c8 Mon Sep 17 00:00:00 2001 From: stevenGravy Date: Sat, 30 Nov 2024 11:07:10 -0500 Subject: [PATCH 1/4] update access request errors to not repeat cluster names --- lib/services/access_request.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/services/access_request.go b/lib/services/access_request.go index 19a9c33bd8064..bce5d5a7bb578 100644 --- a/lib/services/access_request.go +++ b/lib/services/access_request.go @@ -109,6 +109,11 @@ func ValidateAccessRequestClusterNames(cg ClusterGetter, ar types.AccessRequest) } } if len(invalidClusters) > 0 { + // Multiple resources are requestable with the same or different cluster names. + // Prior to showing the error message, sort the list and remove duplicates so + // the same cluster name isn't repeated. + slices.Sort(invalidClusters) + invalidClusters = slices.Compact(invalidClusters) return trace.NotFound("access request contains invalid or unknown cluster names: %v", strings.Join(invalidClusters, ", ")) } From 9c2ce49d55be223398059c8f468a67d2baec61c1 Mon Sep 17 00:00:00 2001 From: stevenGravy Date: Sat, 30 Nov 2024 12:06:19 -0500 Subject: [PATCH 2/4] lint fix for access request --- lib/services/access_request.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/services/access_request.go b/lib/services/access_request.go index bce5d5a7bb578..342412cc59272 100644 --- a/lib/services/access_request.go +++ b/lib/services/access_request.go @@ -109,11 +109,11 @@ func ValidateAccessRequestClusterNames(cg ClusterGetter, ar types.AccessRequest) } } if len(invalidClusters) > 0 { - // Multiple resources are requestable with the same or different cluster names. - // Prior to showing the error message, sort the list and remove duplicates so - // the same cluster name isn't repeated. - slices.Sort(invalidClusters) - invalidClusters = slices.Compact(invalidClusters) + // Multiple resources are requestable with the same or different cluster names. + // Prior to showing the error message, sort the list and remove duplicates so + // the same cluster name isn't repeated. + slices.Sort(invalidClusters) + invalidClusters = slices.Compact(invalidClusters) return trace.NotFound("access request contains invalid or unknown cluster names: %v", strings.Join(invalidClusters, ", ")) } From 1b5538db23dff0b21d4d5321a20ec448c44c11f0 Mon Sep 17 00:00:00 2001 From: Steven Martin Date: Sun, 1 Dec 2024 20:44:24 -0500 Subject: [PATCH 3/4] update to use deduplication for invalid cluster names Co-authored-by: Zac Bergquist --- lib/services/access_request.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/services/access_request.go b/lib/services/access_request.go index 342412cc59272..98ce77a23864c 100644 --- a/lib/services/access_request.go +++ b/lib/services/access_request.go @@ -109,13 +109,8 @@ func ValidateAccessRequestClusterNames(cg ClusterGetter, ar types.AccessRequest) } } if len(invalidClusters) > 0 { - // Multiple resources are requestable with the same or different cluster names. - // Prior to showing the error message, sort the list and remove duplicates so - // the same cluster name isn't repeated. - slices.Sort(invalidClusters) - invalidClusters = slices.Compact(invalidClusters) return trace.NotFound("access request contains invalid or unknown cluster names: %v", - strings.Join(invalidClusters, ", ")) + strings.Join(utils.Deduplicate(invalidClusters), ", ")) } return nil } From 426dcee56298f3c2ab329ac0fa80c24e65260fe7 Mon Sep 17 00:00:00 2001 From: stevenGravy Date: Sun, 1 Dec 2024 21:57:48 -0500 Subject: [PATCH 4/4] update deduplicate call --- lib/services/access_request.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/services/access_request.go b/lib/services/access_request.go index 98ce77a23864c..fd7ee8e9cb225 100644 --- a/lib/services/access_request.go +++ b/lib/services/access_request.go @@ -110,7 +110,7 @@ func ValidateAccessRequestClusterNames(cg ClusterGetter, ar types.AccessRequest) } if len(invalidClusters) > 0 { return trace.NotFound("access request contains invalid or unknown cluster names: %v", - strings.Join(utils.Deduplicate(invalidClusters), ", ")) + strings.Join(apiutils.Deduplicate(invalidClusters), ", ")) } return nil }