Skip to content

Commit ee769d5

Browse files
feat(k8s): detection helpers, CBMLanguage enum, and language table entries
- Add CBM_LANG_KUSTOMIZE and CBM_LANG_K8S to CBMLanguage enum (before CBM_LANG_COUNT) - Add kustomization.yaml/yml to FILENAME_TABLE mapped to CBM_LANG_KUSTOMIZE - Add Kustomize and Kubernetes entries to LANG_NAMES - Implement cbm_is_kustomize_file() with to_lower+strcmp pattern - Implement cbm_is_k8s_manifest() scanning first 4KB for apiVersion: via ci_strstr() - Declare both helpers in pipeline_internal.h Infrascan helpers section Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 75b5dcb commit ee769d5

4 files changed

Lines changed: 27 additions & 0 deletions

File tree

internal/cbm/cbm.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ typedef enum {
7575
CBM_LANG_FORM,
7676
CBM_LANG_MAGMA,
7777
CBM_LANG_WOLFRAM,
78+
CBM_LANG_KUSTOMIZE, // kustomization.yaml — Kubernetes overlay tool
79+
CBM_LANG_K8S, // Generic Kubernetes manifest (apiVersion: detected)
7880
CBM_LANG_COUNT
7981
} CBMLanguage;
8082

src/discover/language.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,8 @@ static const filename_entry_t FILENAME_TABLE[] = {
273273
{"GNUmakefile", CBM_LANG_MAKEFILE}, {"Makefile", CBM_LANG_MAKEFILE},
274274
{"makefile", CBM_LANG_MAKEFILE}, {"meson.build", CBM_LANG_MESON},
275275
{"meson.options", CBM_LANG_MESON}, {"meson_options.txt", CBM_LANG_MESON},
276+
{"kustomization.yaml", CBM_LANG_KUSTOMIZE},
277+
{"kustomization.yml", CBM_LANG_KUSTOMIZE},
276278
{".vimrc", CBM_LANG_VIMSCRIPT},
277279
};
278280

@@ -345,6 +347,8 @@ static const char *LANG_NAMES[CBM_LANG_COUNT] = {
345347
[CBM_LANG_FORM] = "FORM",
346348
[CBM_LANG_MAGMA] = "Magma",
347349
[CBM_LANG_WOLFRAM] = "Wolfram",
350+
[CBM_LANG_KUSTOMIZE] = "Kustomize",
351+
[CBM_LANG_K8S] = "Kubernetes",
348352
};
349353

350354
/* ── Public API ──────────────────────────────────────────────────── */

src/pipeline/pass_infrascan.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,25 @@ bool cbm_is_env_file(const char *name) {
192192
return false;
193193
}
194194

195+
bool cbm_is_kustomize_file(const char *name) {
196+
if (!name) { return false; }
197+
char lower[256];
198+
to_lower(name, lower, sizeof(lower));
199+
return (strcmp(lower, "kustomization.yaml") == 0 ||
200+
strcmp(lower, "kustomization.yml") == 0);
201+
}
202+
203+
// NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
204+
bool cbm_is_k8s_manifest(const char *name, const char *content) {
205+
if (!name || !content || cbm_is_kustomize_file(name)) { return false; }
206+
char buf[4097];
207+
size_t n = strlen(content);
208+
if (n > 4096) { n = 4096; }
209+
memcpy(buf, content, n);
210+
buf[n] = '\0';
211+
return ci_strstr(buf, "apiVersion:") != NULL;
212+
}
213+
195214
// NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
196215
bool cbm_is_shell_script(const char *name, const char *ext) {
197216
(void)name;

src/pipeline/pipeline_internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ bool cbm_is_compose_file(const char *name);
218218
bool cbm_is_cloudbuild_file(const char *name);
219219
bool cbm_is_env_file(const char *name);
220220
bool cbm_is_shell_script(const char *name, const char *ext);
221+
bool cbm_is_kustomize_file(const char *name);
222+
bool cbm_is_k8s_manifest(const char *name, const char *content);
221223

222224
/* Secret detection */
223225
bool cbm_is_secret_binding(const char *key, const char *value);

0 commit comments

Comments
 (0)