Skip to content

Commit

Permalink
handle unexpected errors around uninstall tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
gergoabraham committed Jan 31, 2024
1 parent a846f8d commit a170752
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions x-pack/plugins/fleet/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -703,8 +703,21 @@ export class FleetPlugin
}

private async initializeUninstallTokens() {
await this.generateUninstallTokens();
this.validateUninstallTokens();
try {
await this.generateUninstallTokens();
} catch (error) {
appContextService
.getLogger()
.error('Error happened during uninstall token generation.', { error: { message: error } });
}

try {
await this.validateUninstallTokens();
} catch (error) {
appContextService
.getLogger()
.error('Error happened during uninstall token validation.', { error: { message: error } });
}
}

private async generateUninstallTokens() {
Expand All @@ -724,24 +737,18 @@ export class FleetPlugin
}
}

private validateUninstallTokens() {
private async validateUninstallTokens() {
const logger = appContextService.getLogger();
const uninstallTokenService = appContextService.getUninstallTokenService();

logger.debug('Validating uninstall tokens');
uninstallTokenService
?.checkTokenValidityForAllPolicies()
.catch((error) => {
logger.error('Error happened during uninstall token validation.', {
error: { message: error },
});
})
.then((unintallTokenValidationError) => {
if (unintallTokenValidationError) {
logger.warn(unintallTokenValidationError.error);
} else {
logger.debug('Uninstall tokens validation successful.');
}
});

const unintallTokenValidationError = await appContextService
.getUninstallTokenService()
?.checkTokenValidityForAllPolicies();

if (unintallTokenValidationError) {
logger.warn(unintallTokenValidationError.error);
} else {
logger.debug('Uninstall tokens validation successful.');
}
}
}

0 comments on commit a170752

Please sign in to comment.