Skip to content

Commit

Permalink
feat(log): warn when defender resource does not exist (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
shahnami authored Oct 3, 2024
1 parent 4b5ae4c commit 2544009
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import {
NotificationOrDefenderID,
NotifyConfig,
} from '../types/types/resources.schema';
import Logger from './logger';

const getDefenderIdFromResource = <Y>(resource: Y, resourceType: ResourceType): DefenderID => {
switch (resourceType) {
Expand Down Expand Up @@ -86,10 +87,16 @@ export const getEquivalentResource = <Y, D>(
) => {
if (resource) {
if (isDefenderId(resource)) {
return currentResources.find((e) => getDefenderIdFromResource(e, type) === resource);
const foundResource = currentResources.find((e) => getDefenderIdFromResource(e, type) === resource);
if (!foundResource) Logger.getInstance().warn(`Resource ${resource} not found in Defender. Skipping...`);
return foundResource;
}
const [key, value] = Object.entries(resources ?? {}).find((a) => _.isEqual(a[1], resource))!;
return currentResources.find((e) => (e as any).stackResourceId === getResourceID(getStackName(context), key));
const foundResource = currentResources.find(
(e) => (e as any).stackResourceId === getResourceID(getStackName(context), key),
);
if (!foundResource) Logger.getInstance().warn(`Resource ${key} not found in Defender. Skipping...`);
return foundResource;
}
};

Expand Down

0 comments on commit 2544009

Please sign in to comment.