Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] feat(marketplace): add marketplace providers #240

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions workspaces/marketplace/app-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ catalog:
rules:
- allow: [User, Group, System, Component, API]

marketplace:
providers:
npm:
- package: '@backstage-community/plugin-npm'

kubernetes:
# see https://backstage.io/docs/features/kubernetes/configuration for kubernetes configuration options

Expand Down
29 changes: 15 additions & 14 deletions workspaces/marketplace/packages/backend/knip-report.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
# Knip report

## Unused dependencies (11)
## Unused dependencies (12)

| Name | Location | Severity |
| :---------------------------------------------------------- | :----------- | :------- |
| @red-hat-developer-hub/backstage-plugin-marketplace-backend | package.json | error |
| @backstage/plugin-auth-backend-module-github-provider | package.json | error |
| @backstage/plugin-search-backend-node | package.json | error |
| @backstage/plugin-permission-common | package.json | error |
| @backstage/plugin-permission-node | package.json | error |
| @backstage/plugin-auth-node | package.json | error |
| @backstage/config | package.json | error |
| better-sqlite3 | package.json | error |
| node-gyp | package.json | error |
| app | package.json | error |
| pg | package.json | error |
| Name | Location | Severity |
| :------------------------------------------------------------------------- | :----------- | :------- |
| @red-hat-developer-hub/backstage-plugin-catalog-backend-module-marketplace | package.json | error |
| @red-hat-developer-hub/backstage-plugin-marketplace-backend | package.json | error |
| @backstage/plugin-auth-backend-module-github-provider | package.json | error |
| @backstage/plugin-search-backend-node | package.json | error |
| @backstage/plugin-permission-common | package.json | error |
| @backstage/plugin-permission-node | package.json | error |
| @backstage/plugin-auth-node | package.json | error |
| @backstage/config | package.json | error |
| better-sqlite3 | package.json | error |
| node-gyp | package.json | error |
| app | package.json | error |
| pg | package.json | error |
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('@backstage/cli/config/eslint-factory')(__dirname);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# @red-hat-developer-hub/marketplace-cli
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env node
/*
* Copyright 2025 The Backstage Authors
*
* 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.
*/

const path = require('path');

// Figure out whether we're running inside the backstage repo
/* eslint-disable-next-line no-restricted-syntax */
const isLocal = require('fs').existsSync(path.resolve(__dirname, '../src')) && process.env.USE_SRC !== 'false';

if (isLocal) {
require('@backstage/cli/config/nodeTransform.cjs');
require('../src');
} else {
require('../dist/index.cjs.js');
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Knip report

## Unused dependencies (3)

| Name | Location | Severity |
| :--------------------------------------------------------- | :----------- | :------- |
| @red-hat-developer-hub/backstage-plugin-marketplace-common | package.json | error |
| @backstage/catalog-model | package.json | error |
| glob | package.json | error |
45 changes: 45 additions & 0 deletions workspaces/marketplace/packages/marketplace-cli/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"name": "@red-hat-developer-hub/marketplace-cli",
"description": "Marketplace cli",
"version": "0.0.0",
"main": "src/index.ts",
"types": "src/index.ts",
"license": "Apache-2.0",
"private": true,
"publishConfig": {
"access": "public",
"main": "dist/index.cjs.js",
"types": "dist/index.d.ts"
},
"repository": {
"type": "git",
"url": "https://github.com/redhat-developer/rhdh-plugins",
"directory": "workspaces/marketplace/packages/marketplace-cli"
},
"backstage": {
"role": "cli"
},
"scripts": {
"build": "backstage-cli package build",
"lint": "backstage-cli package lint",
"test": "backstage-cli package test",
"clean": "backstage-cli package clean",
"prepack": "backstage-cli package prepack",
"postpack": "backstage-cli package postpack"
},
"dependencies": {
"@backstage/catalog-model": "^1.7.1",
"@red-hat-developer-hub/backstage-plugin-marketplace-common": "workspace:^",
"chalk": "^4.0.0",
"commander": "^12.0.0",
"fs-extra": "^11.2.0",
"glob": "^10.4.5",
"yaml": "^2.6.0"
},
"devDependencies": {
"@backstage/cli": "^0.28.0"
},
"files": [
"dist"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2025 The Backstage Authors
*
* 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 chalk from 'chalk';
import yaml from 'yaml';

import {
NPM,
OCI,
} from '@red-hat-developer-hub/backstage-plugin-marketplace-common';

export default async function extract(uri: string) {
console.log('Extract', chalk.green(uri));

if (uri.startsWith('@')) {
const plugin = await NPM.extractPlugin(uri);
console.log(yaml.stringify(plugin));
} else if (OCI.isOciUri(uri)) {
const plugin = await OCI.extractPlugin(uri);
console.log(yaml.stringify(plugin));
} else {
throw new Error('Unsupported URI');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2025 The Backstage Authors
*
* 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 chalk from 'chalk';
import { Command } from 'commander';

export function registerCommands(program: Command) {
program
.command('extract')
.argument('<uri>', 'The URI to extract')
.action(lazy(() => import('./extract').then(m => m.default)));

program
.command('verify')
.description('Verifty a set of verify files')
.argument('<files...>', 'The files to verify')
// .option('-g, --glob', 'Enable glob pattern matching')
.action(lazy(() => import('./verify').then(m => m.default)));
}

// Wraps an action function so that it always exits and handles errors
function lazy(
getActionFunc: () => Promise<(...args: any[]) => Promise<void>>,
): (...args: any[]) => Promise<never> {
return async (...args: any[]) => {
try {
const actionFunc = await getActionFunc();
await actionFunc(...args);

process.exit(0);
} catch (error) {
process.stderr.write(`\n${chalk.red(`${error}`)}\n\n`);
process.exit(1);
}
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2025 The Backstage Authors
*
* 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 chalk from 'chalk';
import fs from 'fs-extra';
import yaml from 'yaml';

interface Options {
// TODO
glob?: boolean;
// TODO
recursive?: boolean;
}

export default async function verify(files: string[], _options: Options) {
for (const file of files) {
const fileContent = await fs.readFile(file, 'utf8');

const data = yaml.parse(fileContent);

console.log(
'Found',
chalk.blueBright(data.kind),
chalk.green(data.metadata.name),
);
}
}
53 changes: 53 additions & 0 deletions workspaces/marketplace/packages/marketplace-cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2025 The Backstage Authors
*
* 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.
*/

/**
* Marketplace CLI
*
* @packageDocumentation
*/

import { program } from 'commander';
import chalk from 'chalk';
import { version } from '../package.json';
import { registerCommands } from './commands';

const main = (argv: string[]) => {
program.name('marketplace-cli').version(version);

registerCommands(program);

program.on('command:*', () => {
console.log();
console.log(chalk.red(`Invalid command: ${program.args.join(' ')}`));
console.log();
program.outputHelp();
process.exit(1);
});

program.parse(argv);
};

process.on('unhandledRejection', rejection => {
const error =
rejection instanceof Error
? rejection
: new Error(`Unknown rejection: '${rejection}'`);
process.stderr.write(`\n${chalk.red(`${error}`)}\n\n`);
process.exit(1);
});

main(process.argv);
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright 2025 The Backstage Authors
*
* 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 interface Config {
marketplace: {};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Knip report

## Unused dependencies (3)

| Name | Location | Severity |
| :--------------------------------------------------------- | :----------- | :------- |
| @red-hat-developer-hub/backstage-plugin-marketplace-common | package.json | error |
| express | package.json | error |
| glob | package.json | error |

## Unused devDependencies (1)

| Name | Location | Severity |
| :---------------------------- | :----------- | :------- |
| @backstage/backend-test-utils | package.json | error |
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,23 @@
"dependencies": {
"@backstage/backend-plugin-api": "^1.0.1",
"@backstage/catalog-model": "^1.7.1",
"@backstage/config": "^1.3.1",
"@backstage/plugin-catalog-common": "^1.1.0",
"@backstage/plugin-catalog-node": "^1.13.1",
"@red-hat-developer-hub/backstage-plugin-marketplace-common": "workspace:^",
"express": "^4.17.1",
"fs-extra": "^11.2.0",
"glob": "^10.4.5",
"yaml": "^2.6.0"
},
"devDependencies": {
"@backstage/backend-test-utils": "^1.0.2",
"@backstage/cli": "^0.28.0"
"@backstage/cli": "^0.28.0",
"@types/fs-extra": "^11.0.4"
},
"files": [
"config.d.ts",
"dist"
]
],
"configSchema": "config.d.ts"
}
Loading
Loading