Skip to content

Commit 00a835b

Browse files
authored
Mariano/fix 11 (#1898)
* refactor(api): enhance variable handling in VariablesController
1 parent 764d605 commit 00a835b

File tree

3 files changed

+46
-6
lines changed

3 files changed

+46
-6
lines changed

apps/api/src/integration-platform/controllers/variables.controller.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,15 @@ export class VariablesController {
6262
);
6363
}
6464

65-
// Collect all unique variables from all checks
65+
// Collect all unique variables from manifest-level and checks
6666
const variableMap = new Map<string, CheckVariable>();
6767

68+
// First, add manifest-level variables
69+
for (const variable of manifest.variables || []) {
70+
variableMap.set(variable.id, variable);
71+
}
72+
73+
// Then, add check-specific variables (won't override manifest-level)
6874
for (const check of manifest.checks || []) {
6975
for (const variable of check.variables || []) {
7076
if (!variableMap.has(variable.id)) {
@@ -115,8 +121,15 @@ export class VariablesController {
115121
);
116122
}
117123

118-
// Collect all unique variables
124+
// Collect all unique variables from manifest-level and checks
119125
const variableMap = new Map<string, CheckVariable>();
126+
127+
// First, add manifest-level variables
128+
for (const variable of manifest.variables || []) {
129+
variableMap.set(variable.id, variable);
130+
}
131+
132+
// Then, add check-specific variables
120133
for (const check of manifest.checks || []) {
121134
for (const variable of check.variables || []) {
122135
if (!variableMap.has(variable.id)) {
@@ -184,11 +197,18 @@ export class VariablesController {
184197
);
185198
}
186199

187-
// Find the variable definition
200+
// Find the variable definition (check manifest-level first, then checks)
188201
let variable: CheckVariable | undefined;
189-
for (const check of manifest.checks || []) {
190-
variable = check.variables?.find((v) => v.id === variableId);
191-
if (variable) break;
202+
203+
// Check manifest-level variables
204+
variable = manifest.variables?.find((v) => v.id === variableId);
205+
206+
// If not found, check in check-specific variables
207+
if (!variable) {
208+
for (const check of manifest.checks || []) {
209+
variable = check.variables?.find((v) => v.id === variableId);
210+
if (variable) break;
211+
}
192212
}
193213

194214
if (!variable) {

packages/integration-platform/src/manifests/gcp/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,18 @@ This is industry standard - all GCP security monitoring tools use the same scope
6161

6262
capabilities: ['checks'],
6363

64+
// Integration-level variables (used by cloud security scanning)
65+
variables: [
66+
{
67+
id: 'organization_id',
68+
label: 'GCP Organization ID',
69+
type: 'text',
70+
required: true,
71+
helpText:
72+
'Your GCP Organization ID (numeric). Find it at: console.cloud.google.com/iam-admin/settings',
73+
placeholder: '123456789012',
74+
},
75+
],
76+
6477
checks: [],
6578
};

packages/integration-platform/src/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,13 @@ export interface IntegrationManifest {
735735
/** Capabilities this integration supports */
736736
capabilities: IntegrationCapability[];
737737

738+
/**
739+
* Integration-level variables that are collected after authentication.
740+
* These can be used by checks OR by standalone features (like cloud security scanning).
741+
* Variables defined here are merged with check-specific variables.
742+
*/
743+
variables?: CheckVariable[];
744+
738745
/**
739746
* Compliance checks this integration can run.
740747
* Each check can auto-complete linked tasks when passing.

0 commit comments

Comments
 (0)