Skip to content

Commit

Permalink
refactor(core): Convert more routes to use the decorator pattern (no-…
Browse files Browse the repository at this point in the history
…changelog) (#5611)

* move nodeTypes api to a controller class
* move tags api to a controller class
* move LDAP routes to a controller class
* move nodes routes to a controller class
  • Loading branch information
netroy authored Mar 9, 2023
1 parent 493f7a1 commit 356e916
Show file tree
Hide file tree
Showing 19 changed files with 360 additions and 393 deletions.
77 changes: 0 additions & 77 deletions packages/cli/src/Ldap/routes/ldap.controller.ee.ts

This file was deleted.

53 changes: 21 additions & 32 deletions packages/cli/src/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ import config from '@/config';
import * as Queue from '@/Queue';
import { getSharedWorkflowIds } from '@/WorkflowHelpers';

import { nodesController } from '@/api/nodes.api';
import { workflowsController } from '@/workflows/workflows.controller';
import {
EDITOR_UI_DIST_DIR,
Expand All @@ -83,16 +82,18 @@ import type {
import { registerController } from '@/decorators';
import {
AuthController,
LdapController,
MeController,
NodesController,
NodeTypesController,
OwnerController,
PasswordResetController,
TagsController,
TranslationController,
UsersController,
} from '@/controllers';

import { executionsController } from '@/executions/executions.controller';
import { nodeTypesController } from '@/api/nodeTypes.api';
import { tagsController } from '@/api/tags.api';
import { workflowStatsController } from '@/api/workflowStats.api';
import { loadPublicApiVersions } from '@/PublicApi';
import {
Expand Down Expand Up @@ -134,7 +135,6 @@ import { licenseController } from './license/license.controller';
import { Push, setupPushServer, setupPushHandler } from '@/push';
import { setupAuthMiddlewares } from './middlewares';
import { initEvents } from './events';
import { ldapController } from './Ldap/routes/ldap.controller.ee';
import { getLdapLoginLabel, isLdapEnabled, isLdapLoginEnabled } from './Ldap/helpers';
import { AbstractServer } from './AbstractServer';
import { configureMetrics } from './metrics';
Expand All @@ -152,6 +152,7 @@ import { getSamlLoginLabel, isSamlLoginEnabled, isSamlLicensed } from './sso/sam
import { samlControllerPublic } from './sso/saml/routes/saml.controller.public.ee';
import { SamlService } from './sso/saml/saml.service.ee';
import { samlControllerProtected } from './sso/saml/routes/saml.controller.protected.ee';
import { LdapManager } from './Ldap/LdapManager.ee';

const exec = promisify(callbackExec);

Expand Down Expand Up @@ -371,7 +372,7 @@ class Server extends AbstractServer {
}

private registerControllers(ignoredEndpoints: Readonly<string[]>) {
const { app, externalHooks, activeWorkflowRunner } = this;
const { app, externalHooks, activeWorkflowRunner, nodeTypes } = this;
const repositories = Db.collections;
setupAuthMiddlewares(app, ignoredEndpoints, this.restEndpoint, repositories.User);

Expand All @@ -380,11 +381,13 @@ class Server extends AbstractServer {
const mailer = getMailerInstance();
const postHog = this.postHog;

const controllers = [
const controllers: object[] = [
new AuthController({ config, internalHooks, repositories, logger, postHog }),
new OwnerController({ config, internalHooks, repositories, logger }),
new MeController({ externalHooks, internalHooks, repositories, logger }),
new NodeTypesController({ config, nodeTypes }),
new PasswordResetController({ config, externalHooks, internalHooks, repositories, logger }),
new TagsController({ config, repositories, externalHooks }),
new TranslationController(config, this.credentialTypes),
new UsersController({
config,
Expand All @@ -397,6 +400,18 @@ class Server extends AbstractServer {
postHog,
}),
];

if (isLdapEnabled()) {
const { service, sync } = LdapManager.getInstance();
controllers.push(new LdapController(service, sync, internalHooks));
}

if (config.getEnv('nodes.communityPackages.enabled')) {
controllers.push(
new NodesController(config, this.loadNodesAndCredentials, this.push, internalHooks),
);
}

controllers.forEach((controller) => registerController(app, config, controller));
}

Expand Down Expand Up @@ -482,13 +497,6 @@ class Server extends AbstractServer {

this.app.use(`/${this.restEndpoint}/credentials`, credentialsController);

// ----------------------------------------
// Packages and nodes management
// ----------------------------------------
if (config.getEnv('nodes.communityPackages.enabled')) {
this.app.use(`/${this.restEndpoint}/nodes`, nodesController);
}

// ----------------------------------------
// Workflow
// ----------------------------------------
Expand All @@ -504,18 +512,6 @@ class Server extends AbstractServer {
// ----------------------------------------
this.app.use(`/${this.restEndpoint}/workflow-stats`, workflowStatsController);

// ----------------------------------------
// Tags
// ----------------------------------------
this.app.use(`/${this.restEndpoint}/tags`, tagsController);

// ----------------------------------------
// LDAP
// ----------------------------------------
if (isLdapEnabled()) {
this.app.use(`/${this.restEndpoint}/ldap`, ldapController);
}

// ----------------------------------------
// SAML
// ----------------------------------------
Expand All @@ -534,7 +530,6 @@ class Server extends AbstractServer {
this.app.use(`/${this.restEndpoint}/sso/saml`, samlControllerProtected);

// ----------------------------------------

// Returns parameter values which normally get loaded from an external API or
// get generated dynamically
this.app.get(
Expand Down Expand Up @@ -645,12 +640,6 @@ class Server extends AbstractServer {
),
);

// ----------------------------------------
// Node-Types
// ----------------------------------------

this.app.use(`/${this.restEndpoint}/node-types`, nodeTypesController);

// ----------------------------------------
// Active Workflows
// ----------------------------------------
Expand Down
110 changes: 0 additions & 110 deletions packages/cli/src/api/tags.api.ts

This file was deleted.

4 changes: 4 additions & 0 deletions packages/cli/src/controllers/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
export { AuthController } from './auth.controller';
export { LdapController } from './ldap.controller';
export { MeController } from './me.controller';
export { NodesController } from './nodes.controller';
export { NodeTypesController } from './nodeTypes.controller';
export { OwnerController } from './owner.controller';
export { PasswordResetController } from './passwordReset.controller';
export { TagsController } from './tags.controller';
export { TranslationController } from './translation.controller';
export { UsersController } from './users.controller';
Loading

0 comments on commit 356e916

Please sign in to comment.