-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Keycloak plugin for dynamic backend
Add dynamic backend module capabilities for the Keycloak backend plugin. Signed-off-by: Craig Tracey <[email protected]>
- Loading branch information
1 parent
8ee7398
commit 5d89751
Showing
6 changed files
with
2,906 additions
and
141 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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright 2023 The Janus IDP 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. | ||
*/ | ||
|
||
/** | ||
* The Keycloak backend plugin integrates Keycloak into Backstage | ||
* | ||
* @packageDocumentation | ||
*/ | ||
|
||
export * from './module'; | ||
export { default } from './module'; |
77 changes: 77 additions & 0 deletions
77
plugins/keycloak-backend/src/module/catalogModuleKeycloakEntityProvider.test.ts
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,77 @@ | ||
/* | ||
* Copyright 2023 The Janus IDP 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 { TaskScheduleDefinition } from '@backstage/backend-tasks'; | ||
import { mockServices, startTestBackend } from '@backstage/backend-test-utils'; | ||
import { EntityProvider } from '@backstage/plugin-catalog-node'; | ||
import { catalogProcessingExtensionPoint } from '@backstage/plugin-catalog-node/alpha'; | ||
|
||
import { Duration } from 'luxon'; | ||
|
||
import { catalogModuleKeycloakEntityProvider } from './catalogModuleKeycloakEntityProvider'; | ||
|
||
describe('catalogModuleKeycloakEntityProvider', () => { | ||
it('should register provider at the catalog extension point', async () => { | ||
let addedProviders: Array<EntityProvider> | undefined; | ||
let usedSchedule: TaskScheduleDefinition | undefined; | ||
|
||
const extensionPoint = { | ||
addEntityProvider: (providers: any) => { | ||
addedProviders = providers; | ||
}, | ||
}; | ||
const runner = jest.fn(); | ||
const scheduler = mockServices.scheduler.mock({ | ||
createScheduledTaskRunner(schedule) { | ||
usedSchedule = schedule; | ||
return { run: runner }; | ||
}, | ||
}); | ||
|
||
const config = { | ||
catalog: { | ||
providers: { | ||
keycloakOrg: { | ||
default: { | ||
baseUrl: 'https://example.com/auth', | ||
schedule: { | ||
frequency: 'P1M', | ||
timeout: 'PT3M', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
await startTestBackend({ | ||
extensionPoints: [[catalogProcessingExtensionPoint, extensionPoint]], | ||
features: [ | ||
catalogModuleKeycloakEntityProvider(), | ||
mockServices.rootConfig.factory({ data: config }), | ||
scheduler.factory, | ||
], | ||
}); | ||
|
||
expect(usedSchedule?.frequency).toEqual(Duration.fromISO('P1M')); | ||
expect(usedSchedule?.timeout).toEqual(Duration.fromISO('PT3M')); | ||
expect(addedProviders?.length).toEqual(1); | ||
expect(addedProviders?.pop()?.getProviderName()).toEqual( | ||
'KeycloakOrgEntityProvider:default', | ||
); | ||
expect(runner).not.toHaveBeenCalled(); | ||
}); | ||
}); |
53 changes: 53 additions & 0 deletions
53
plugins/keycloak-backend/src/module/catalogModuleKeycloakEntityProvider.ts
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,53 @@ | ||
/* | ||
* Copyright 2023 The Janus IDP 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 { loggerToWinstonLogger } from '@backstage/backend-common'; | ||
import { | ||
coreServices, | ||
createBackendModule, | ||
} from '@backstage/backend-plugin-api'; | ||
import { catalogProcessingExtensionPoint } from '@backstage/plugin-catalog-node/alpha'; | ||
|
||
import { KeycloakOrgEntityProvider } from '../providers'; | ||
|
||
/** | ||
* Registers the `KeycloakEntityProvider` with the catalog processing extension point. | ||
* | ||
* @alpha | ||
*/ | ||
export const catalogModuleKeycloakEntityProvider = createBackendModule({ | ||
pluginId: 'catalog', | ||
moduleId: 'keycloakEntityProvider', | ||
register(env) { | ||
env.registerInit({ | ||
deps: { | ||
catalog: catalogProcessingExtensionPoint, | ||
config: coreServices.rootConfig, | ||
logger: coreServices.logger, | ||
scheduler: coreServices.scheduler, | ||
}, | ||
async init({ catalog, config, logger, scheduler }) { | ||
catalog.addEntityProvider( | ||
KeycloakOrgEntityProvider.fromConfig(config, { | ||
id: 'development', | ||
logger: loggerToWinstonLogger(logger), | ||
scheduler, | ||
}), | ||
); | ||
}, | ||
}); | ||
}, | ||
}); |
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 Janus IDP 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 { catalogModuleKeycloakEntityProvider as default } from './catalogModuleKeycloakEntityProvider'; |
Oops, something went wrong.