@@ -16,11 +16,14 @@ package audit
16
16
import (
17
17
"errors"
18
18
"fmt"
19
+ "reflect"
20
+ "sort"
21
+ "strings"
22
+
19
23
"github.com/dustin/go-humanize"
20
24
"github.com/nats-io/nats-server/v2/server"
21
25
"github.com/nats-io/natscli/internal/archive"
22
- "reflect"
23
- "sort"
26
+ "golang.org/x/exp/maps"
24
27
)
25
28
26
29
// checkClusterMemoryUsageOutliers creates a parametrized check to verify the memory usage of any given node in a
@@ -214,3 +217,57 @@ func makeCheckClusterHighHAAssets(haAssetsThreshold int) checkFunc {
214
217
return Pass , nil
215
218
}
216
219
}
220
+
221
+ func checkClusterNamesForWhitespace (reader * archive.Reader , examples * ExamplesCollection ) (Outcome , error ) {
222
+
223
+ for _ , clusterName := range reader .GetClusterNames () {
224
+ if strings .Contains (clusterName , " " ) {
225
+ examples .add ("Cluster: %s" , clusterName )
226
+ }
227
+ }
228
+
229
+ if examples .Count () > 0 {
230
+ logCritical ("Found %d clusters with names containing whitespace" , examples .Count ())
231
+ return Fail , nil
232
+ }
233
+
234
+ return Pass , nil
235
+ }
236
+
237
+ func checkLeafnodeServerNamesForWhitespace (r * archive.Reader , examples * ExamplesCollection ) (Outcome , error ) {
238
+
239
+ for _ , clusterName := range r .GetClusterNames () {
240
+ clusterTag := archive .TagCluster (clusterName )
241
+
242
+ leafnodesWithWhitespace := map [string ]struct {}{}
243
+
244
+ for _ , serverName := range r .GetClusterServerNames (clusterName ) {
245
+ serverTag := archive .TagServer (serverName )
246
+
247
+ var serverLeafz server.Leafz
248
+ err := r .Load (& serverLeafz , clusterTag , serverTag , archive .TagServerLeafs ())
249
+ if err != nil {
250
+ logWarning ("Artifact 'LEAFZ' is missing for server %s" , serverName )
251
+ continue
252
+ }
253
+
254
+ for _ , leaf := range serverLeafz .Leafs {
255
+ // check if leafnode name contains whitespace
256
+ if strings .Contains (leaf .Name , " " ) {
257
+ leafnodesWithWhitespace [leaf .Name ] = struct {}{}
258
+ }
259
+ }
260
+ }
261
+
262
+ if len (leafnodesWithWhitespace ) > 0 {
263
+ examples .add ("Cluster %s: %v" , clusterName , maps .Keys (leafnodesWithWhitespace ))
264
+ }
265
+ }
266
+
267
+ if examples .Count () > 0 {
268
+ logCritical ("Found %d clusters with leafnode names containing whitespace" , examples .Count ())
269
+ return Fail , nil
270
+ }
271
+
272
+ return Pass , nil
273
+ }
0 commit comments