mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-20 11:22:15 +00:00
refactor(core): Prevent a server from starting if it's configured to use S3, but the license does not allow it (#13532)
This commit is contained in:
committed by
GitHub
parent
7fb88e623f
commit
223ec2d9c9
@@ -4,7 +4,6 @@ import { mock } from 'jest-mock-extended';
|
||||
import { Readable } from 'stream';
|
||||
|
||||
import { ObjectStoreService } from '@/binary-data/object-store/object-store.service.ee';
|
||||
import { writeBlockedMessage } from '@/binary-data/object-store/utils';
|
||||
|
||||
jest.mock('axios');
|
||||
|
||||
@@ -128,23 +127,6 @@ describe('put()', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should block if read-only', async () => {
|
||||
objectStoreService.setReadonly(true);
|
||||
|
||||
const metadata = { fileName: 'file.txt', mimeType: 'text/plain' };
|
||||
|
||||
const promise = objectStoreService.put(fileId, mockBuffer, metadata);
|
||||
|
||||
await expect(promise).resolves.not.toThrow();
|
||||
|
||||
const result = await promise;
|
||||
|
||||
expect(result.status).toBe(403);
|
||||
expect(result.statusText).toBe('Forbidden');
|
||||
|
||||
expect(result.data).toBe(writeBlockedMessage(fileId));
|
||||
});
|
||||
|
||||
it('should throw an error on request failure', async () => {
|
||||
const metadata = { fileName: 'file.txt', mimeType: 'text/plain' };
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import { Service } from '@n8n/di';
|
||||
import { sign } from 'aws4';
|
||||
import type { Request as Aws4Options } from 'aws4';
|
||||
import axios from 'axios';
|
||||
import type { AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig, Method } from 'axios';
|
||||
import type { AxiosRequestConfig, Method } from 'axios';
|
||||
import { ApplicationError } from 'n8n-workflow';
|
||||
import { createHash } from 'node:crypto';
|
||||
import type { Readable } from 'stream';
|
||||
@@ -11,7 +11,7 @@ import type { Readable } from 'stream';
|
||||
import { Logger } from '@/logging/logger';
|
||||
|
||||
import type { ListPage, MetadataResponseHeaders, RawListPage, RequestOptions } from './types';
|
||||
import { isStream, parseXml, writeBlockedMessage } from './utils';
|
||||
import { isStream, parseXml } from './utils';
|
||||
import type { BinaryData } from '../types';
|
||||
|
||||
@Service()
|
||||
@@ -20,8 +20,6 @@ export class ObjectStoreService {
|
||||
|
||||
private isReady = false;
|
||||
|
||||
private isReadOnly = false;
|
||||
|
||||
constructor(
|
||||
private readonly logger: Logger,
|
||||
private readonly s3Config: S3Config,
|
||||
@@ -48,10 +46,6 @@ export class ObjectStoreService {
|
||||
this.setReady(true);
|
||||
}
|
||||
|
||||
setReadonly(newState: boolean) {
|
||||
this.isReadOnly = newState;
|
||||
}
|
||||
|
||||
setReady(newState: boolean) {
|
||||
this.isReady = newState;
|
||||
}
|
||||
@@ -73,8 +67,6 @@ export class ObjectStoreService {
|
||||
* @doc https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutObject.html
|
||||
*/
|
||||
async put(filename: string, buffer: Buffer, metadata: BinaryData.PreWriteMetadata = {}) {
|
||||
if (this.isReadOnly) return await this.blockWrite(filename);
|
||||
|
||||
const headers: Record<string, string | number> = {
|
||||
'Content-Length': buffer.length,
|
||||
'Content-MD5': createHash('md5').update(buffer).digest('base64'),
|
||||
@@ -204,20 +196,6 @@ export class ObjectStoreService {
|
||||
return page as ListPage;
|
||||
}
|
||||
|
||||
private async blockWrite(filename: string): Promise<AxiosResponse> {
|
||||
const logMessage = writeBlockedMessage(filename);
|
||||
|
||||
this.logger.warn(logMessage);
|
||||
|
||||
return {
|
||||
status: 403,
|
||||
statusText: 'Forbidden',
|
||||
data: logMessage,
|
||||
headers: {},
|
||||
config: {} as InternalAxiosRequestConfig,
|
||||
};
|
||||
}
|
||||
|
||||
private async request<T>(
|
||||
method: Method,
|
||||
rawPath = '',
|
||||
|
||||
@@ -14,7 +14,3 @@ export async function parseXml<T>(xml: string): Promise<T> {
|
||||
valueProcessors: [parseNumbers, parseBooleans],
|
||||
}) as Promise<T>);
|
||||
}
|
||||
|
||||
export function writeBlockedMessage(filename: string) {
|
||||
return `Request to write file "${filename}" to object storage was blocked because S3 storage is not available with your current license. Please upgrade to a license that supports this feature, or set N8N_DEFAULT_BINARY_DATA_MODE to an option other than "s3".`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user