Skip to content

Commit 58ae1fe

Browse files
authored
feat(extensions): allow installing plugins based on access and env (#769)
* feat(extensions): allow installing plugins * add RBAC configuration * use the fetch API to get the plugin configuration * updated UI to show error states * add installation api * disable plugin installation for production env
1 parent b33a321 commit 58ae1fe

33 files changed

Lines changed: 2093 additions & 514 deletions
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@red-hat-developer-hub/backstage-plugin-marketplace-backend': patch
3+
'@red-hat-developer-hub/backstage-plugin-marketplace-common': patch
4+
'@red-hat-developer-hub/marketplace-cli': patch
5+
'@red-hat-developer-hub/backstage-plugin-marketplace': minor
6+
---
7+
8+
Added an alert for production environment
9+
Integrated the fetch configuration and install API calls
10+
Fixed an import error

workspaces/marketplace/app-config.yaml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ backend:
99
# Used for enabling authentication, secret is shared by all backend plugins
1010
# See https://backstage.io/docs/auth/service-to-service-auth for
1111
# information on the format
12-
# auth:
13-
# keys:
14-
# - secret: ${BACKEND_SECRET}
12+
auth:
13+
dangerouslyDisableDefaultAuthPolicy: true
14+
# keys:
15+
# - secret: ${BACKEND_SECRET}
1516
baseUrl: http://localhost:7007
1617
listen:
1718
port: 7007
@@ -67,6 +68,13 @@ auth:
6768
providers:
6869
# See https://backstage.io/docs/auth/guest/provider
6970
guest: {}
71+
github:
72+
development:
73+
clientId: ${GITHUB_CLIENT_ID}
74+
clientSecret: ${GITHUB_CLIENT_SECRET}
75+
signIn:
76+
resolvers:
77+
- resolver: usernameMatchingUserEntityName
7078

7179
scaffolder:
7280
# see https://backstage.io/docs/features/software-templates/configuration for software template options
@@ -88,7 +96,6 @@ catalog:
8896
Location,
8997
]
9098
locations:
91-
# Local example data, file locations are relative to the backend process, typically `packages/backend`
9299
- type: file
93100
target: ../../catalog-info.yaml
94101
rules:
@@ -124,3 +131,4 @@ extensions:
124131
# enabled: true
125132
# saveToSingleFile:
126133
# file: ${EXTENSIONS_PLUGIN_CONFIG}
134+
dangerouslyAllowSignInWithoutUserInCatalog: true

workspaces/marketplace/packages/app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"lint": "backstage-cli package lint"
2020
},
2121
"dependencies": {
22+
"@backstage-community/plugin-rbac": "^1.40.1",
2223
"@backstage/app-defaults": "^1.5.17",
2324
"@backstage/catalog-model": "^1.7.3",
2425
"@backstage/cli": "^0.30.0",

workspaces/marketplace/packages/app/src/App.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import {
2626
CatalogImportPage,
2727
catalogImportPlugin,
2828
} from '@backstage/plugin-catalog-import';
29+
import { RbacPage } from '@backstage-community/plugin-rbac';
30+
2931
import { ScaffolderPage, scaffolderPlugin } from '@backstage/plugin-scaffolder';
3032
import { orgPlugin } from '@backstage/plugin-org';
3133
import { SearchPage } from '@backstage/plugin-search';
@@ -47,6 +49,7 @@ import { AppRouter, FlatRoutes } from '@backstage/core-app-api';
4749
import { CatalogGraphPage } from '@backstage/plugin-catalog-graph';
4850
import { RequirePermission } from '@backstage/plugin-permission-react';
4951
import { catalogEntityCreatePermission } from '@backstage/plugin-catalog-common/alpha';
52+
import { githubAuthApiRef } from '@backstage/core-plugin-api';
5053

5154
import { getAllThemes } from '@red-hat-developer-hub/backstage-plugin-theme';
5255

@@ -77,7 +80,21 @@ const app = createApp({
7780
});
7881
},
7982
components: {
80-
SignInPage: props => <SignInPage {...props} auto providers={['guest']} />,
83+
SignInPage: props => (
84+
<SignInPage
85+
{...props}
86+
auto
87+
providers={[
88+
'guest',
89+
{
90+
id: 'github-auth-provider',
91+
title: 'GitHub',
92+
message: 'Sign in using GitHub',
93+
apiRef: githubAuthApiRef,
94+
},
95+
]}
96+
/>
97+
),
8198
},
8299
themes: getAllThemes(),
83100
});
@@ -101,6 +118,7 @@ const routes = (
101118
<ReportIssue />
102119
</TechDocsAddons>
103120
</Route>
121+
<Route path="/rbac" element={<RbacPage />} />;
104122
<Route path="/create" element={<ScaffolderPage />} />
105123
<Route path="/api-docs" element={<ApiExplorerPage />} />
106124
<Route
@@ -116,7 +134,6 @@ const routes = (
116134
</Route>
117135
<Route path="/settings" element={<UserSettingsPage />} />
118136
<Route path="/catalog-graph" element={<CatalogGraphPage />} />
119-
120137
<Route path="/extensions" element={<Marketplace />} />
121138
</FlatRoutes>
122139
);

workspaces/marketplace/packages/app/src/components/Root/Root.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import {
2727
UserSettingsSignInAvatar,
2828
} from '@backstage/plugin-user-settings';
2929
import { SidebarSearchModal } from '@backstage/plugin-search';
30+
import { Administration } from '@backstage-community/plugin-rbac';
31+
3032
import {
3133
Sidebar,
3234
sidebarConfig,
@@ -94,6 +96,7 @@ export const Root = ({ children }: PropsWithChildren<{}>) => (
9496
<SidebarItem icon={LibraryBooks} to="docs" text="Docs" />
9597
<SidebarItem icon={CreateComponentIcon} to="create" text="Create..." />
9698
<SidebarItem icon={MarketplaceIcon} to="extensions" text="Extensions" />
99+
<Administration />
97100
{/* End global nav */}
98101
<SidebarDivider />
99102
<SidebarScrollWrapper>

workspaces/marketplace/packages/backend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"build-image": "docker build ../.. -f Dockerfile --tag backstage"
2222
},
2323
"dependencies": {
24+
"@backstage-community/plugin-rbac-backend": "6.0.0",
2425
"@backstage/backend-defaults": "^0.8.1",
2526
"@backstage/config": "^1.3.2",
2627
"@backstage/plugin-app-backend": "^0.4.5",

workspaces/marketplace/packages/backend/src/index.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ backend.add(import('@backstage/plugin-techdocs-backend/alpha'));
2525

2626
// auth plugin
2727
backend.add(import('@backstage/plugin-auth-backend'));
28+
backend.add(import('@backstage/plugin-auth-backend-module-github-provider'));
29+
2830
// See https://backstage.io/docs/backend-system/building-backends/migrating#the-auth-plugin
2931
backend.add(import('@backstage/plugin-auth-backend-module-guest-provider'));
3032
// See https://backstage.io/docs/auth/guest/provider
@@ -39,11 +41,12 @@ backend.add(
3941
backend.add(import('@backstage/plugin-catalog-backend-module-logs'));
4042

4143
// permission plugin
42-
backend.add(import('@backstage/plugin-permission-backend/alpha'));
43-
// See https://backstage.io/docs/permissions/getting-started for how to create your own permission policy
44-
backend.add(
45-
import('@backstage/plugin-permission-backend-module-allow-all-policy'),
46-
);
44+
backend.add(import('@backstage-community/plugin-rbac-backend'));
45+
// backend.add(import('@backstage/plugin-permission-backend/alpha'));
46+
// // See https://backstage.io/docs/permissions/getting-started for how to create your own permission policy
47+
// backend.add(
48+
// import('@backstage/plugin-permission-backend-module-allow-all-policy'),
49+
// );
4750

4851
// search plugin
4952
backend.add(import('@backstage/plugin-search-backend/alpha'));

workspaces/marketplace/packages/cli/src/commands/export-csv/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616
import chalk from 'chalk';
17-
import { Entity } from '@backstage/catalog-model/index';
17+
import { Entity } from '@backstage/catalog-model';
1818
import {
1919
isMarketplacePackage,
2020
isMarketplacePlugin,

workspaces/marketplace/plugins/marketplace-backend/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@ backend.add(
2121
);
2222
```
2323

24+
### Plugin Configurations
25+
26+
Add the following extensions configuration in your `app-config.yaml` file:
27+
28+
```yaml
29+
extensions:
30+
### Example for how to enable installation to a file.
31+
installation:
32+
enabled: true
33+
saveToSingleFile:
34+
file: <path-to>/dynamic-plugins.yaml
35+
```
36+
2437
## Development
2538
2639
This plugin backend can be started in a standalone mode from directly in this

workspaces/marketplace/plugins/marketplace-backend/src/installation/FileInstallationStorage.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ describe('FileInstallationStorage', () => {
5858

5959
expect(() => {
6060
fileInstallationStorage.initialize();
61-
}).toThrow(`Installation config file does not exist: ${configFileName}`);
61+
}).toThrow(`The file ${configFileName} is missing`);
6262
});
6363

6464
it('should throw on initialize when bad plugins format', async () => {

0 commit comments

Comments
 (0)