refactor(core): Abstract away InstanceSettings and encryptionKey into injectable services (no-changelog) (#7471)
This change ensures that things like `encryptionKey` and `instanceId` are always available directly where they are needed, instead of passing them around throughout the code.
This commit is contained in:
committed by
GitHub
parent
519680c2cf
commit
b6de910cbe
@@ -39,7 +39,7 @@
|
||||
"dist/**/*"
|
||||
],
|
||||
"devDependencies": {
|
||||
"@types/crypto-js": "^4.1.1",
|
||||
"@types/crypto-js": "^4.1.3",
|
||||
"@types/deep-equal": "^1.0.1",
|
||||
"@types/express": "^4.17.6",
|
||||
"@types/jmespath": "^0.15.0",
|
||||
|
||||
@@ -108,17 +108,13 @@ export abstract class ICredentials {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
abstract getData(encryptionKey: string, nodeType?: string): ICredentialDataDecryptedObject;
|
||||
|
||||
abstract getDataKey(key: string, encryptionKey: string, nodeType?: string): CredentialInformation;
|
||||
abstract getData(nodeType?: string): ICredentialDataDecryptedObject;
|
||||
|
||||
abstract getDataToSave(): ICredentialsEncrypted;
|
||||
|
||||
abstract hasNodeAccess(nodeType: string): boolean;
|
||||
|
||||
abstract setData(data: ICredentialDataDecryptedObject, encryptionKey: string): void;
|
||||
|
||||
abstract setDataKey(key: string, data: CredentialInformation, encryptionKey: string): void;
|
||||
abstract setData(data: ICredentialDataDecryptedObject): void;
|
||||
}
|
||||
|
||||
export interface IUser {
|
||||
@@ -192,8 +188,6 @@ export interface IHttpRequestHelper {
|
||||
helpers: { httpRequest: IAllExecuteFunctions['helpers']['httpRequest'] };
|
||||
}
|
||||
export abstract class ICredentialsHelper {
|
||||
constructor(readonly encryptionKey: string) {}
|
||||
|
||||
abstract getParentTypes(name: string): string[];
|
||||
|
||||
abstract authenticate(
|
||||
@@ -740,7 +734,7 @@ export interface FunctionsBase {
|
||||
getTimezone(): string;
|
||||
getRestApiUrl(): string;
|
||||
getInstanceBaseUrl(): string;
|
||||
getInstanceId(): Promise<string>;
|
||||
getInstanceId(): string;
|
||||
|
||||
getMode?: () => WorkflowExecuteMode;
|
||||
getActivationMode?: () => WorkflowActivateMode;
|
||||
@@ -1847,7 +1841,6 @@ export interface IWorkflowExecuteHooks {
|
||||
|
||||
export interface IWorkflowExecuteAdditionalData {
|
||||
credentialsHelper: ICredentialsHelper;
|
||||
encryptionKey: string;
|
||||
executeWorkflow: (
|
||||
workflowInfo: IExecuteWorkflowInfo,
|
||||
additionalData: IWorkflowExecuteAdditionalData,
|
||||
@@ -1860,7 +1853,6 @@ export interface IWorkflowExecuteAdditionalData {
|
||||
parentWorkflowSettings?: IWorkflowSettings;
|
||||
},
|
||||
) => Promise<any>;
|
||||
// hooks?: IWorkflowExecuteHooks;
|
||||
executionId?: string;
|
||||
restartExecutionId?: string;
|
||||
hooks?: WorkflowHooks;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import get from 'lodash/get';
|
||||
import type {
|
||||
CredentialInformation,
|
||||
IAdditionalCredentialOptions,
|
||||
IAllExecuteFunctions,
|
||||
IContextObject,
|
||||
@@ -44,48 +43,21 @@ export interface INodeTypesObject {
|
||||
}
|
||||
|
||||
export class Credentials extends ICredentials {
|
||||
hasNodeAccess(nodeType: string): boolean {
|
||||
hasNodeAccess() {
|
||||
return true;
|
||||
}
|
||||
|
||||
setData(data: ICredentialDataDecryptedObject, encryptionKey: string): void {
|
||||
setData(data: ICredentialDataDecryptedObject) {
|
||||
this.data = JSON.stringify(data);
|
||||
}
|
||||
|
||||
setDataKey(key: string, data: CredentialInformation, encryptionKey: string): void {
|
||||
let fullData;
|
||||
try {
|
||||
fullData = this.getData(encryptionKey);
|
||||
} catch (e) {
|
||||
fullData = {};
|
||||
}
|
||||
|
||||
fullData[key] = data;
|
||||
|
||||
return this.setData(fullData, encryptionKey);
|
||||
}
|
||||
|
||||
getData(encryptionKey: string, nodeType?: string): ICredentialDataDecryptedObject {
|
||||
getData(): ICredentialDataDecryptedObject {
|
||||
if (this.data === undefined) {
|
||||
throw new Error('No data is set so nothing can be returned.');
|
||||
}
|
||||
return JSON.parse(this.data);
|
||||
}
|
||||
|
||||
getDataKey(key: string, encryptionKey: string, nodeType?: string): CredentialInformation {
|
||||
const fullData = this.getData(encryptionKey, nodeType);
|
||||
|
||||
if (fullData === null) {
|
||||
throw new Error('No data was set.');
|
||||
}
|
||||
|
||||
if (!fullData.hasOwnProperty(key)) {
|
||||
throw new Error(`No data for key "${key}" exists.`);
|
||||
}
|
||||
|
||||
return fullData[key];
|
||||
}
|
||||
|
||||
getDataToSave(): ICredentialsEncrypted {
|
||||
if (this.data === undefined) {
|
||||
throw new Error('No credentials were set to save.');
|
||||
@@ -702,12 +674,11 @@ export function WorkflowExecuteAdditionalData(): IWorkflowExecuteAdditionalData
|
||||
};
|
||||
|
||||
return {
|
||||
credentialsHelper: new CredentialsHelper(''),
|
||||
credentialsHelper: new CredentialsHelper(),
|
||||
hooks: new WorkflowHooks({}, 'trigger', '1', workflowData),
|
||||
executeWorkflow: async (workflowInfo: IExecuteWorkflowInfo): Promise<any> => {},
|
||||
sendMessageToUI: (message: string) => {},
|
||||
sendDataToUI: (message: string) => {},
|
||||
restApiUrl: '',
|
||||
encryptionKey: 'test',
|
||||
timezone: 'America/New_York',
|
||||
webhookBaseUrl: 'webhook',
|
||||
webhookWaitingBaseUrl: 'webhook-waiting',
|
||||
|
||||
Reference in New Issue
Block a user