@backstage/plugin-catalog-backend 0.17.3 → 0.17.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/dist/index.cjs.js +81 -62
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +11 -1
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @backstage/plugin-catalog-backend
|
|
2
2
|
|
|
3
|
+
## 0.17.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 5d2a7303bd: This fixes a bug where locations couldn't be added unless the processing engine is started.
|
|
8
|
+
It's now possible to run the catalog backend without starting the processing engine and still allowing locations registrations.
|
|
9
|
+
|
|
10
|
+
This is done by refactor the `EntityProvider.connect` to happen outside the engine.
|
|
11
|
+
|
|
12
|
+
- 06934f2f52: Adjust entity query construction to ensure sub-queries are always isolated from one another.
|
|
13
|
+
- b90fc74d70: adds getDefaultProcessor method to CatalogBuilder
|
|
14
|
+
- Updated dependencies
|
|
15
|
+
- @backstage/catalog-client@0.5.2
|
|
16
|
+
- @backstage/catalog-model@0.9.7
|
|
17
|
+
- @backstage/backend-common@0.9.10
|
|
18
|
+
|
|
3
19
|
## 0.17.3
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/dist/index.cjs.js
CHANGED
|
@@ -3705,49 +3705,9 @@ function startTaskPipeline(options) {
|
|
|
3705
3705
|
}
|
|
3706
3706
|
|
|
3707
3707
|
const CACHE_TTL = 5;
|
|
3708
|
-
class Connection {
|
|
3709
|
-
constructor(config) {
|
|
3710
|
-
this.config = config;
|
|
3711
|
-
this.validateEntityEnvelope = catalogModel.entityEnvelopeSchemaValidator();
|
|
3712
|
-
}
|
|
3713
|
-
async applyMutation(mutation) {
|
|
3714
|
-
const db = this.config.processingDatabase;
|
|
3715
|
-
if (mutation.type === "full") {
|
|
3716
|
-
this.check(mutation.entities.map((e) => e.entity));
|
|
3717
|
-
await db.transaction(async (tx) => {
|
|
3718
|
-
await db.replaceUnprocessedEntities(tx, {
|
|
3719
|
-
sourceKey: this.config.id,
|
|
3720
|
-
type: "full",
|
|
3721
|
-
items: mutation.entities
|
|
3722
|
-
});
|
|
3723
|
-
});
|
|
3724
|
-
} else if (mutation.type === "delta") {
|
|
3725
|
-
this.check(mutation.added.map((e) => e.entity));
|
|
3726
|
-
this.check(mutation.removed.map((e) => e.entity));
|
|
3727
|
-
await db.transaction(async (tx) => {
|
|
3728
|
-
await db.replaceUnprocessedEntities(tx, {
|
|
3729
|
-
sourceKey: this.config.id,
|
|
3730
|
-
type: "delta",
|
|
3731
|
-
added: mutation.added,
|
|
3732
|
-
removed: mutation.removed
|
|
3733
|
-
});
|
|
3734
|
-
});
|
|
3735
|
-
}
|
|
3736
|
-
}
|
|
3737
|
-
check(entities) {
|
|
3738
|
-
for (const entity of entities) {
|
|
3739
|
-
try {
|
|
3740
|
-
this.validateEntityEnvelope(entity);
|
|
3741
|
-
} catch (e) {
|
|
3742
|
-
throw new TypeError(`Malformed entity envelope, ${e}`);
|
|
3743
|
-
}
|
|
3744
|
-
}
|
|
3745
|
-
}
|
|
3746
|
-
}
|
|
3747
3708
|
class DefaultCatalogProcessingEngine {
|
|
3748
|
-
constructor(logger,
|
|
3709
|
+
constructor(logger, processingDatabase, orchestrator, stitcher, createHash, pollingIntervalMs = 1e3) {
|
|
3749
3710
|
this.logger = logger;
|
|
3750
|
-
this.entityProviders = entityProviders;
|
|
3751
3711
|
this.processingDatabase = processingDatabase;
|
|
3752
3712
|
this.orchestrator = orchestrator;
|
|
3753
3713
|
this.stitcher = stitcher;
|
|
@@ -3759,12 +3719,6 @@ class DefaultCatalogProcessingEngine {
|
|
|
3759
3719
|
if (this.stopFunc) {
|
|
3760
3720
|
throw new Error("Processing engine is already started");
|
|
3761
3721
|
}
|
|
3762
|
-
for (const provider of this.entityProviders) {
|
|
3763
|
-
await provider.connect(new Connection({
|
|
3764
|
-
id: provider.getProviderName(),
|
|
3765
|
-
processingDatabase: this.processingDatabase
|
|
3766
|
-
}));
|
|
3767
|
-
}
|
|
3768
3722
|
this.stopFunc = startTaskPipeline({
|
|
3769
3723
|
lowWatermark: 5,
|
|
3770
3724
|
highWatermark: 10,
|
|
@@ -4157,25 +4111,26 @@ function isOrEntityFilter(filter) {
|
|
|
4157
4111
|
return filter.hasOwnProperty("anyOf");
|
|
4158
4112
|
}
|
|
4159
4113
|
function parseFilter(filter, query, db) {
|
|
4160
|
-
var _a, _b;
|
|
4161
4114
|
if (isEntitiesSearchFilter(filter)) {
|
|
4162
|
-
return query.
|
|
4115
|
+
return query.andWhere(function filterFunction() {
|
|
4163
4116
|
addCondition(this, db, filter);
|
|
4164
4117
|
});
|
|
4165
4118
|
}
|
|
4166
4119
|
if (isOrEntityFilter(filter)) {
|
|
4167
|
-
|
|
4168
|
-
|
|
4169
|
-
|
|
4170
|
-
|
|
4171
|
-
|
|
4120
|
+
return query.andWhere(function filterFunction() {
|
|
4121
|
+
var _a;
|
|
4122
|
+
for (const subFilter of (_a = filter.anyOf) != null ? _a : []) {
|
|
4123
|
+
this.orWhere((subQuery) => parseFilter(subFilter, subQuery, db));
|
|
4124
|
+
}
|
|
4125
|
+
});
|
|
4172
4126
|
}
|
|
4173
4127
|
if (isAndEntityFilter(filter)) {
|
|
4174
|
-
|
|
4175
|
-
|
|
4176
|
-
|
|
4177
|
-
|
|
4178
|
-
|
|
4128
|
+
return query.andWhere(function filterFunction() {
|
|
4129
|
+
var _a;
|
|
4130
|
+
for (const subFilter of (_a = filter.allOf) != null ? _a : []) {
|
|
4131
|
+
this.andWhere((subQuery) => parseFilter(subFilter, subQuery, db));
|
|
4132
|
+
}
|
|
4133
|
+
});
|
|
4179
4134
|
}
|
|
4180
4135
|
return query;
|
|
4181
4136
|
}
|
|
@@ -4790,6 +4745,55 @@ class DefaultRefreshService {
|
|
|
4790
4745
|
}
|
|
4791
4746
|
}
|
|
4792
4747
|
|
|
4748
|
+
class Connection {
|
|
4749
|
+
constructor(config) {
|
|
4750
|
+
this.config = config;
|
|
4751
|
+
this.validateEntityEnvelope = catalogModel.entityEnvelopeSchemaValidator();
|
|
4752
|
+
}
|
|
4753
|
+
async applyMutation(mutation) {
|
|
4754
|
+
const db = this.config.processingDatabase;
|
|
4755
|
+
if (mutation.type === "full") {
|
|
4756
|
+
this.check(mutation.entities.map((e) => e.entity));
|
|
4757
|
+
await db.transaction(async (tx) => {
|
|
4758
|
+
await db.replaceUnprocessedEntities(tx, {
|
|
4759
|
+
sourceKey: this.config.id,
|
|
4760
|
+
type: "full",
|
|
4761
|
+
items: mutation.entities
|
|
4762
|
+
});
|
|
4763
|
+
});
|
|
4764
|
+
} else if (mutation.type === "delta") {
|
|
4765
|
+
this.check(mutation.added.map((e) => e.entity));
|
|
4766
|
+
this.check(mutation.removed.map((e) => e.entity));
|
|
4767
|
+
await db.transaction(async (tx) => {
|
|
4768
|
+
await db.replaceUnprocessedEntities(tx, {
|
|
4769
|
+
sourceKey: this.config.id,
|
|
4770
|
+
type: "delta",
|
|
4771
|
+
added: mutation.added,
|
|
4772
|
+
removed: mutation.removed
|
|
4773
|
+
});
|
|
4774
|
+
});
|
|
4775
|
+
}
|
|
4776
|
+
}
|
|
4777
|
+
check(entities) {
|
|
4778
|
+
for (const entity of entities) {
|
|
4779
|
+
try {
|
|
4780
|
+
this.validateEntityEnvelope(entity);
|
|
4781
|
+
} catch (e) {
|
|
4782
|
+
throw new TypeError(`Malformed entity envelope, ${e}`);
|
|
4783
|
+
}
|
|
4784
|
+
}
|
|
4785
|
+
}
|
|
4786
|
+
}
|
|
4787
|
+
async function connectEntityProviders(db, providers) {
|
|
4788
|
+
await Promise.all(providers.map(async (provider) => {
|
|
4789
|
+
const connection = new Connection({
|
|
4790
|
+
id: provider.getProviderName(),
|
|
4791
|
+
processingDatabase: db
|
|
4792
|
+
});
|
|
4793
|
+
return provider.connect(connection);
|
|
4794
|
+
}));
|
|
4795
|
+
}
|
|
4796
|
+
|
|
4793
4797
|
class NextCatalogBuilder {
|
|
4794
4798
|
constructor(env) {
|
|
4795
4799
|
this.refreshInterval = createRandomRefreshInterval({
|
|
@@ -4852,6 +4856,20 @@ class NextCatalogBuilder {
|
|
|
4852
4856
|
this.processorsReplace = true;
|
|
4853
4857
|
return this;
|
|
4854
4858
|
}
|
|
4859
|
+
getDefaultProcessors() {
|
|
4860
|
+
const {config, logger, reader} = this.env;
|
|
4861
|
+
const integrations = integration.ScmIntegrations.fromConfig(config);
|
|
4862
|
+
return [
|
|
4863
|
+
new FileReaderProcessor(),
|
|
4864
|
+
BitbucketDiscoveryProcessor.fromConfig(config, {logger}),
|
|
4865
|
+
GithubDiscoveryProcessor.fromConfig(config, {logger}),
|
|
4866
|
+
GithubOrgReaderProcessor.fromConfig(config, {logger}),
|
|
4867
|
+
GitLabDiscoveryProcessor.fromConfig(config, {logger}),
|
|
4868
|
+
new UrlReaderProcessor({reader, logger}),
|
|
4869
|
+
CodeOwnersProcessor.fromConfig(config, {logger, reader}),
|
|
4870
|
+
new AnnotateLocationEntityProcessor({integrations})
|
|
4871
|
+
];
|
|
4872
|
+
}
|
|
4855
4873
|
setEntityDataParser(parser) {
|
|
4856
4874
|
this.parser = parser;
|
|
4857
4875
|
return this;
|
|
@@ -4885,7 +4903,7 @@ class NextCatalogBuilder {
|
|
|
4885
4903
|
const locationStore = new DefaultLocationStore(dbClient);
|
|
4886
4904
|
const configLocationProvider = new ConfigLocationEntityProvider(config);
|
|
4887
4905
|
const entityProviders = lodash__default['default'].uniqBy([...this.entityProviders, locationStore, configLocationProvider], (provider) => provider.getProviderName());
|
|
4888
|
-
const processingEngine = new DefaultCatalogProcessingEngine(logger,
|
|
4906
|
+
const processingEngine = new DefaultCatalogProcessingEngine(logger, processingDatabase, orchestrator, stitcher, () => crypto.createHash("sha1"));
|
|
4889
4907
|
const locationsCatalog = new DatabaseLocationsCatalog(db);
|
|
4890
4908
|
const locationAnalyzer = (_a = this.locationAnalyzer) != null ? _a : new RepoLocationAnalyzer(logger, integrations);
|
|
4891
4909
|
const locationService = new DefaultLocationService(locationStore, orchestrator);
|
|
@@ -4900,6 +4918,7 @@ class NextCatalogBuilder {
|
|
|
4900
4918
|
logger,
|
|
4901
4919
|
config
|
|
4902
4920
|
});
|
|
4921
|
+
await connectEntityProviders(processingDatabase, entityProviders);
|
|
4903
4922
|
return {
|
|
4904
4923
|
entitiesCatalog,
|
|
4905
4924
|
locationsCatalog,
|
|
@@ -4920,7 +4939,7 @@ class NextCatalogBuilder {
|
|
|
4920
4939
|
return catalogModel.EntityPolicies.allOf(entityPolicies);
|
|
4921
4940
|
}
|
|
4922
4941
|
buildProcessors() {
|
|
4923
|
-
const {config,
|
|
4942
|
+
const {config, reader} = this.env;
|
|
4924
4943
|
const integrations = integration.ScmIntegrations.fromConfig(config);
|
|
4925
4944
|
this.checkDeprecatedReaderProcessors();
|
|
4926
4945
|
const placeholderResolvers = {
|
|
@@ -4938,7 +4957,7 @@ class NextCatalogBuilder {
|
|
|
4938
4957
|
new BuiltinKindsEntityProcessor()
|
|
4939
4958
|
];
|
|
4940
4959
|
if (!this.processorsReplace) {
|
|
4941
|
-
processors.push(
|
|
4960
|
+
processors.push(...this.getDefaultProcessors());
|
|
4942
4961
|
}
|
|
4943
4962
|
processors.push(...this.processors);
|
|
4944
4963
|
return processors;
|