-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for the new backend system to the
rbac-backend
pl…
…ugin (#1179) Add support for the new backend system Signed-off-by: David Festal <[email protected]>
- Loading branch information
1 parent
90b26a7
commit d625cb2
Showing
16 changed files
with
253 additions
and
7 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
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 |
---|---|---|
@@ -1,2 +1,8 @@ | ||
export * from './service/router'; | ||
export * from './service/policy-builder'; | ||
|
||
// To provide backward compatibility with client code implemented | ||
// before PluginIdProvider was moved to @janus-idp/backstage-plugin-rbac-node. | ||
export type { PluginIdProvider } from '@janus-idp/backstage-plugin-rbac-node'; | ||
|
||
export { rbacPlugin as default } from './plugin'; |
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,82 @@ | ||
import { loggerToWinstonLogger } from '@backstage/backend-common'; | ||
import { | ||
coreServices, | ||
createBackendPlugin, | ||
} from '@backstage/backend-plugin-api'; | ||
|
||
import { PolicyBuilder } from '@janus-idp/backstage-plugin-rbac-backend'; | ||
import { | ||
PluginIdProvider, | ||
PluginIdProviderExtensionPoint, | ||
pluginIdProviderExtensionPoint, | ||
} from '@janus-idp/backstage-plugin-rbac-node'; | ||
|
||
/** | ||
* RBAC plugin | ||
* | ||
*/ | ||
export const rbacPlugin = createBackendPlugin({ | ||
pluginId: 'permission', | ||
register(env) { | ||
const pluginIdProviderExtensionPointImpl = new (class PluginIdProviderImpl | ||
implements PluginIdProviderExtensionPoint | ||
{ | ||
pluginIdProviders: PluginIdProvider[] = []; | ||
|
||
addPluginIdProvider(pluginIdProvider: PluginIdProvider): void { | ||
this.pluginIdProviders.push(pluginIdProvider); | ||
} | ||
})(); | ||
|
||
env.registerExtensionPoint( | ||
pluginIdProviderExtensionPoint, | ||
pluginIdProviderExtensionPointImpl, | ||
); | ||
|
||
env.registerInit({ | ||
deps: { | ||
http: coreServices.httpRouter, | ||
config: coreServices.rootConfig, | ||
logger: coreServices.logger, | ||
discovery: coreServices.discovery, | ||
identity: coreServices.identity, | ||
permissions: coreServices.permissions, | ||
tokenManager: coreServices.tokenManager, | ||
}, | ||
async init({ | ||
http, | ||
config, | ||
logger, | ||
discovery, | ||
identity, | ||
permissions, | ||
tokenManager, | ||
}) { | ||
const winstonLogger = loggerToWinstonLogger(logger); | ||
|
||
http.use( | ||
await PolicyBuilder.build( | ||
{ | ||
config, | ||
logger: winstonLogger, | ||
discovery, | ||
identity, | ||
permissions, | ||
tokenManager, | ||
}, | ||
{ | ||
getPluginIds: () => | ||
Array.from( | ||
new Set( | ||
pluginIdProviderExtensionPointImpl.pluginIdProviders.flatMap( | ||
p => p.getPluginIds(), | ||
), | ||
), | ||
), | ||
}, | ||
), | ||
); | ||
}, | ||
}); | ||
}, | ||
}); |
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,5 @@ | ||
# @backstage/plugin-rbac-node | ||
|
||
Welcome to the Node.js library package for the rbac plugin! | ||
|
||
For more information about RBAC plugin, see the [RBAC plugin documentation](https://github.com/janus-idp/backstage-plugins/tree/main/plugins/rbac-backend) on GitHub. |
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 @@ | ||
{ | ||
"name": "@janus-idp/backstage-plugin-rbac-node", | ||
"description": "Node.js library for the rbac plugin", | ||
"version": "0.1.0", | ||
"main": "src/index.ts", | ||
"types": "src/index.ts", | ||
"license": "Apache-2.0", | ||
"publishConfig": { | ||
"access": "public", | ||
"main": "dist/index.cjs.js", | ||
"types": "dist/index.d.ts" | ||
}, | ||
"backstage": { | ||
"role": "node-library" | ||
}, | ||
"scripts": { | ||
"build": "backstage-cli package build", | ||
"tsc": "tsc", | ||
"lint": "backstage-cli package lint", | ||
"test": "backstage-cli package test --passWithNoTests --coverage", | ||
"clean": "backstage-cli package clean", | ||
"prepack": "backstage-cli package prepack", | ||
"postpack": "backstage-cli package postpack" | ||
}, | ||
"devDependencies": { | ||
"@backstage/cli": "0.23.0" | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"dependencies": { | ||
"@backstage/backend-plugin-api": "^0.6.6" | ||
} | ||
} |
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,22 @@ | ||
import { createExtensionPoint } from '@backstage/backend-plugin-api'; | ||
|
||
import { PluginIdProvider } from './types'; | ||
|
||
/** | ||
* An extension point the exposes the ability to configure additional PluginIDProviders. | ||
* | ||
* @public | ||
*/ | ||
export const pluginIdProviderExtensionPoint = | ||
createExtensionPoint<PluginIdProviderExtensionPoint>({ | ||
id: 'permission.rbac.pluginIdProvider', | ||
}); | ||
|
||
/** | ||
* The interface for {@link pluginIdProviderExtensionPoint}. | ||
* | ||
* @public | ||
*/ | ||
export type PluginIdProviderExtensionPoint = { | ||
addPluginIdProvider(pluginIdProvider: PluginIdProvider): void; | ||
}; |
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,24 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/** | ||
* Node.js library for the rbac plugin. | ||
* | ||
* @packageDocumentation | ||
*/ | ||
|
||
export * from './extensions'; | ||
export * from './types'; |
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,16 @@ | ||
/* | ||
* Copyright 2023 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 {}; |
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,17 @@ | ||
/* | ||
* Copyright 2023 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 * from './types'; |
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,23 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/** | ||
* Used to provide a list of pluginIDs on which a permission well-known endpoint is to be searched. | ||
* @public | ||
*/ | ||
export interface PluginIdProvider { | ||
getPluginIds: () => 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,9 @@ | ||
{ | ||
"extends": "@backstage/cli/config/tsconfig.json", | ||
"include": ["src", "dev", "migrations"], | ||
"exclude": ["node_modules"], | ||
"compilerOptions": { | ||
"outDir": "../../dist-types/plugins/rbac-node", | ||
"rootDir": "." | ||
} | ||
} |
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,9 @@ | ||
{ | ||
"extends": ["//"], | ||
"pipeline": { | ||
"tsc": { | ||
"outputs": ["../../dist-types/plugins/rbac-node/**"], | ||
"dependsOn": ["^tsc"] | ||
} | ||
} | ||
} |