-
Notifications
You must be signed in to change notification settings - Fork 254
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(npm): add backend to fetch data from private registries
Signed-off-by: Christoph Jerolimov <jerolimov+git@redhat.com>
- Loading branch information
1 parent
1fbf57e
commit 7d08a0d
Showing
47 changed files
with
1,424 additions
and
210 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
File renamed without changes.
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,8 @@ | ||
--- | ||
# https://backstage.io/docs/features/software-catalog/descriptor-format#kind-system | ||
apiVersion: backstage.io/v1alpha1 | ||
kind: System | ||
metadata: | ||
name: backstage | ||
spec: | ||
owner: guests |
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,14 @@ | ||
--- | ||
# https://backstage.io/docs/features/software-catalog/descriptor-format#kind-component | ||
apiVersion: backstage.io/v1alpha1 | ||
kind: Component | ||
metadata: | ||
name: github-packages-examples | ||
annotations: | ||
npm/registry: github | ||
npm/package: '@github-packages-examples/npm-publish' | ||
spec: | ||
type: library | ||
lifecycle: production | ||
owner: guests | ||
system: backstage |
8 changes: 0 additions & 8 deletions
8
workspaces/npm/examples/entities.yaml → ...spaces/npm/examples/npmjs-components.yaml
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('@backstage/cli/config/eslint-factory')(__dirname); |
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,28 @@ | ||
# npm | ||
|
||
This plugin backend was templated using the Backstage CLI. You should replace this text with a description of your plugin backend. | ||
|
||
## Installation | ||
|
||
This plugin is installed via the `@backstage-community/plugin-npm-backend` package. To install it to your backend package, run the following command: | ||
|
||
```bash | ||
# From your root directory | ||
yarn --cwd packages/backend add @backstage-community/plugin-npm-backend | ||
``` | ||
|
||
Then add the plugin to your backend in `packages/backend/src/index.ts`: | ||
|
||
```ts | ||
const backend = createBackend(); | ||
// ... | ||
backend.add(import('@backstage-community/plugin-npm-backend')); | ||
``` | ||
|
||
## Development | ||
|
||
This plugin backend can be started in a standalone mode from directly in this | ||
package with `yarn start`. It is a limited setup that is most convenient when | ||
developing the plugin backend itself. | ||
|
||
If you want to run the entire project, including the frontend, run `yarn dev` from the root directory. |
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,10 @@ | ||
apiVersion: backstage.io/v1alpha1 | ||
kind: Component | ||
metadata: | ||
name: backstage-plugin-npm | ||
title: '@backstage-community/plugin-npm-backend' | ||
description: A Backstage plugin that shows meta info and latest versions from a npm registry | ||
spec: | ||
lifecycle: experimental | ||
type: backstage-backend-plugin | ||
owner: maintainers |
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,34 @@ | ||
/* | ||
* Copyright 2024 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 { | ||
npm?: { | ||
registries?: { | ||
/** | ||
* Registry name | ||
*/ | ||
name?: string; | ||
/** | ||
* Registry base url | ||
*/ | ||
url?: string; | ||
/** | ||
* Registry auth token | ||
* @visibility secret | ||
*/ | ||
token?: string; | ||
}[]; | ||
}; | ||
} |
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,75 @@ | ||
/* | ||
* Copyright 2024 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 { createBackend } from '@backstage/backend-defaults'; | ||
import { mockServices } from '@backstage/backend-test-utils'; | ||
import { catalogServiceMock } from '@backstage/plugin-catalog-node/testUtils'; | ||
|
||
// TEMPLATE NOTE: | ||
// This is the development setup for your plugin that wires up a | ||
// minimal backend that can use both real and mocked plugins and services. | ||
// | ||
// Start up the backend by running `yarn start` in the package directory. | ||
// Once it's up and running, try out the following requests: | ||
// | ||
// Create a new todo item, standalone or for the sample component: | ||
// | ||
// curl http://localhost:7007/api/npm/todos -H 'Content-Type: application/json' -d '{"title": "My Todo"}' | ||
// curl http://localhost:7007/api/npm/todos -H 'Content-Type: application/json' -d '{"title": "My Todo", "entityRef": "component:default/sample"}' | ||
// | ||
// List TODOs: | ||
// | ||
// curl http://localhost:7007/api/npm/todos | ||
// | ||
// Explicitly make an unauthenticated request, or with service auth: | ||
// | ||
// curl http://localhost:7007/api/npm/todos -H 'Authorization: Bearer mock-none-token' | ||
// curl http://localhost:7007/api/npm/todos -H 'Authorization: Bearer mock-service-token' | ||
|
||
const backend = createBackend(); | ||
|
||
// TEMPLATE NOTE: | ||
// Mocking the auth and httpAuth service allows you to call your plugin API without | ||
// having to authenticate. | ||
// | ||
// If you want to use real auth, you can install the following instead: | ||
// backend.add(import('@backstage/plugin-auth-backend')); | ||
// backend.add(import('@backstage/plugin-auth-backend-module-guest-provider')); | ||
backend.add(mockServices.auth.factory()); | ||
backend.add(mockServices.httpAuth.factory()); | ||
|
||
// TEMPLATE NOTE: | ||
// Rather than using a real catalog you can use a mock with a fixed set of entities. | ||
backend.add( | ||
catalogServiceMock.factory({ | ||
entities: [ | ||
{ | ||
apiVersion: 'backstage.io/v1alpha1', | ||
kind: 'Component', | ||
metadata: { | ||
name: 'sample', | ||
title: 'Sample Component', | ||
}, | ||
spec: { | ||
type: 'service', | ||
}, | ||
}, | ||
], | ||
}), | ||
); | ||
|
||
backend.add(import('../src')); | ||
|
||
backend.start(); |
Oops, something went wrong.