Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚡ Set timezone in luxon #3115

Merged
merged 1 commit into from
Apr 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions packages/cli/src/CredentialsHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ 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);
Expand Down Expand Up @@ -127,6 +128,7 @@ export class CredentialsHelper extends ICredentialsHelper {
{ $credentials: credentials },
workflow,
node,
defaultTimezone,
);

const value = this.resolveValue(
Expand All @@ -135,6 +137,7 @@ export class CredentialsHelper extends ICredentialsHelper {
{ $credentials: credentials },
workflow,
node,
defaultTimezone,
);
requestOptions.headers[key] = value;
} else if (authenticate.type === 'queryAuth') {
Expand All @@ -144,6 +147,7 @@ export class CredentialsHelper extends ICredentialsHelper {
{ $credentials: credentials },
workflow,
node,
defaultTimezone,
);

const value = this.resolveValue(
Expand All @@ -152,6 +156,7 @@ export class CredentialsHelper extends ICredentialsHelper {
{ $credentials: credentials },
workflow,
node,
defaultTimezone,
);
if (!requestOptions.qs) {
requestOptions.qs = {};
Expand All @@ -172,6 +177,7 @@ export class CredentialsHelper extends ICredentialsHelper {
additionalKeys: IWorkflowDataProxyAdditionalKeys,
workflow: Workflow,
node: INode,
defaultTimezone: string,
): string {
if (parameterValue.charAt(0) !== '=') {
return parameterValue;
Expand All @@ -181,6 +187,7 @@ export class CredentialsHelper extends ICredentialsHelper {
node,
parameterValue,
'internal',
defaultTimezone,
additionalKeys,
'',
);
Expand Down Expand Up @@ -293,6 +300,7 @@ export class CredentialsHelper extends ICredentialsHelper {
nodeCredentials: INodeCredentialsDetails,
type: string,
mode: WorkflowExecuteMode,
defaultTimezone: string,
raw?: boolean,
expressionResolveValues?: ICredentialsExpressionResolveValues,
): Promise<ICredentialDataDecryptedObject> {
Expand All @@ -307,6 +315,7 @@ export class CredentialsHelper extends ICredentialsHelper {
decryptedDataOriginal,
type,
mode,
defaultTimezone,
expressionResolveValues,
);
}
Expand All @@ -323,6 +332,7 @@ export class CredentialsHelper extends ICredentialsHelper {
decryptedDataOriginal: ICredentialDataDecryptedObject,
type: string,
mode: WorkflowExecuteMode,
defaultTimezone: string,
expressionResolveValues?: ICredentialsExpressionResolveValues,
): ICredentialDataDecryptedObject {
const credentialsProperties = this.getCredentialsProperties(type);
Expand All @@ -342,21 +352,19 @@ export class CredentialsHelper extends ICredentialsHelper {
}

if (expressionResolveValues) {
const timezone =
(expressionResolveValues.workflow.settings.timezone as string) || defaultTimezone;

try {
const workflow = new Workflow({
nodes: Object.values(expressionResolveValues.workflow.nodes),
connections: expressionResolveValues.workflow.connectionsBySourceNode,
active: false,
nodeTypes: expressionResolveValues.workflow.nodeTypes,
});
decryptedData = workflow.expression.getParameterValue(
decryptedData = expressionResolveValues.workflow.expression.getParameterValue(
decryptedData as INodeParameters,
expressionResolveValues.runExecutionData,
expressionResolveValues.runIndex,
expressionResolveValues.itemIndex,
expressionResolveValues.node.name,
expressionResolveValues.connectionInputData,
mode,
timezone,
{},
false,
decryptedData,
Expand Down Expand Up @@ -387,6 +395,7 @@ export class CredentialsHelper extends ICredentialsHelper {
node,
decryptedData as INodeParameters,
mode,
defaultTimezone,
{},
undefined,
decryptedData,
Expand Down
12 changes: 12 additions & 0 deletions packages/cli/src/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1706,18 +1706,21 @@ class App {
}

const mode: WorkflowExecuteMode = 'internal';
const timezone = config.getEnv('generic.timezone');
const credentialsHelper = new CredentialsHelper(encryptionKey);
const decryptedDataOriginal = await credentialsHelper.getDecrypted(
credential as INodeCredentialsDetails,
credential.type,
mode,
timezone,
true,
);

const oauthCredentials = credentialsHelper.applyDefaultsAndOverwrites(
decryptedDataOriginal,
credential.type,
mode,
timezone,
);

const signatureMethod = _.get(oauthCredentials, 'signatureMethod') as string;
Expand Down Expand Up @@ -1844,17 +1847,20 @@ class App {
}

const mode: WorkflowExecuteMode = 'internal';
const timezone = config.getEnv('generic.timezone');
const credentialsHelper = new CredentialsHelper(encryptionKey);
const decryptedDataOriginal = await credentialsHelper.getDecrypted(
credential as INodeCredentialsDetails,
credential.type,
mode,
timezone,
true,
);
const oauthCredentials = credentialsHelper.applyDefaultsAndOverwrites(
decryptedDataOriginal,
credential.type,
mode,
timezone,
);

const options: OptionsWithUrl = {
Expand Down Expand Up @@ -1959,18 +1965,21 @@ class App {
}

const mode: WorkflowExecuteMode = 'internal';
const timezone = config.getEnv('generic.timezone');
const credentialsHelper = new CredentialsHelper(encryptionKey);
const decryptedDataOriginal = await credentialsHelper.getDecrypted(
credential as INodeCredentialsDetails,
credential.type,
mode,
timezone,
true,
);

const oauthCredentials = credentialsHelper.applyDefaultsAndOverwrites(
decryptedDataOriginal,
credential.type,
mode,
timezone,
);

const token = new csrf();
Expand Down Expand Up @@ -2099,17 +2108,20 @@ class App {
}

const mode: WorkflowExecuteMode = 'internal';
const timezone = config.getEnv('generic.timezone');
const credentialsHelper = new CredentialsHelper(encryptionKey);
const decryptedDataOriginal = await credentialsHelper.getDecrypted(
credential as INodeCredentialsDetails,
credential.type,
mode,
timezone,
true,
);
const oauthCredentials = credentialsHelper.applyDefaultsAndOverwrites(
decryptedDataOriginal,
credential.type,
mode,
timezone,
);

const token = new csrf();
Expand Down
61 changes: 24 additions & 37 deletions packages/cli/src/WebhookHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,26 +132,6 @@ export function encodeWebhookResponse(
return response;
}

/**
* Returns all the webhooks which should be created for the give workflow
*
* @export
* @param {string} workflowId
* @param {Workflow} workflow
* @returns {IWebhookData[]}
*/
export function getWorkflowWebhooksBasic(workflow: Workflow): IWebhookData[] {
// Check all the nodes in the workflow if they have webhooks

const returnData: IWebhookData[] = [];

for (const node of Object.values(workflow.nodes)) {
returnData.push.apply(returnData, NodeHelpers.getNodeWebhooksBasic(workflow, node));
}

return returnData;
}

/**
* Executes a webhook
*
Expand Down Expand Up @@ -194,18 +174,37 @@ export async function executeWebhook(
$executionId: executionId,
};

let user: User;
if (
(workflowData as WorkflowEntity).shared?.length &&
(workflowData as WorkflowEntity).shared[0].user
) {
user = (workflowData as WorkflowEntity).shared[0].user;
} else {
try {
user = await getWorkflowOwner(workflowData.id.toString());
} catch (error) {
throw new ResponseHelper.ResponseError('Cannot find workflow', undefined, 404);
}
}

// Prepare everything that is needed to run the workflow
const additionalData = await WorkflowExecuteAdditionalData.getBase(user.id);

// Get the responseMode
const responseMode = workflow.expression.getSimpleParameterValue(
workflowStartNode,
webhookData.webhookDescription.responseMode,
executionMode,
additionalData.timezone,
additionalKeys,
'onReceived',
);
const responseCode = workflow.expression.getSimpleParameterValue(
workflowStartNode,
webhookData.webhookDescription.responseCode,
executionMode,
additionalData.timezone,
additionalKeys,
200,
) as number;
Expand All @@ -214,6 +213,7 @@ export async function executeWebhook(
workflowStartNode,
webhookData.webhookDescription.responseData,
executionMode,
additionalData.timezone,
additionalKeys,
'firstEntryJson',
);
Expand All @@ -227,23 +227,6 @@ export async function executeWebhook(
throw new ResponseHelper.ResponseError(errorMessage, 500, 500);
}

let user: User;
if (
(workflowData as WorkflowEntity).shared?.length &&
(workflowData as WorkflowEntity).shared[0].user
) {
user = (workflowData as WorkflowEntity).shared[0].user;
} else {
try {
user = await getWorkflowOwner(workflowData.id.toString());
} catch (error) {
throw new ResponseHelper.ResponseError('Cannot find workflow', undefined, 404);
}
}

// Prepare everything that is needed to run the workflow
const additionalData = await WorkflowExecuteAdditionalData.getBase(user.id);

// Add the Response and Request so that this data can be accessed in the node
additionalData.httpRequest = req;
additionalData.httpResponse = res;
Expand Down Expand Up @@ -302,6 +285,7 @@ export async function executeWebhook(
workflowStartNode,
webhookData.webhookDescription.responseHeaders,
executionMode,
additionalData.timezone,
additionalKeys,
undefined,
) as {
Expand Down Expand Up @@ -560,6 +544,7 @@ export async function executeWebhook(
workflowStartNode,
webhookData.webhookDescription.responsePropertyName,
executionMode,
additionalData.timezone,
additionalKeys,
undefined,
);
Expand All @@ -572,6 +557,7 @@ export async function executeWebhook(
workflowStartNode,
webhookData.webhookDescription.responseContentType,
executionMode,
additionalData.timezone,
additionalKeys,
undefined,
);
Expand Down Expand Up @@ -616,6 +602,7 @@ export async function executeWebhook(
workflowStartNode,
webhookData.webhookDescription.responseBinaryPropertyName,
executionMode,
additionalData.timezone,
additionalKeys,
'data',
);
Expand Down
3 changes: 3 additions & 0 deletions packages/cli/test/unit/CredentialsHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ describe('CredentialsHelper', () => {
nodeTypes,
});

const timezone = 'America/New_York';

for (const testData of tests) {
test(testData.description, async () => {
const credentialTypes: ICredentialTypeData = {
Expand All @@ -296,6 +298,7 @@ describe('CredentialsHelper', () => {
JSON.parse(JSON.stringify(incomingRequestOptions)),
workflow,
node,
timezone,
);

expect(result).toEqual(testData.output);
Expand Down
Loading