Skip to content

Commit 4e39fb0

Browse files
committed
chore: code cleanup and api reports
1 parent 34ba0cb commit 4e39fb0

File tree

5 files changed

+18
-78
lines changed

5 files changed

+18
-78
lines changed

workspaces/redhat-resource-optimization/plugins/redhat-resource-optimization-backend/src/routes/costManagementAccess.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,6 @@ export const getCostManagementAccess: (
9595
clustersData.data?.forEach(
9696
(cluster: { value: string; cluster_alias: string }) => {
9797
if (cluster.cluster_alias && cluster.value) {
98-
logger.info(
99-
`Cluster: ${cluster.cluster_alias} -> ${cluster.value}`,
100-
);
10198
clusterDataMap[cluster.cluster_alias] = cluster.value;
10299
}
103100
},
@@ -132,13 +129,6 @@ export const getCostManagementAccess: (
132129
}
133130

134131
// RBAC Filtering: Single batch call for both cluster and cluster-project permissions
135-
logger.info(
136-
`Checking permissions for ${
137-
Object.keys(clusterDataMap).length
138-
} clusters and ${allProjects.length} projects`,
139-
);
140-
logger.info(`Cluster names: ${Object.keys(clusterDataMap).join(', ')}`);
141-
logger.info(`Projects: ${allProjects.join(', ')}`);
142132

143133
const { authorizedClusterIds, authorizedClusterProjects } =
144134
await filterAuthorizedClustersAndProjects(
@@ -150,16 +140,6 @@ export const getCostManagementAccess: (
150140
'cost',
151141
);
152142

153-
logger.info(
154-
`Authorization results: ${authorizedClusterIds.length} clusters, ${authorizedClusterProjects.length} cluster-project combinations`,
155-
);
156-
logger.info(`Authorized clusters: ${authorizedClusterIds.join(', ')}`);
157-
logger.info(
158-
`Authorized cluster-projects: ${authorizedClusterProjects
159-
.map(cp => `${cp.cluster}.${cp.project}`)
160-
.join(', ')}`,
161-
);
162-
163143
// Combine cluster names from both cluster-level and project-level permissions
164144
const finalAuthorizedClusterNames = [
165145
...new Set([

workspaces/redhat-resource-optimization/plugins/redhat-resource-optimization-backend/src/util/checkPermissions.ts

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,6 @@ export const filterAuthorizedClustersAndProjects = async (
238238
const allClusterNames: string[] = Object.keys(clusterDataMap);
239239
const allClusterIds: string[] = Object.values(clusterDataMap);
240240

241-
console.log(
242-
`[DEBUG] filterAuthorizedClustersAndProjects called with permissionType: ${permissionType}`,
243-
);
244-
console.log(`[DEBUG] Clusters to check: ${allClusterNames.join(', ')}`);
245-
console.log(`[DEBUG] Projects to check: ${allProjects.join(', ')}`);
246-
247241
// Early exit if no data
248242
if (allClusterNames.length === 0) {
249243
return {
@@ -269,7 +263,6 @@ export const filterAuthorizedClustersAndProjects = async (
269263
const clusterPermissionRequests: AuthorizePermissionRequest[] =
270264
allClusterNames.map(clusterName => {
271265
const perm = getClusterPermission(clusterName);
272-
console.log(`[DEBUG] Checking cluster permission: ${perm.name}`);
273266
return { permission: perm };
274267
});
275268

@@ -291,42 +284,20 @@ export const filterAuthorizedClustersAndProjects = async (
291284
permissionType === 'cost' ? clusterName : clusterId;
292285
const decision = clusterDecisions[i].result;
293286

294-
console.log(
295-
`[DEBUG] Cluster "${clusterName}" (id: ${clusterId}): ${decision}`,
296-
);
297-
298287
if (decision === AuthorizeResult.ALLOW) {
299288
// User has full cluster access
300-
console.log(
301-
`[DEBUG] Adding "${clusterIdentifier}" to clustersWithFullAccess`,
302-
);
303289
clustersWithFullAccess.add(clusterIdentifier);
304290
} else {
305291
// No cluster access - will need to check project-level permissions
306-
console.log(
307-
`[DEBUG] Adding cluster index ${i} to clustersWithoutFullAccess`,
308-
);
309292
clustersWithoutFullAccess.push(i);
310293
}
311294
}
312295

313-
console.log(
314-
`[DEBUG] Clusters with full access: ${Array.from(
315-
clustersWithFullAccess,
316-
).join(', ')}`,
317-
);
318-
console.log(
319-
`[DEBUG] Clusters without full access (count): ${clustersWithoutFullAccess.length}`,
320-
);
321-
322296
// Step 2: Check project-level permissions only for clusters without full access
323297
const authorizedClusterProjects: ClusterProjectResult[] = [];
324298
const clustersGrantedViaProjects = new Set<string>();
325299

326300
if (clustersWithoutFullAccess.length > 0 && allProjects.length > 0) {
327-
console.log(
328-
`[DEBUG] Checking project-level permissions for ${clustersWithoutFullAccess.length} clusters`,
329-
);
330301
const numProjectChecks =
331302
clustersWithoutFullAccess.length * allProjects.length;
332303
const projectPermissionRequests: AuthorizePermissionRequest[] = new Array(
@@ -344,16 +315,10 @@ export const filterAuthorizedClustersAndProjects = async (
344315
const clusterIdentifier =
345316
permissionType === 'cost' ? clusterName : clusterId;
346317

347-
console.log(
348-
`[DEBUG] Building project checks for cluster "${clusterName}"`,
349-
);
350-
351318
for (let j = 0; j < allProjects.length; j++) {
352319
const projectName = allProjects[j];
353320
const perm = getClusterProjectPermission(clusterName, projectName);
354321

355-
console.log(`[DEBUG] Will check: ${perm.name}`);
356-
357322
projectPermissionRequests[idx] = {
358323
permission: perm,
359324
};
@@ -376,45 +341,22 @@ export const filterAuthorizedClustersAndProjects = async (
376341
// Process project-level results
377342
for (let i = 0; i < projectDecisions.length; i++) {
378343
const decision = projectDecisions[i].result;
379-
const map = projectPermissionMap[i];
380-
381-
console.log(
382-
`[DEBUG] Project permission "${map.cluster}.${map.project}": ${decision}`,
383-
);
384344

385345
if (decision === AuthorizeResult.ALLOW) {
386346
const result = projectPermissionMap[i];
387347
authorizedClusterProjects.push(result);
388-
console.log(
389-
`[DEBUG] Adding cluster "${result.cluster}" to clustersGrantedViaProjects`,
390-
);
391348
// Project-level permission also grants cluster access
392349
clustersGrantedViaProjects.add(result.cluster);
393350
}
394351
}
395352
}
396353

397-
console.log(
398-
`[DEBUG] Clusters granted via projects: ${Array.from(
399-
clustersGrantedViaProjects,
400-
).join(', ')}`,
401-
);
402-
403354
// Step 3: Combine clusters from both full access and project-level grants
404355
const authorizedClusterIds = [
405356
...clustersWithFullAccess,
406357
...clustersGrantedViaProjects,
407358
];
408359

409-
console.log(
410-
`[DEBUG] Final authorized clusters: ${authorizedClusterIds.join(', ')}`,
411-
);
412-
console.log(
413-
`[DEBUG] Final authorized cluster-projects: ${authorizedClusterProjects
414-
.map(cp => `${cp.cluster}.${cp.project}`)
415-
.join(', ')}`,
416-
);
417-
418360
return {
419361
authorizedClusterIds,
420362
authorizedClusterProjects,

workspaces/redhat-resource-optimization/plugins/redhat-resource-optimization-common/report-clients.api.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ export interface CostManagementSlimApi {
113113
search?: string,
114114
options?: {
115115
token?: string;
116+
limit?: number;
116117
},
117118
): Promise<
118119
TypedResponse<{
@@ -139,6 +140,7 @@ export interface CostManagementSlimApi {
139140
search?: string,
140141
options?: {
141142
token?: string;
143+
limit?: number;
142144
},
143145
): Promise<
144146
TypedResponse<{
@@ -187,6 +189,7 @@ export class CostManagementSlimClient implements CostManagementSlimApi {
187189
search?: string,
188190
options?: {
189191
token?: string;
192+
limit?: number;
190193
},
191194
): Promise<
192195
TypedResponse<{
@@ -207,10 +210,13 @@ export class CostManagementSlimClient implements CostManagementSlimApi {
207210
links?: any;
208211
}>
209212
>;
213+
// Warning: (tsdoc-param-tag-with-invalid-name) The @param block should be followed by a valid parameter name: The identifier cannot non-word characters
214+
// Warning: (tsdoc-param-tag-with-invalid-name) The @param block should be followed by a valid parameter name: The identifier cannot non-word characters
210215
searchOpenShiftProjects(
211216
search?: string,
212217
options?: {
213218
token?: string;
219+
limit?: number;
214220
},
215221
): Promise<
216222
TypedResponse<{

workspaces/redhat-resource-optimization/plugins/redhat-resource-optimization-common/report-permissions.api.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
```ts
66
import { BasicPermission } from '@backstage/plugin-permission-common';
77

8+
// @public (undocumented)
9+
export const costClusterProjectPermission: (
10+
clusterName: string,
11+
projectName: string,
12+
) => BasicPermission;
13+
814
// @public (undocumented)
915
export const costClusterSpecificPermission: (
1016
clusterName: string,

workspaces/redhat-resource-optimization/plugins/redhat-resource-optimization-common/report.api.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ export interface CostManagementSlimApi {
111111
search?: string,
112112
options?: {
113113
token?: string;
114+
limit?: number;
114115
},
115116
): Promise<
116117
TypedResponse<{
@@ -137,6 +138,7 @@ export interface CostManagementSlimApi {
137138
search?: string,
138139
options?: {
139140
token?: string;
141+
limit?: number;
140142
},
141143
): Promise<
142144
TypedResponse<{
@@ -185,6 +187,7 @@ export class CostManagementSlimClient implements CostManagementSlimApi {
185187
search?: string,
186188
options?: {
187189
token?: string;
190+
limit?: number;
188191
},
189192
): Promise<
190193
TypedResponse<{
@@ -205,10 +208,13 @@ export class CostManagementSlimClient implements CostManagementSlimApi {
205208
links?: any;
206209
}>
207210
>;
211+
// Warning: (tsdoc-param-tag-with-invalid-name) The @param block should be followed by a valid parameter name: The identifier cannot non-word characters
212+
// Warning: (tsdoc-param-tag-with-invalid-name) The @param block should be followed by a valid parameter name: The identifier cannot non-word characters
208213
searchOpenShiftProjects(
209214
search?: string,
210215
options?: {
211216
token?: string;
217+
limit?: number;
212218
},
213219
): Promise<
214220
TypedResponse<{

0 commit comments

Comments
 (0)