(data map[string]interface{})
| 264 | } |
| 265 | |
| 266 | func (c *OperatorUsageCommand) namespacesOutput(data map[string]interface{}) []string { |
| 267 | byNs, ok := data["by_namespace"].([]interface{}) |
| 268 | if !ok { |
| 269 | c.UI.Error("missing namespace breakdown in response") |
| 270 | return nil |
| 271 | } |
| 272 | |
| 273 | nsOut := make([]UsageCommandNamespace, 0, len(byNs)) |
| 274 | |
| 275 | for _, rawVal := range byNs { |
| 276 | val, err := c.parseNamespaceCount(rawVal) |
| 277 | if err != nil { |
| 278 | c.UI.Error(fmt.Sprintf("malformed namespace in response: %v", err)) |
| 279 | continue |
| 280 | } |
| 281 | |
| 282 | sortOrder := "1" + val.namespacePath |
| 283 | if val.namespacePath == "" { |
| 284 | val.namespacePath = "[root]" |
| 285 | sortOrder = "0" |
| 286 | } else if strings.HasPrefix(val.namespacePath, "deleted namespace") { |
| 287 | sortOrder = "2" + val.namespacePath |
| 288 | } |
| 289 | |
| 290 | formattedLine := fmt.Sprintf("%s | %d | %d | %d | %d | %d", |
| 291 | val.namespacePath, val.entityCount, val.tokenCount, val.secretSyncs, val.acmeCount, val.clientCount) |
| 292 | nsOut = append(nsOut, UsageCommandNamespace{ |
| 293 | formattedLine: formattedLine, |
| 294 | sortOrder: sortOrder, |
| 295 | }) |
| 296 | } |
| 297 | |
| 298 | sort.Slice(nsOut, func(i, j int) bool { |
| 299 | return nsOut[i].sortOrder < nsOut[j].sortOrder |
| 300 | }) |
| 301 | |
| 302 | out := make([]string, len(nsOut)) |
| 303 | for i := range nsOut { |
| 304 | out[i] = nsOut[i].formattedLine |
| 305 | } |
| 306 | |
| 307 | return out |
| 308 | } |
| 309 | |
| 310 | func (c *OperatorUsageCommand) totalOutput(data map[string]interface{}) []string { |
| 311 | // blank line separating it from namespaces |
no test coverage detected