backend-common: added toString methods for all readers + log in backend instead of at creation

This commit is contained in:
Patrik Oldsberg
2020-10-02 17:34:51 +02:00
parent 3289598526
commit 69b3c03473
9 changed files with 42 additions and 12 deletions
@@ -162,4 +162,9 @@ export class AzureUrlReader implements UrlReader {
throw new Error(`Incorrect url: ${target}, ${e}`);
}
}
toString() {
const { host, token } = this.options;
return `azure{host=${host},authed=${Boolean(token)}}`;
}
}
@@ -158,4 +158,9 @@ export class BitbucketUrlReader implements UrlReader {
throw new Error(`Incorrect url: ${target}, ${e}`);
}
}
toString() {
const { host, auth } = this.options;
return `bitbucket{host=${host},authed=${Boolean(auth)}}`;
}
}
@@ -40,4 +40,8 @@ export class FetchUrlReader implements UrlReader {
}
throw new Error(message);
}
toString() {
return 'fetch{}';
}
}
@@ -229,4 +229,9 @@ export class GithubUrlReader implements UrlReader {
}
throw new Error(message);
}
toString() {
const { host, token } = this.config;
return `github{host=${host},authed=${Boolean(token)}}`;
}
}
@@ -187,4 +187,9 @@ export class GitlabUrlReader implements UrlReader {
throw new Error(`Could not get GitLab ProjectID for: ${target}, ${e}`);
}
}
toString() {
const { host, token } = this.options;
return `gitlab{host=${host},authed=${Boolean(token)}}`;
}
}
@@ -59,4 +59,10 @@ export class UrlReaderPredicateMux implements UrlReader {
throw new Error(`No reader found that could handle '${url}'`);
}
toString() {
return `predicateMux{readers=${this.readers
.map(t => t.reader)
.join(',')},fallback=${this.fallback}}`;
}
}
@@ -79,21 +79,15 @@ export class UrlReaders {
*/
createWithConfig(config: Config): UrlReader {
const mux = new UrlReaderPredicateMux({ fallback: this.fallback });
const readers = [];
for (const factory of this.factories) {
const tuples = factory({ config, logger: this.logger });
for (const tuple of tuples) {
mux.register(tuple);
readers.push(tuple.reader);
}
}
this.logger.info(
`Registered the following UrlReaders: ${readers.join(', ')}`,
);
return mux;
}