From b53b569b51a6b226322bd1da192df08d3c727e0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Costa?= Date: Fri, 12 Jan 2024 12:59:15 +0000 Subject: [PATCH] addded condition to prevent previous users and groups from being wiped if sync request fails MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Costa --- .../providers/GithubMultiOrgEntityProvider.ts | 29 ++++++++++-------- .../src/providers/GithubOrgEntityProvider.ts | 30 +++++++++++-------- .../src/processors/LdapOrgEntityProvider.ts | 23 +++++++------- .../MicrosoftGraphOrgEntityProvider.ts | 23 +++++++------- 4 files changed, 59 insertions(+), 46 deletions(-) diff --git a/plugins/catalog-backend-module-github/src/providers/GithubMultiOrgEntityProvider.ts b/plugins/catalog-backend-module-github/src/providers/GithubMultiOrgEntityProvider.ts index cabb9e21ce..858095e766 100644 --- a/plugins/catalog-backend-module-github/src/providers/GithubMultiOrgEntityProvider.ts +++ b/plugins/catalog-backend-module-github/src/providers/GithubMultiOrgEntityProvider.ts @@ -298,21 +298,24 @@ export class GithubMultiOrgEntityProvider implements EntityProvider { } const allUsers = Array.from(allUsersMap.values()); + if (allUsers.length > 0 || allTeams.length > 0) { + const { markCommitComplete } = markReadComplete({ allUsers, allTeams }); - const { markCommitComplete } = markReadComplete({ allUsers, allTeams }); + await this.connection.applyMutation({ + type: 'full', + entities: [...allUsers, ...allTeams].map(entity => ({ + locationKey: `github-multi-org-provider:${this.options.id}`, + entity: withLocations( + `https://${this.options.gitHubConfig.host}`, + entity, + ), + })), + }); - await this.connection.applyMutation({ - type: 'full', - entities: [...allUsers, ...allTeams].map(entity => ({ - locationKey: `github-multi-org-provider:${this.options.id}`, - entity: withLocations( - `https://${this.options.gitHubConfig.host}`, - entity, - ), - })), - }); - - markCommitComplete(); + markCommitComplete(); + } else { + logger.info('No users or teams to process'); + } } private supportsEventTopics(): string[] { diff --git a/plugins/catalog-backend-module-github/src/providers/GithubOrgEntityProvider.ts b/plugins/catalog-backend-module-github/src/providers/GithubOrgEntityProvider.ts index 0fe61aa229..a3ff980fd6 100644 --- a/plugins/catalog-backend-module-github/src/providers/GithubOrgEntityProvider.ts +++ b/plugins/catalog-backend-module-github/src/providers/GithubOrgEntityProvider.ts @@ -229,21 +229,25 @@ export class GithubOrgEntityProvider } } - const { markCommitComplete } = markReadComplete({ users, teams }); + if (users.length > 0 || teams.length > 0) { + const { markCommitComplete } = markReadComplete({ users, teams }); - await this.connection.applyMutation({ - type: 'full', - entities: [...users, ...teams].map(entity => ({ - locationKey: `github-org-provider:${this.options.id}`, - entity: withLocations( - `https://${this.options.gitHubConfig.host}`, - org, - entity, - ), - })), - }); + await this.connection.applyMutation({ + type: 'full', + entities: [...users, ...teams].map(entity => ({ + locationKey: `github-org-provider:${this.options.id}`, + entity: withLocations( + `https://${this.options.gitHubConfig.host}`, + org, + entity, + ), + })), + }); - markCommitComplete(); + markCommitComplete(); + } else { + logger.info('No users or teams to process'); + } } /** {@inheritdoc @backstage/plugin-events-node#EventSubscriber.onEvent} */ diff --git a/plugins/catalog-backend-module-ldap/src/processors/LdapOrgEntityProvider.ts b/plugins/catalog-backend-module-ldap/src/processors/LdapOrgEntityProvider.ts index d4f19d0522..ced28face8 100644 --- a/plugins/catalog-backend-module-ldap/src/processors/LdapOrgEntityProvider.ts +++ b/plugins/catalog-backend-module-ldap/src/processors/LdapOrgEntityProvider.ts @@ -192,18 +192,21 @@ export class LdapOrgEntityProvider implements EntityProvider { logger, }, ); + if (users.length > 0 || groups.length > 0) { + const { markCommitComplete } = markReadComplete({ users, groups }); - const { markCommitComplete } = markReadComplete({ users, groups }); + await this.connection.applyMutation({ + type: 'full', + entities: [...users, ...groups].map(entity => ({ + locationKey: `ldap-org-provider:${this.options.id}`, + entity: withLocations(this.options.id, entity), + })), + }); - await this.connection.applyMutation({ - type: 'full', - entities: [...users, ...groups].map(entity => ({ - locationKey: `ldap-org-provider:${this.options.id}`, - entity: withLocations(this.options.id, entity), - })), - }); - - markCommitComplete(); + markCommitComplete(); + } else { + logger.info('No users or teams to process'); + } } private schedule(schedule: LdapOrgEntityProviderOptions['schedule']) { diff --git a/plugins/catalog-backend-module-msgraph/src/processors/MicrosoftGraphOrgEntityProvider.ts b/plugins/catalog-backend-module-msgraph/src/processors/MicrosoftGraphOrgEntityProvider.ts index 160696e2e7..3a3d5c29c4 100644 --- a/plugins/catalog-backend-module-msgraph/src/processors/MicrosoftGraphOrgEntityProvider.ts +++ b/plugins/catalog-backend-module-msgraph/src/processors/MicrosoftGraphOrgEntityProvider.ts @@ -323,18 +323,21 @@ export class MicrosoftGraphOrgEntityProvider implements EntityProvider { logger: logger, }, ); + if (users.length > 0 || groups.length > 0) { + const { markCommitComplete } = markReadComplete({ users, groups }); - const { markCommitComplete } = markReadComplete({ users, groups }); + await this.connection.applyMutation({ + type: 'full', + entities: [...users, ...groups].map(entity => ({ + locationKey: `msgraph-org-provider:${this.options.id}`, + entity: withLocations(this.options.id, entity), + })), + }); - await this.connection.applyMutation({ - type: 'full', - entities: [...users, ...groups].map(entity => ({ - locationKey: `msgraph-org-provider:${this.options.id}`, - entity: withLocations(this.options.id, entity), - })), - }); - - markCommitComplete(); + markCommitComplete(); + } else { + logger.info('No users or teams to process'); + } } private schedule(taskRunner: TaskRunner) {