0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

feat(core): enable creating a new connector with specified id (#3099)

This commit is contained in:
Darcy Ye 2023-02-13 15:13:12 +08:00 committed by GitHub
parent af272446d9
commit 84bb5b29f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -128,16 +128,18 @@ export default function connectorRoutes<T extends AuthedRouter>(
router.post(
'/connectors',
koaGuard({
body: Connectors.createGuard.pick({
body: Connectors.createGuard
.pick({
config: true,
connectorId: true,
metadata: true,
syncProfile: true,
}),
})
.merge(Connectors.createGuard.pick({ id: true }).partial()), // `id` is optional
}),
async (ctx, next) => {
const {
body: { connectorId, metadata, config, syncProfile },
body: { id: proposedId, connectorId, metadata, config, syncProfile },
} = ctx.guard;
const connectorFactories = await loadConnectorFactories();
@ -190,7 +192,7 @@ export default function connectorRoutes<T extends AuthedRouter>(
validateConfig(config, rawConnector.configGuard);
}
const insertConnectorId = generateConnectorId();
const insertConnectorId = proposedId ?? generateConnectorId();
await insertConnector({
id: insertConnectorId,
connectorId,