Skip to content
This repository has been archived by the owner on Jun 25, 2024. It is now read-only.

INT-7913: fix Audit Config log type additional property #589

Merged
merged 2 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/steps/resource-manager/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,14 @@ describe('flattenAuditLogConfigs', () => {
{ exemptedMembers: ['[email protected]', '[email protected]'], logType: 'type2' },
]),
).toEqual([
{ exemptedMember: '[email protected]', logTypes: ['type1', 'type2'] },
{ exemptedMember: '[email protected]', logTypes: ['type1', 'type2'] },
{
exemptedMember: '[email protected]',
logTypes: { 'logType.type1': true, 'logType.type2': true },
},
{
exemptedMember: '[email protected]',
logTypes: { 'logType.type1': true, 'logType.type2': true },
},
]);
});

Expand All @@ -50,15 +56,15 @@ describe('flattenAuditLogConfigs', () => {
flattenAuditLogConfigs([
{ exemptedMembers: ['[email protected]'], logType: null },
]),
).toEqual([{ exemptedMember: '[email protected]', logTypes: [] }]);
).toEqual([{ exemptedMember: '[email protected]', logTypes: {} }]);
});

test('should return empty array for `undefined` logType', () => {
expect(
flattenAuditLogConfigs([
{ exemptedMembers: ['[email protected]'], logType: undefined },
]),
).toEqual([{ exemptedMember: '[email protected]', logTypes: [] }]);
).toEqual([{ exemptedMember: '[email protected]', logTypes: {} }]);
});

test('should skip `null` exemptedMembers', () => {
Expand Down
16 changes: 12 additions & 4 deletions src/steps/resource-manager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ export async function fetchIamPolicyAuditConfig(
parsedMember,
logger,
projectId: client.projectId,
additionalProperties: { logTypes },
additionalProperties: { ...logTypes },
relationshipClass: RelationshipClass.ALLOWS,
});

Expand All @@ -357,15 +357,15 @@ export async function fetchIamPolicyAuditConfig(
* =>
*
* [
* { exemptedMember: ['[email protected]'], logTypes: ['type1', 'type2' ] }
* { exemptedMember: ['[email protected]'], logTypes: { 'logType.type1': true, 'logType.type2': true } }
* ]
*
*/
export function flattenAuditLogConfigs(
auditLogConfigs: cloudresourcemanager_v3.Schema$AuditLogConfig[],
): {
exemptedMember: string;
logTypes: string[];
logTypes: { [key: string]: boolean };
}[] {
const exemptedMemberToLogTypesMap: { [exemptedMember: string]: string[] } =
{};
Expand All @@ -384,7 +384,15 @@ export function flattenAuditLogConfigs(
}

return Object.entries(exemptedMemberToLogTypesMap).map(
([exemptedMember, logTypes]) => ({ exemptedMember, logTypes }),
([exemptedMember, logTypes]) => {
const parsedLogtype = {};

for (const logType of logTypes) {
parsedLogtype[`logType.${logType}`] = true;
}

return { exemptedMember, logTypes: parsedLogtype };
gastonyelmini marked this conversation as resolved.
Show resolved Hide resolved
},
);
}

Expand Down