fix: handle missing orgEnabled config key gracefully by logging and returning early. Fixes #24857

Signed-off-by: ElaineDeMattosSilvaB <elaine.de-mattos-silva-bezerra@deutschebahn.com>
This commit is contained in:
ElaineDeMattosSilvaB
2024-05-22 10:13:30 +02:00
parent 85d9346ef1
commit a7810510fc
2 changed files with 10 additions and 9 deletions
@@ -75,16 +75,16 @@ describe('GitlabOrgDiscoveryEntityProvider - configuration', () => {
}).toThrow('No gitlab integration found that matches host example.com');
});
it('should throw error when org configuration not found', () => {
it('should log a message and return when org configuration not found', () => {
const schedule = new PersistingTaskRunner();
const config = new ConfigReader(mock.config_no_org_integration);
expect(() => {
GitlabOrgDiscoveryEntityProvider.fromConfig(config, {
logger,
schedule,
});
}).toThrow('Org not enabled for test-id');
GitlabOrgDiscoveryEntityProvider.fromConfig(config, {
logger,
schedule,
});
expect(logger.info).toHaveBeenCalledWith('Org not enabled for test-id.');
});
it('should throw error when saas without group configuration', () => {
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { LoggerService } from '@backstage/backend-plugin-api';
import { PluginTaskScheduler, TaskRunner } from '@backstage/backend-tasks';
import {
ANNOTATION_LOCATION,
@@ -28,7 +29,6 @@ import {
import { EventsService } from '@backstage/plugin-events-node';
import { merge } from 'lodash';
import * as uuid from 'uuid';
import { LoggerService } from '@backstage/backend-plugin-api';
import {
GitLabClient,
@@ -133,7 +133,8 @@ export class GitlabOrgDiscoveryEntityProvider implements EntityProvider {
const integration = integrations.byHost(providerConfig.host);
if (!providerConfig.orgEnabled) {
throw new Error(`Org not enabled for ${providerConfig.id}.`);
options.logger.info(`Org not enabled for ${providerConfig.id}.`);
return;
}
if (!integration) {