@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/backend-tasks': patch
|
||||
---
|
||||
|
||||
Relaxed the task ID requirement to now support any non-empty string
|
||||
@@ -20,14 +20,14 @@ import { delegateAbortController, sleep, validateId } from './util';
|
||||
|
||||
describe('util', () => {
|
||||
describe('validateId', () => {
|
||||
it.each(['a', 'a_b', 'ab123c_2'])(
|
||||
it.each(['a', 'a_b', 'ab123c_2', 'a!', 'A', 'a-b', 'a.b', '_a', 'a_'])(
|
||||
'accepts valid inputs, %p',
|
||||
async input => {
|
||||
expect(validateId(input)).toBeUndefined();
|
||||
},
|
||||
);
|
||||
|
||||
it.each(['', 'a!', 'A', 'a-b', 'a.b', '_a', 'a_', null, Symbol('a')])(
|
||||
it.each(['', null, Symbol('a')])(
|
||||
'rejects invalid inputs, %p',
|
||||
async input => {
|
||||
expect(() => validateId(input as any)).toThrow();
|
||||
|
||||
@@ -19,12 +19,10 @@ import { Knex } from 'knex';
|
||||
import { DateTime, Duration } from 'luxon';
|
||||
import { AbortController, AbortSignal } from 'node-abort-controller';
|
||||
|
||||
// Keep the IDs compatible with e.g. Prometheus
|
||||
// Keep the IDs compatible with e.g. Prometheus labels
|
||||
export function validateId(id: string) {
|
||||
if (typeof id !== 'string' || !/^[a-z0-9]+(?:_[a-z0-9]+)*$/.test(id)) {
|
||||
throw new InputError(
|
||||
`${id} is not a valid ID, expected string of lowercase characters and digits separated by underscores`,
|
||||
);
|
||||
if (typeof id !== 'string' || !id.trim()) {
|
||||
throw new InputError(`${id} is not a valid ID, expected non-empty string`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -217,7 +217,7 @@ export class LdapOrgEntityProvider implements EntityProvider {
|
||||
}
|
||||
|
||||
this.scheduleFn = async () => {
|
||||
const id = this.getScheduledTaskId();
|
||||
const id = `${this.getProviderName()}:refresh`;
|
||||
await schedule.run({
|
||||
id,
|
||||
fn: async () => {
|
||||
@@ -236,12 +236,6 @@ export class LdapOrgEntityProvider implements EntityProvider {
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
// Gets a suitable scheduler task ID for this provider instance
|
||||
private getScheduledTaskId(): string {
|
||||
const rawId = `refresh_${this.getProviderName()}`;
|
||||
return rawId.toLocaleLowerCase('en-US').replace(/[^a-z0-9]/g, '_');
|
||||
}
|
||||
}
|
||||
|
||||
// Helps wrap the timing and logging behaviors
|
||||
|
||||
Reference in New Issue
Block a user