Skip to content

Commit

Permalink
feat: ignore retired users for contract key count
Browse files Browse the repository at this point in the history
  • Loading branch information
diegofigs committed Dec 3, 2024
1 parent 27e4c64 commit 3aae729
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/hungry-sloths-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"backstage-blockchain-actions": patch
---

feat: ignore retired users for contract key count
5 changes: 5 additions & 0 deletions src/core/base-collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
isApiEntity,
isResourceEntity,
isSystemEntity,
isUserEntity,
stringifyEntityRef,
} from "@backstage/catalog-model";
import type { Entity } from "@backstage/catalog-model";
Expand Down Expand Up @@ -31,6 +32,10 @@ export class BaseCollector {
return this.entities.filter(isResourceEntity).sort(this.sortByName);
}

getUserEntities(): Entity[] {
return this.entities.filter(isUserEntity).sort(this.sortByName);
}

getEntityTags(entity: Entity): string[] {
return entity.metadata.tags || [];
}
Expand Down
12 changes: 12 additions & 0 deletions src/helpers/backstage-metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,12 +503,24 @@ function generateContractAccessKeyMetrics(
collector: MetricsCollector,
backstageUrl: string,
) {
const retiredUsers = collector
.getUserEntities()
.filter(
(user) => user.metadata.tags && user.metadata.tags.includes("retired"),
);
const accessKeysPerContract = collector
.getContractAccessKeys()
.reduce<KeysByOwner>((acc, key) => {
// inferred type is JsonObject, this converts to any
const spec = JSON.parse(JSON.stringify(key.spec));
const { owner } = spec;
if (
retiredUsers.find(
(user) => `user:default/${user.metadata.name}` === owner,
)
) {
return { ...acc };
}
return {
...acc,
[owner]: [...(acc[owner] || []), key],
Expand Down

0 comments on commit 3aae729

Please sign in to comment.