add base setup as well as catalog for gitea

This commit is contained in:
2022-12-22 17:00:50 +01:00
parent fff5cc93f8
commit 7e9e53dbbc
22 changed files with 584 additions and 48 deletions

View File

@@ -28,10 +28,11 @@
"@backstage/plugin-search-react": "^0.2.1",
"@backstage/plugin-tech-radar": "^0.5.13",
"@backstage/plugin-techdocs": "^1.2.0",
"@backstage/plugin-techdocs-react": "^1.0.1",
"@backstage/plugin-techdocs-module-addons-contrib": "^1.0.1",
"@backstage/plugin-techdocs-react": "^1.0.1",
"@backstage/plugin-user-settings": "^0.4.5",
"@backstage/theme": "^0.2.15",
"@internal/plugin-catalog-backend-module-gitea": "^0.1.0",
"@material-ui/core": "^4.12.2",
"@material-ui/icons": "^4.9.1",
"history": "^5.0.0",

View File

@@ -27,15 +27,35 @@ import { entityPage } from './components/catalog/EntityPage';
import { searchPage } from './components/search/SearchPage';
import { Root } from './components/Root';
import { AlertDisplay, OAuthRequestDialog } from '@backstage/core-components';
import {
AlertDisplay,
OAuthRequestDialog,
SignInPage,
} from '@backstage/core-components';
import { createApp } from '@backstage/app-defaults';
import { FlatRoutes } from '@backstage/core-app-api';
import { CatalogGraphPage } from '@backstage/plugin-catalog-graph';
import { PermissionedRoute } from '@backstage/plugin-permission-react';
import { catalogEntityCreatePermission } from '@backstage/plugin-catalog-common/alpha';
import { githubAuthApiRef } from '@backstage/core-plugin-api';
import { CatalogBackendModuleGiteaPage } from '@internal/plugin-catalog-backend-module-gitea';
const app = createApp({
apis,
components: {
SignInPage: props => (
<SignInPage
{...props}
auto
provider={{
id: 'github-auth-provider',
title: 'github',
message: 'Sign in using GitHub',
apiRef: githubAuthApiRef,
}}
/>
),
},
bindRoutes({ bind }) {
bind(catalogPlugin.externalRoutes, {
createComponent: scaffolderPlugin.routes.root,
@@ -91,6 +111,7 @@ const routes = (
</Route>
<Route path="/settings" element={<UserSettingsPage />} />
<Route path="/catalog-graph" element={<CatalogGraphPage />} />
<Route path="/catalog-backend-module-gitea" element={<CatalogBackendModuleGiteaPage />}/>
</FlatRoutes>
);

View File

@@ -16,15 +16,15 @@
"build-image": "docker build ../.. -f Dockerfile --tag backstage"
},
"dependencies": {
"app": "link:../app",
"@backstage/backend-common": "^0.14.0",
"@backstage/backend-tasks": "^0.3.2",
"@backstage/catalog-model": "^1.0.3",
"@backstage/catalog-client": "^1.0.3",
"@backstage/catalog-model": "^1.0.3",
"@backstage/config": "^1.0.1",
"@backstage/plugin-app-backend": "^0.3.33",
"@backstage/plugin-auth-backend": "^0.14.1",
"@backstage/plugin-catalog-backend": "^1.2.0",
"@backstage/plugin-catalog-backend-module-github": "^0.2.2",
"@backstage/plugin-permission-common": "^0.6.2",
"@backstage/plugin-permission-node": "^0.6.2",
"@backstage/plugin-proxy-backend": "^0.2.27",
@@ -33,6 +33,7 @@
"@backstage/plugin-search-backend-module-pg": "^0.3.4",
"@backstage/plugin-search-backend-node": "^0.6.2",
"@backstage/plugin-techdocs-backend": "^1.1.2",
"app": "link:../app",
"dockerode": "^3.3.1",
"express": "^4.17.1",
"express-promise-router": "^4.1.0",
@@ -42,8 +43,8 @@
"devDependencies": {
"@backstage/cli": "^0.17.2",
"@types/dockerode": "^3.3.0",
"@types/express-serve-static-core": "^4.17.5",
"@types/express": "^4.17.6",
"@types/express-serve-static-core": "^4.17.5",
"@types/luxon": "^2.0.4",
"better-sqlite3": "^7.5.0"
},

View File

@@ -1,11 +1,41 @@
import {
DEFAULT_NAMESPACE,
stringifyEntityRef,
} from '@backstage/catalog-model';
import {
createRouter,
providers,
defaultAuthProviderFactories,
SignInInfo,
AuthResolverContext,
} from '@backstage/plugin-auth-backend';
import { Router } from 'express';
import { PluginEnvironment } from '../types';
const unknownUserSignInResolver = async (
{ profile }: SignInInfo<unknown>,
ctx: AuthResolverContext,
) => {
if (!profile.email) {
throw new Error('Login failed, user profile does not contain an email');
}
//const [_, localPart] = profile.email.split('@');
const userEntityRef = stringifyEntityRef({
kind: 'User',
name: 'kjuulh',
namespace: DEFAULT_NAMESPACE,
});
return ctx.issueToken({
claims: {
sub: userEntityRef,
ent: [userEntityRef],
},
});
};
export default async function createPlugin(
env: PluginEnvironment,
): Promise<Router> {
@@ -17,36 +47,19 @@ export default async function createPlugin(
tokenManager: env.tokenManager,
providerFactories: {
...defaultAuthProviderFactories,
// This replaces the default GitHub auth provider with a customized one.
// The `signIn` option enables sign-in for this provider, using the
// identity resolution logic that's provided in the `resolver` callback.
//
// This particular resolver makes all users share a single "guest" identity.
// It should only be used for testing and trying out Backstage.
//
// If you want to use a production ready resolver you can switch to the
// the one that is commented out below, it looks up a user entity in the
// catalog using the GitHub username of the authenticated user.
// That resolver requires you to have user entities populated in the catalog,
// for example using https://backstage.io/docs/integrations/github/org
//
// There are other resolvers to choose from, and you can also create
// your own, see the auth documentation for more details:
//
// https://backstage.io/docs/auth/identity-resolver
github: providers.github.create({
signIn: {
resolver(_, ctx) {
const userRef = 'user:default/guest'; // Must be a full entity reference
return ctx.issueToken({
claims: {
sub: userRef, // The user's own identity
ent: [userRef], // A list of identities that the user claims ownership through
},
});
},
// resolver: providers.github.resolvers.usernameMatchingUserEntityName(),
//resolver(_, ctx) {
// const userRef = 'user:default/guest'; // Must be a full entity reference
// return ctx.issueToken({
// claims: {
// sub: userRef, // The user's own identity
// ent: [userRef], // A list of identities that the user claims ownership through
// },
// });
//},
resolver: unknownUserSignInResolver,
//resolver: providers.github.resolvers.usernameMatchingUserEntityName(),
},
}),
},

View File

@@ -2,11 +2,40 @@ import { CatalogBuilder } from '@backstage/plugin-catalog-backend';
import { ScaffolderEntitiesProcessor } from '@backstage/plugin-scaffolder-backend';
import { Router } from 'express';
import { PluginEnvironment } from '../types';
import { GithubEntityProvider } from '@backstage/plugin-catalog-backend-module-github';
import { stringifyEntityRef } from '@backstage/catalog-model';
export default async function createPlugin(
env: PluginEnvironment,
): Promise<Router> {
const builder = await CatalogBuilder.create(env);
builder.subscribe({
onProcessingError: event => {
env.logger.error(
`Catalog got processing errors on entity ${stringifyEntityRef(
event.unprocessedEntity,
)}`,
{
entity: stringifyEntityRef(event.unprocessedEntity),
entityDetails: event.unprocessedEntity,
errors: event.errors.map(err => JSON.stringify(err)),
},
);
},
});
builder.addEntityProvider(
GithubEntityProvider.fromConfig(env.config, {
logger: env.logger,
schedule: env.scheduler.createScheduledTaskRunner({
frequency: { minutes: 30 },
timeout: { minutes: 3 },
}),
scheduler: env.scheduler,
}),
);
builder.addProcessor(new ScaffolderEntitiesProcessor());
const { processingEngine, router } = await builder.build();
await processingEngine.start();