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

INT-9845: limit extensions #220

Merged
merged 1 commit into from
Dec 12, 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
8 changes: 4 additions & 4 deletions src/gsuite/clients/GSuiteInstalledAppsClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ export class GSuiteInstalledAppsClient extends GSuiteChromeManagementClient {
): Promise<void> {
const client = await this.getAuthenticatedServiceClient();

const oneYearAgo = new Date();
oneYearAgo.setFullYear(oneYearAgo.getFullYear() - 1);
const oneYearAgoFormatted = oneYearAgo.toISOString().split('T')[0]; // Format date to YYYY-MM-DD
const threeMonths = new Date();
threeMonths.setMonth(threeMonths.getMonth() - 3);
const threeMonthsFormatted = threeMonths.toISOString().split('T')[0]; // Format date to YYYY-MM-DD

await this.iterateApi(
async () => {
return client.customers.reports.countInstalledApps({
customer: `customers/${this.accountId}`,
filter: `app_type=${appType} AND latest_profile_active_date>=${oneYearAgoFormatted}`,
filter: `app_type=${appType} AND latest_profile_active_date>=${threeMonthsFormatted}`,
});
},
async (data) => {
Expand Down
12 changes: 12 additions & 0 deletions src/steps/chrome-extensions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import { isAuthorizationError } from '../../utils/isAuthorizationError';

const APP_EXTENSION_TYPE = 'EXTENSION';

function isMultipleOfHundredThousand(num: number) {
return num % 100000 === 0;
}

export async function fetchChromeExtensions({
instance,
logger,
Expand All @@ -26,6 +30,8 @@ export async function fetchChromeExtensions({
logger: logger,
});

let processedCount = 0;

try {
await client.iterateInstalledApps(APP_EXTENSION_TYPE, async (app) => {
if (
Expand All @@ -35,6 +41,12 @@ export async function fetchChromeExtensions({
return;
}
await jobState.addEntity(createChromeExtensionEntity(app));

processedCount++;

if (isMultipleOfHundredThousand(processedCount)) {
logger.info(`Processing extensions: ${processedCount}`);
}
});
} catch (err) {
if (
Expand Down
22 changes: 16 additions & 6 deletions src/steps/groups/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ export async function fetchGroupSettings(
});

const quotaExceededWarnings: string[] = [];
const authWarnings: string[] = [];

await jobState.iterateEntities(
{ _type: entities.GROUP._type },
Expand Down Expand Up @@ -328,12 +329,14 @@ export async function fetchGroupSettings(
err.statusText.match(errorText),
).length > 0
) {
context.logger.publishWarnEvent({
name: IntegrationWarnEventName.MissingPermission,
description: `Could not ingest group setttings. Missing required scope(s) (scopes=${client.requiredScopes.join(
', ',
)}). Additionally, Groups -> Read Admin API Privilege needs to be enabled.`,
});
const authErrorWarningMessage = `Could not ingest group setttings. Missing required scope(s) (scopes=${client.requiredScopes.join(
', ',
)}). Additionally, Groups -> Read Admin API Privilege needs to be enabled.`;

if (!authWarnings.includes(authErrorWarningMessage)) {
authWarnings.push(authErrorWarningMessage);
}

return;
}

Expand All @@ -360,6 +363,13 @@ export async function fetchGroupSettings(
description: quotaExceededWarning,
});
}

for (const authWarning of authWarnings) {
context.logger.publishWarnEvent({
name: IntegrationWarnEventName.MissingPermission,
description: authWarning,
});
}
}

export const groupSteps: IntegrationStep<IntegrationConfig>[] = [
Expand Down
Loading