-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add marketplace providers to ingest the entities into catalog
- Loading branch information
1 parent
4db1263
commit b25c681
Showing
15 changed files
with
556 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@red-hat-developer-hub/backstage-plugin-catalog-backend-module-marketplace': patch | ||
--- | ||
|
||
Add marketplace providers to add entities into catalog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
...arketplace/plugins/catalog-backend-module-marketplace/src/providers/BaseEntityProvider.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* Copyright Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import { SchedulerServiceTaskRunner } from '@backstage/backend-plugin-api'; | ||
import { | ||
ANNOTATION_LOCATION, | ||
ANNOTATION_ORIGIN_LOCATION, | ||
Entity, | ||
} from '@backstage/catalog-model'; | ||
import { | ||
EntityProvider, | ||
EntityProviderConnection, | ||
} from '@backstage/plugin-catalog-node'; | ||
|
||
import { findTopmostFolder, readYamlFiles } from '../utils/file-utils'; | ||
import { JsonFileData } from '../types'; | ||
|
||
/** | ||
* @public | ||
*/ | ||
export abstract class BaseEntityProvider<T extends Entity> | ||
implements EntityProvider | ||
{ | ||
private connection?: EntityProviderConnection; | ||
private taskRunner: SchedulerServiceTaskRunner; | ||
|
||
constructor(taskRunner: SchedulerServiceTaskRunner) { | ||
this.taskRunner = taskRunner; | ||
} | ||
|
||
abstract getProviderName(): string; | ||
abstract getKind(): string; | ||
|
||
getEntities(allEntities: JsonFileData<T>[]): T[] { | ||
if (allEntities.length === 0) { | ||
return []; | ||
} | ||
return allEntities | ||
.filter(d => d.content.kind === this.getKind()) | ||
.map(file => ({ | ||
...file.content, | ||
metadata: { | ||
...file.content.metadata, | ||
annotations: { | ||
[ANNOTATION_LOCATION]: `file:${this.getProviderName()}`, | ||
[ANNOTATION_ORIGIN_LOCATION]: `file:${this.getProviderName()}`, | ||
}, | ||
}, | ||
})); | ||
} | ||
|
||
async connect(connection: EntityProviderConnection): Promise<void> { | ||
this.connection = connection; | ||
await this.taskRunner.run({ | ||
id: this.getProviderName(), | ||
fn: async () => { | ||
await this.run(); | ||
}, | ||
}); | ||
} | ||
|
||
async run(): Promise<void> { | ||
if (!this.connection) { | ||
throw new Error('Not initialized'); | ||
} | ||
|
||
const marketplaceFilePath = findTopmostFolder('marketplace'); | ||
|
||
let yamlData: JsonFileData<T>[] = []; | ||
if (marketplaceFilePath) { | ||
try { | ||
yamlData = readYamlFiles(marketplaceFilePath); | ||
} catch (error) { | ||
console.error(error.message); | ||
} | ||
} | ||
|
||
const entities: T[] = this.getEntities(yamlData); | ||
|
||
await this.connection.applyMutation({ | ||
type: 'full', | ||
entities: entities.map(entity => ({ | ||
entity, | ||
locationKey: `file:${this.getProviderName()}`, | ||
})), | ||
}); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...plugins/catalog-backend-module-marketplace/src/providers/MarketplaceCollectionProvider.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import { | ||
MarketplaceCollection, | ||
MarketplaceKind, | ||
} from '@red-hat-developer-hub/backstage-plugin-marketplace-common'; | ||
import { BaseEntityProvider } from './BaseEntityProvider'; | ||
|
||
/** | ||
* @public | ||
*/ | ||
export class MarketplaceCollectionProvider extends BaseEntityProvider<MarketplaceCollection> { | ||
getKind(): string { | ||
return MarketplaceKind.Collection; | ||
} | ||
|
||
getProviderName(): string { | ||
return 'marketplace-collection-provider'; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...ce/plugins/catalog-backend-module-marketplace/src/providers/MarketplacePackageProvider.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import { | ||
MarketplaceKind, | ||
MarketplacePackage, | ||
} from '@red-hat-developer-hub/backstage-plugin-marketplace-common'; | ||
import { BaseEntityProvider } from './BaseEntityProvider'; | ||
|
||
/** | ||
* @public | ||
*/ | ||
export class MarketplacePackageProvider extends BaseEntityProvider<MarketplacePackage> { | ||
getKind(): string { | ||
return MarketplaceKind.Package; | ||
} | ||
|
||
getProviderName(): string { | ||
return 'marketplace-package-provider'; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...ace/plugins/catalog-backend-module-marketplace/src/providers/MarketplacePluginProvider.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import { | ||
MarketplaceKind, | ||
MarketplacePlugin, | ||
} from '@red-hat-developer-hub/backstage-plugin-marketplace-common'; | ||
import { BaseEntityProvider } from './BaseEntityProvider'; | ||
|
||
/** | ||
* @public | ||
*/ | ||
export class MarketplacePluginProvider extends BaseEntityProvider<MarketplacePlugin> { | ||
getKind(): string { | ||
return MarketplaceKind.Plugin; | ||
} | ||
|
||
getProviderName(): string { | ||
return 'marketplace-plugin-provider'; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
workspaces/marketplace/plugins/catalog-backend-module-marketplace/src/providers/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
export * from './BaseEntityProvider'; | ||
export * from './MarketplacePluginProvider'; | ||
export * from './MarketplaceCollectionProvider'; | ||
export * from './MarketplacePackageProvider'; |
20 changes: 20 additions & 0 deletions
20
workspaces/marketplace/plugins/catalog-backend-module-marketplace/src/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* @public | ||
*/ | ||
export type JsonFileData<T> = { filePath: string; content: T }; |
Oops, something went wrong.