|
4 | 4 | "encoding/json" |
5 | 5 | "errors" |
6 | 6 | "fmt" |
| 7 | + "strings" |
7 | 8 |
|
8 | 9 | "cuelang.org/go/cue" |
9 | 10 | "github.com/meshery/meshkit/utils" |
@@ -58,6 +59,34 @@ var OpenAPISpecPathConfig = CuePathConfig{ |
58 | 59 |
|
59 | 60 | var Configs = []CuePathConfig{DefaultPathConfig, DefaultPathConfig2} |
60 | 61 |
|
| 62 | +// GroupToModel determines the model name and display name from a CRD/OpenAPI group value. |
| 63 | +// - If group is non-empty, model name is the exact group (e.g., "monitor.azure.com"). |
| 64 | +// Display name is a title-cased, dot-separated host converted to words (e.g., "Monitor Azure Com"). |
| 65 | +// - If group is empty, fallbackName and its formatted variant are used. |
| 66 | +func GroupToModel(group, fallbackName string) (modelName, displayName string) { |
| 67 | + if strings.TrimSpace(group) != "" { |
| 68 | + // Title case each dot-separated part and join with space for display name |
| 69 | + parts := strings.Split(group, ".") |
| 70 | + for i := range parts { |
| 71 | + if parts[i] == "" { |
| 72 | + continue |
| 73 | + } |
| 74 | + parts[i] = strings.ToUpper(parts[i][:1]) + strings.ToLower(parts[i][1:]) |
| 75 | + } |
| 76 | + return group, strings.Join(parts, " ") |
| 77 | + } |
| 78 | + return fallbackName, manifests.FormatToReadableString(fallbackName) |
| 79 | +} |
| 80 | + |
| 81 | +// ExtractGroupFromAPIVersion returns the API group from a k8s apiVersion string like "group/version". |
| 82 | +// If apiVersion does not contain '/', it returns an empty string. |
| 83 | +func ExtractGroupFromAPIVersion(apiVersion string) string { |
| 84 | + if strings.Contains(apiVersion, "/") { |
| 85 | + return strings.SplitN(apiVersion, "/", 2)[0] |
| 86 | + } |
| 87 | + return "" |
| 88 | +} |
| 89 | + |
61 | 90 | func IncludeComponentBasedOnGroup(resource string, groupFilter string) (bool, error) { |
62 | 91 | if groupFilter == "" { |
63 | 92 | return true, nil |
|
0 commit comments