refactor(core): Avoid passing around static state like default timezone (no-changelog) (#7221)
This commit is contained in:
committed by
GitHub
parent
62c096710f
commit
35bb42c1b9
@@ -37,8 +37,6 @@ export abstract class AbstractServer {
|
||||
|
||||
protected sslCert: string;
|
||||
|
||||
protected timezone: string;
|
||||
|
||||
protected restEndpoint: string;
|
||||
|
||||
protected endpointWebhook: string;
|
||||
@@ -61,8 +59,6 @@ export abstract class AbstractServer {
|
||||
this.sslKey = config.getEnv('ssl_key');
|
||||
this.sslCert = config.getEnv('ssl_cert');
|
||||
|
||||
this.timezone = config.getEnv('generic.timezone');
|
||||
|
||||
this.restEndpoint = config.getEnv('endpoints.rest');
|
||||
this.endpointWebhook = config.getEnv('endpoints.webhook');
|
||||
this.endpointWebhookTest = config.getEnv('endpoints.webhookTest');
|
||||
|
||||
@@ -106,7 +106,6 @@ export class CredentialsHelper extends ICredentialsHelper {
|
||||
incomingRequestOptions: IHttpRequestOptions | IRequestOptionsSimplified,
|
||||
workflow: Workflow,
|
||||
node: INode,
|
||||
defaultTimezone: string,
|
||||
): Promise<IHttpRequestOptions> {
|
||||
const requestOptions = incomingRequestOptions;
|
||||
const credentialType = this.credentialTypes.getByName(typeName);
|
||||
@@ -131,20 +130,13 @@ export class CredentialsHelper extends ICredentialsHelper {
|
||||
if (authenticate.type === 'generic') {
|
||||
Object.entries(authenticate.properties).forEach(([outerKey, outerValue]) => {
|
||||
Object.entries(outerValue).forEach(([key, value]) => {
|
||||
keyResolved = this.resolveValue(
|
||||
key,
|
||||
{ $credentials: credentials },
|
||||
workflow,
|
||||
node,
|
||||
defaultTimezone,
|
||||
);
|
||||
keyResolved = this.resolveValue(key, { $credentials: credentials }, workflow, node);
|
||||
|
||||
valueResolved = this.resolveValue(
|
||||
value as string,
|
||||
{ $credentials: credentials },
|
||||
workflow,
|
||||
node,
|
||||
defaultTimezone,
|
||||
);
|
||||
|
||||
// @ts-ignore
|
||||
@@ -226,7 +218,6 @@ export class CredentialsHelper extends ICredentialsHelper {
|
||||
additionalKeys: IWorkflowDataProxyAdditionalKeys,
|
||||
workflow: Workflow,
|
||||
node: INode,
|
||||
defaultTimezone: string,
|
||||
): string {
|
||||
if (typeof parameterValue !== 'string' || parameterValue.charAt(0) !== '=') {
|
||||
return parameterValue;
|
||||
@@ -236,7 +227,6 @@ export class CredentialsHelper extends ICredentialsHelper {
|
||||
node,
|
||||
parameterValue,
|
||||
'internal',
|
||||
defaultTimezone,
|
||||
additionalKeys,
|
||||
undefined,
|
||||
'',
|
||||
@@ -347,7 +337,6 @@ export class CredentialsHelper extends ICredentialsHelper {
|
||||
nodeCredentials: INodeCredentialsDetails,
|
||||
type: string,
|
||||
mode: WorkflowExecuteMode,
|
||||
defaultTimezone: string,
|
||||
raw?: boolean,
|
||||
expressionResolveValues?: ICredentialsExpressionResolveValues,
|
||||
): Promise<ICredentialDataDecryptedObject> {
|
||||
@@ -367,7 +356,6 @@ export class CredentialsHelper extends ICredentialsHelper {
|
||||
decryptedDataOriginal,
|
||||
type,
|
||||
mode,
|
||||
defaultTimezone,
|
||||
expressionResolveValues,
|
||||
canUseSecrets,
|
||||
);
|
||||
@@ -381,7 +369,6 @@ export class CredentialsHelper extends ICredentialsHelper {
|
||||
decryptedDataOriginal: ICredentialDataDecryptedObject,
|
||||
type: string,
|
||||
mode: WorkflowExecuteMode,
|
||||
defaultTimezone: string,
|
||||
expressionResolveValues?: ICredentialsExpressionResolveValues,
|
||||
canUseSecrets?: boolean,
|
||||
): ICredentialDataDecryptedObject {
|
||||
@@ -413,8 +400,6 @@ export class CredentialsHelper extends ICredentialsHelper {
|
||||
});
|
||||
|
||||
if (expressionResolveValues) {
|
||||
const timezone = expressionResolveValues.workflow.settings.timezone ?? defaultTimezone;
|
||||
|
||||
try {
|
||||
decryptedData = expressionResolveValues.workflow.expression.getParameterValue(
|
||||
decryptedData as INodeParameters,
|
||||
@@ -424,7 +409,6 @@ export class CredentialsHelper extends ICredentialsHelper {
|
||||
expressionResolveValues.node.name,
|
||||
expressionResolveValues.connectionInputData,
|
||||
mode,
|
||||
timezone,
|
||||
additionalKeys,
|
||||
undefined,
|
||||
false,
|
||||
@@ -447,7 +431,6 @@ export class CredentialsHelper extends ICredentialsHelper {
|
||||
mockNode,
|
||||
decryptedData as INodeParameters,
|
||||
mode,
|
||||
defaultTimezone,
|
||||
additionalKeys,
|
||||
undefined,
|
||||
undefined,
|
||||
@@ -597,7 +580,6 @@ export class CredentialsHelper extends ICredentialsHelper {
|
||||
credentialsDecrypted.data,
|
||||
credentialType,
|
||||
'internal' as WorkflowExecuteMode,
|
||||
additionalData.timezone,
|
||||
undefined,
|
||||
user.isOwner,
|
||||
);
|
||||
|
||||
@@ -727,14 +727,12 @@ export class Server extends AbstractServer {
|
||||
const additionalData = await WorkflowExecuteAdditionalData.getBase(req.user.id);
|
||||
|
||||
const mode: WorkflowExecuteMode = 'internal';
|
||||
const timezone = config.getEnv('generic.timezone');
|
||||
const credentialsHelper = Container.get(CredentialsHelper);
|
||||
const decryptedDataOriginal = await credentialsHelper.getDecrypted(
|
||||
additionalData,
|
||||
credential as INodeCredentialsDetails,
|
||||
credential.type,
|
||||
mode,
|
||||
timezone,
|
||||
true,
|
||||
);
|
||||
|
||||
@@ -743,7 +741,6 @@ export class Server extends AbstractServer {
|
||||
decryptedDataOriginal,
|
||||
credential.type,
|
||||
mode,
|
||||
timezone,
|
||||
);
|
||||
|
||||
const signatureMethod = oauthCredentials.signatureMethod as string;
|
||||
@@ -870,14 +867,12 @@ export class Server extends AbstractServer {
|
||||
const additionalData = await WorkflowExecuteAdditionalData.getBase(req.user.id);
|
||||
|
||||
const mode: WorkflowExecuteMode = 'internal';
|
||||
const timezone = config.getEnv('generic.timezone');
|
||||
const credentialsHelper = Container.get(CredentialsHelper);
|
||||
const decryptedDataOriginal = await credentialsHelper.getDecrypted(
|
||||
additionalData,
|
||||
credential as INodeCredentialsDetails,
|
||||
credential.type,
|
||||
mode,
|
||||
timezone,
|
||||
true,
|
||||
);
|
||||
const oauthCredentials = credentialsHelper.applyDefaultsAndOverwrites(
|
||||
@@ -885,7 +880,6 @@ export class Server extends AbstractServer {
|
||||
decryptedDataOriginal,
|
||||
credential.type,
|
||||
mode,
|
||||
timezone,
|
||||
);
|
||||
|
||||
const options: AxiosRequestConfig = {
|
||||
|
||||
@@ -246,7 +246,6 @@ export async function executeWebhook(
|
||||
workflowStartNode,
|
||||
webhookData.webhookDescription.responseMode,
|
||||
executionMode,
|
||||
additionalData.timezone,
|
||||
additionalKeys,
|
||||
undefined,
|
||||
'onReceived',
|
||||
@@ -255,7 +254,6 @@ export async function executeWebhook(
|
||||
workflowStartNode,
|
||||
webhookData.webhookDescription.responseCode,
|
||||
executionMode,
|
||||
additionalData.timezone,
|
||||
additionalKeys,
|
||||
undefined,
|
||||
200,
|
||||
@@ -265,7 +263,6 @@ export async function executeWebhook(
|
||||
workflowStartNode,
|
||||
webhookData.webhookDescription.responseData,
|
||||
executionMode,
|
||||
additionalData.timezone,
|
||||
additionalKeys,
|
||||
undefined,
|
||||
'firstEntryJson',
|
||||
@@ -288,7 +285,6 @@ export async function executeWebhook(
|
||||
workflowStartNode,
|
||||
'={{$parameter["options"]["binaryData"]}}',
|
||||
executionMode,
|
||||
additionalData.timezone,
|
||||
additionalKeys,
|
||||
undefined,
|
||||
false,
|
||||
@@ -370,7 +366,6 @@ export async function executeWebhook(
|
||||
workflowStartNode,
|
||||
webhookData.webhookDescription.responseHeaders,
|
||||
executionMode,
|
||||
additionalData.timezone,
|
||||
additionalKeys,
|
||||
undefined,
|
||||
undefined,
|
||||
@@ -644,7 +639,6 @@ export async function executeWebhook(
|
||||
workflowStartNode,
|
||||
webhookData.webhookDescription.responsePropertyName,
|
||||
executionMode,
|
||||
additionalData.timezone,
|
||||
additionalKeys,
|
||||
undefined,
|
||||
undefined,
|
||||
@@ -658,7 +652,6 @@ export async function executeWebhook(
|
||||
workflowStartNode,
|
||||
webhookData.webhookDescription.responseContentType,
|
||||
executionMode,
|
||||
additionalData.timezone,
|
||||
additionalKeys,
|
||||
undefined,
|
||||
undefined,
|
||||
@@ -704,7 +697,6 @@ export async function executeWebhook(
|
||||
workflowStartNode,
|
||||
webhookData.webhookDescription.responseBinaryPropertyName,
|
||||
executionMode,
|
||||
additionalData.timezone,
|
||||
additionalKeys,
|
||||
undefined,
|
||||
'data',
|
||||
|
||||
@@ -1006,7 +1006,6 @@ export function sendDataToUI(type: string, data: IDataObject | IDataObject[]) {
|
||||
|
||||
/**
|
||||
* Returns the base additional data without webhooks
|
||||
*
|
||||
*/
|
||||
export async function getBase(
|
||||
userId: string,
|
||||
@@ -1015,7 +1014,6 @@ export async function getBase(
|
||||
): Promise<IWorkflowExecuteAdditionalData> {
|
||||
const urlBaseWebhook = WebhookHelpers.getWebhookBaseUrl();
|
||||
|
||||
const timezone = config.getEnv('generic.timezone');
|
||||
const webhookBaseUrl = urlBaseWebhook + config.getEnv('endpoints.webhook');
|
||||
const webhookWaitingBaseUrl = urlBaseWebhook + config.getEnv('endpoints.webhookWaiting');
|
||||
const webhookTestBaseUrl = urlBaseWebhook + config.getEnv('endpoints.webhookTest');
|
||||
@@ -1026,7 +1024,6 @@ export async function getBase(
|
||||
credentialsHelper: Container.get(CredentialsHelper),
|
||||
executeWorkflow,
|
||||
restApiUrl: urlBaseWebhook + config.getEnv('endpoints.rest'),
|
||||
timezone,
|
||||
instanceBaseUrl: urlBaseWebhook,
|
||||
webhookBaseUrl,
|
||||
webhookWaitingBaseUrl,
|
||||
|
||||
@@ -3,6 +3,7 @@ import dotenv from 'dotenv';
|
||||
import { tmpdir } from 'os';
|
||||
import { mkdirSync, mkdtempSync, readFileSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
import { setGlobalState } from 'n8n-workflow';
|
||||
import { schema } from './schema';
|
||||
import { inTest, inE2ETests } from '@/constants';
|
||||
|
||||
@@ -73,6 +74,10 @@ config.validate({
|
||||
allowed: 'strict',
|
||||
});
|
||||
|
||||
setGlobalState({
|
||||
defaultTimezone: config.getEnv('generic.timezone'),
|
||||
});
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default config;
|
||||
export type Config = typeof config;
|
||||
|
||||
@@ -65,14 +65,12 @@ oauth2CredentialController.get(
|
||||
const credentialType = credential.type;
|
||||
|
||||
const mode: WorkflowExecuteMode = 'internal';
|
||||
const timezone = config.getEnv('generic.timezone');
|
||||
const credentialsHelper = Container.get(CredentialsHelper);
|
||||
const decryptedDataOriginal = await credentialsHelper.getDecrypted(
|
||||
additionalData,
|
||||
credential as INodeCredentialsDetails,
|
||||
credentialType,
|
||||
mode,
|
||||
timezone,
|
||||
true,
|
||||
);
|
||||
|
||||
@@ -93,7 +91,6 @@ oauth2CredentialController.get(
|
||||
decryptedDataOriginal,
|
||||
credentialType,
|
||||
mode,
|
||||
timezone,
|
||||
);
|
||||
|
||||
const token = new Csrf();
|
||||
@@ -208,14 +205,12 @@ oauth2CredentialController.get(
|
||||
const additionalData = await WorkflowExecuteAdditionalData.getBase(state.cid);
|
||||
|
||||
const mode: WorkflowExecuteMode = 'internal';
|
||||
const timezone = config.getEnv('generic.timezone');
|
||||
const credentialsHelper = Container.get(CredentialsHelper);
|
||||
const decryptedDataOriginal = await credentialsHelper.getDecrypted(
|
||||
additionalData,
|
||||
credential as INodeCredentialsDetails,
|
||||
credential.type,
|
||||
mode,
|
||||
timezone,
|
||||
true,
|
||||
);
|
||||
const oauthCredentials = credentialsHelper.applyDefaultsAndOverwrites(
|
||||
@@ -223,7 +218,6 @@ oauth2CredentialController.get(
|
||||
decryptedDataOriginal,
|
||||
credential.type,
|
||||
mode,
|
||||
timezone,
|
||||
);
|
||||
|
||||
const token = new Csrf();
|
||||
|
||||
@@ -18,7 +18,6 @@ import type {
|
||||
} from 'n8n-workflow';
|
||||
import { CredentialsHelper } from '@/CredentialsHelper';
|
||||
import { Agent as HTTPSAgent } from 'https';
|
||||
import config from '@/config';
|
||||
import { isLogStreamingEnabled } from '../MessageEventBus/MessageEventBusHelper';
|
||||
import { eventMessageGenericDestinationTestEvent } from '../EventMessageClasses/EventMessageGeneric';
|
||||
import { MessageEventBus } from '../MessageEventBus/MessageEventBus';
|
||||
@@ -107,13 +106,11 @@ export class MessageEventBusDestinationWebhook
|
||||
async matchDecryptedCredentialType(credentialType: string) {
|
||||
const foundCredential = Object.entries(this.credentials).find((e) => e[0] === credentialType);
|
||||
if (foundCredential) {
|
||||
const timezone = config.getEnv('generic.timezone');
|
||||
const credentialsDecrypted = await this.credentialsHelper?.getDecrypted(
|
||||
{ secretsHelpers: SecretsHelpers } as unknown as IWorkflowExecuteAdditionalData,
|
||||
foundCredential[1],
|
||||
foundCredential[0],
|
||||
'internal',
|
||||
timezone,
|
||||
true,
|
||||
);
|
||||
return credentialsDecrypted;
|
||||
|
||||
Reference in New Issue
Block a user