mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-10 22:54:05 -08:00
ed927d34b2
Github issue / Community forum post (link here to close automatically): --------- Co-authored-by: Romain Minaud <romain.minaud@gmail.com> Co-authored-by: Valya Bullions <valya@n8n.io> Co-authored-by: Csaba Tuncsik <csaba@n8n.io> Co-authored-by: Giulio Andreini <g.andreini@gmail.com> Co-authored-by: Omar Ajoue <krynble@gmail.com>
216 lines
4.2 KiB
TypeScript
216 lines
4.2 KiB
TypeScript
import { SecretsProvider } from '@/Interfaces';
|
|
import type { SecretsProviderSettings, SecretsProviderState } from '@/Interfaces';
|
|
import type { IDataObject, INodeProperties } from 'n8n-workflow';
|
|
|
|
export class MockProviders {
|
|
providers: Record<string, { new (): SecretsProvider }> = {
|
|
dummy: DummyProvider,
|
|
};
|
|
|
|
setProviders(providers: Record<string, { new (): SecretsProvider }>) {
|
|
this.providers = providers;
|
|
}
|
|
|
|
getProvider(name: string): { new (): SecretsProvider } | null {
|
|
return this.providers[name] ?? null;
|
|
}
|
|
|
|
hasProvider(name: string) {
|
|
return name in this.providers;
|
|
}
|
|
|
|
getAllProviders() {
|
|
return this.providers;
|
|
}
|
|
}
|
|
|
|
export class DummyProvider extends SecretsProvider {
|
|
properties: INodeProperties[] = [
|
|
{
|
|
name: 'username',
|
|
displayName: 'Username',
|
|
type: 'string',
|
|
default: '',
|
|
required: true,
|
|
},
|
|
{
|
|
name: 'other',
|
|
displayName: 'Other',
|
|
type: 'string',
|
|
default: '',
|
|
},
|
|
{
|
|
name: 'password',
|
|
displayName: 'Password',
|
|
type: 'string',
|
|
default: '',
|
|
typeOptions: {
|
|
password: true,
|
|
},
|
|
},
|
|
];
|
|
|
|
secrets: Record<string, string> = {};
|
|
|
|
displayName = 'Dummy Provider';
|
|
|
|
name = 'dummy';
|
|
|
|
state: SecretsProviderState = 'initializing';
|
|
|
|
_updateSecrets: Record<string, string> = {
|
|
test1: 'value1',
|
|
test2: 'value2',
|
|
};
|
|
|
|
async init(settings: SecretsProviderSettings<IDataObject>): Promise<void> {}
|
|
|
|
async connect(): Promise<void> {
|
|
this.state = 'connected';
|
|
}
|
|
|
|
async disconnect(): Promise<void> {}
|
|
|
|
async update(): Promise<void> {
|
|
this.secrets = this._updateSecrets;
|
|
}
|
|
|
|
async test(): Promise<[boolean] | [boolean, string]> {
|
|
return [true];
|
|
}
|
|
|
|
getSecret(name: string): IDataObject | undefined {
|
|
return this.secrets[name] as unknown as IDataObject | undefined;
|
|
}
|
|
|
|
hasSecret(name: string): boolean {
|
|
return name in this.secrets;
|
|
}
|
|
|
|
getSecretNames(): string[] {
|
|
return Object.keys(this.secrets);
|
|
}
|
|
}
|
|
|
|
export class ErrorProvider extends SecretsProvider {
|
|
secrets: Record<string, string> = {};
|
|
|
|
displayName = 'Error Provider';
|
|
|
|
name = 'dummy';
|
|
|
|
state: SecretsProviderState = 'initializing';
|
|
|
|
async init(settings: SecretsProviderSettings<IDataObject>): Promise<void> {
|
|
throw new Error();
|
|
}
|
|
|
|
async connect(): Promise<void> {
|
|
this.state = 'error';
|
|
throw new Error();
|
|
}
|
|
|
|
async disconnect(): Promise<void> {
|
|
throw new Error();
|
|
}
|
|
|
|
async update(): Promise<void> {
|
|
throw new Error();
|
|
}
|
|
|
|
async test(): Promise<[boolean] | [boolean, string]> {
|
|
throw new Error();
|
|
}
|
|
|
|
getSecret(name: string): IDataObject | undefined {
|
|
throw new Error();
|
|
}
|
|
|
|
hasSecret(name: string): boolean {
|
|
throw new Error();
|
|
}
|
|
|
|
getSecretNames(): string[] {
|
|
throw new Error();
|
|
}
|
|
}
|
|
|
|
export class FailedProvider extends SecretsProvider {
|
|
secrets: Record<string, string> = {};
|
|
|
|
displayName = 'Failed Provider';
|
|
|
|
name = 'dummy';
|
|
|
|
state: SecretsProviderState = 'initializing';
|
|
|
|
async init(settings: SecretsProviderSettings<IDataObject>): Promise<void> {}
|
|
|
|
async connect(): Promise<void> {
|
|
this.state = 'error';
|
|
}
|
|
|
|
async disconnect(): Promise<void> {}
|
|
|
|
async update(): Promise<void> {}
|
|
|
|
async test(): Promise<[boolean] | [boolean, string]> {
|
|
return [true];
|
|
}
|
|
|
|
getSecret(name: string): IDataObject | undefined {
|
|
return this.secrets[name] as unknown as IDataObject | undefined;
|
|
}
|
|
|
|
hasSecret(name: string): boolean {
|
|
return name in this.secrets;
|
|
}
|
|
|
|
getSecretNames(): string[] {
|
|
return Object.keys(this.secrets);
|
|
}
|
|
}
|
|
|
|
export class TestFailProvider extends SecretsProvider {
|
|
secrets: Record<string, string> = {};
|
|
|
|
displayName = 'Test Failed Provider';
|
|
|
|
name = 'dummy';
|
|
|
|
state: SecretsProviderState = 'initializing';
|
|
|
|
_updateSecrets: Record<string, string> = {
|
|
test1: 'value1',
|
|
test2: 'value2',
|
|
};
|
|
|
|
async init(settings: SecretsProviderSettings<IDataObject>): Promise<void> {}
|
|
|
|
async connect(): Promise<void> {
|
|
this.state = 'connected';
|
|
}
|
|
|
|
async disconnect(): Promise<void> {}
|
|
|
|
async update(): Promise<void> {
|
|
this.secrets = this._updateSecrets;
|
|
}
|
|
|
|
async test(): Promise<[boolean] | [boolean, string]> {
|
|
return [false];
|
|
}
|
|
|
|
getSecret(name: string): IDataObject | undefined {
|
|
return this.secrets[name] as unknown as IDataObject | undefined;
|
|
}
|
|
|
|
hasSecret(name: string): boolean {
|
|
return name in this.secrets;
|
|
}
|
|
|
|
getSecretNames(): string[] {
|
|
return Object.keys(this.secrets);
|
|
}
|
|
}
|