fix linter and add auth

This commit is contained in:
Manabu Mccloskey 2023-03-21 16:42:54 -07:00
parent 93bbf69132
commit 4db8bc3c48
8 changed files with 85 additions and 67 deletions

View file

@ -6,3 +6,5 @@ packages/*/src
packages/*/node_modules
plugins
*.local.yaml
github-integration.yaml
k8s-config.yaml

View file

@ -27,7 +27,7 @@ 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, ProxiedSignInPage} from '@backstage/core-components';
import { createApp } from '@backstage/app-defaults';
import { AppRouter, FlatRoutes } from '@backstage/core-app-api';
import { CatalogGraphPage } from '@backstage/plugin-catalog-graph';
@ -36,6 +36,9 @@ import { catalogEntityCreatePermission } from '@backstage/plugin-catalog-common/
const app = createApp({
apis,
components: {
SignInPage: (props) => <ProxiedSignInPage {...props} provider="oauth2Proxy" />,
},
bindRoutes({ bind }) {
bind(catalogPlugin.externalRoutes, {
createComponent: scaffolderPlugin.routes.root,

View file

@ -5,6 +5,7 @@ import {
} from '@backstage/plugin-auth-backend';
import { Router } from 'express';
import { PluginEnvironment } from '../types';
import {DEFAULT_NAMESPACE, stringifyEntityRef} from "@backstage/catalog-model";
export default async function createPlugin(
env: PluginEnvironment,
@ -17,7 +18,39 @@ export default async function createPlugin(
tokenManager: env.tokenManager,
providerFactories: {
...defaultAuthProviderFactories,
oauth2Proxy: providers.oauth2Proxy.create({
signIn: {
async resolver({ result }, ctx) {
console.log(result)
const name = result.getHeader('x-forwarded-preferred-username');
if (!name) {
throw new Error('Request did not contain a user');
}
try {
// Attempts to sign in existing user
const signedInUser = await ctx.signInWithCatalogUser({
entityRef: { name },
});
return Promise.resolve(signedInUser);
} catch (e) {
// Create stub user
const userEntityRef = stringifyEntityRef({
kind: 'User',
name: name,
namespace: DEFAULT_NAMESPACE,
});
return ctx.issueToken({
claims: {
sub: userEntityRef,
ent: [userEntityRef],
},
});
}
},
},
}),
// 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.
@ -35,20 +68,20 @@ export default async function createPlugin(
// 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(),
},
}),
// 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(),
// },
// }),
},
});
}

View file

@ -1,12 +0,0 @@
// import React from 'react';
// import { createDevApp } from '@backstage/dev-utils';
// import { workflowsPlugin, EntityWorkflowsContent } from '../src/plugin';
//
// createDevApp()
// .registerPlugin(workflowsPlugin)
// .addPage({
// element: <WorkflowsPage />,
// title: 'Root Page',
// path: '/workflows'
// })
// .render();

View file

@ -1,27 +0,0 @@
import React from 'react';
import { ExampleComponent } from './ExampleComponent';
import { rest } from 'msw';
import { setupServer } from 'msw/node';
import { screen } from '@testing-library/react';
import {
setupRequestMockHandlers,
renderInTestApp,
} from "@backstage/test-utils";
describe('ExampleComponent', () => {
const server = setupServer();
// Enable sane handlers for network requests
setupRequestMockHandlers(server);
// setup mock response
beforeEach(() => {
server.use(
rest.get('/*', (_, res, ctx) => res(ctx.status(200), ctx.json({}))),
);
});
it('should render', async () => {
await renderInTestApp(<ExampleComponent />);
expect(screen.getByText('Welcome to workflows!')).toBeInTheDocument();
});
});

View file

@ -0,0 +1,26 @@
// import React from 'react';
// import { rest } from 'msw';
// import { setupServer } from 'msw/node';
// import { screen } from '@testing-library/react';
// import {
// setupRequestMockHandlers,
// renderInTestApp,
// } from "@backstage/test-utils";
// describe('ExampleComponent', () => {
// const server = setupServer();
// // Enable sane handlers for network requests
// setupRequestMockHandlers(server);
//
// // setup mock response
// beforeEach(() => {
// server.use(
// rest.get('/*', (_, res, ctx) => res(ctx.status(200), ctx.json({}))),
// );
// });
//
// it('should render', async () => {
// await renderInTestApp(<ExampleComponent />);
// expect(screen.getByText('Welcome to workflows!')).toBeInTheDocument();
// });
// });

View file

@ -1,27 +1,21 @@
import React from 'react';
import {Typography, Grid, IconButton} from '@material-ui/core';
import DeleteIcon from '@material-ui/icons/Delete';
import ClearIcon from '@material-ui/icons/Clear'
import LinkOffRounded from "@material-ui/icons/LinkOffRounded";
import {Grid} from '@material-ui/core';
import {
InfoCard,
Header,
Page,
Content,
HeaderLabel,
} from '@backstage/core-components';
import {FetchTFState, ManageBlueprint} from "./FetchTFState";
export const BlueprintsComponent = () => (
<Page themeId="tool">
<Content>
{/*<ContentHeader title="Blueprint information">*/}
{/* <ContentHeader title="Blueprint information">*/}
{/* <SupportButton>A description of your plugin goes here.</SupportButton>*/}
{/*</ContentHeader>*/}
{/* </ContentHeader>*/}
<Grid container spacing={3} direction="column">
<Grid item>
<ManageBlueprint />
{/*<InfoCard title="Blueprint management">*/}
{/* <InfoCard title="Blueprint management">*/}
{/* <Typography color="textSecondary">*/}
{/* Manage this blueprint deployment*/}
{/* </Typography>*/}
@ -34,7 +28,7 @@ export const BlueprintsComponent = () => (
{/* <IconButton aria-label="link" size="medium">*/}
{/* <LinkOffRounded />*/}
{/* </IconButton>*/}
{/*</InfoCard>*/}
{/* </InfoCard>*/}
</Grid>
<Grid item>
<FetchTFState />

View file

@ -17,14 +17,13 @@ import {
DialogContentText,
DialogTitle,
IconButton,
PaperProps,
Typography
} from "@material-ui/core";
import DeleteIcon from "@material-ui/icons/Delete";
import ClearIcon from "@material-ui/icons/Clear";
import LinkOffRounded from "@material-ui/icons/LinkOffRounded";
const token = ""
const token = "..---"
type TFState = {
terraform_version: string