mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
feat(Azure Storage Node): New node (#12536)
This commit is contained in:
committed by
GitHub
parent
d550382a4a
commit
727f6f3c0e
@@ -0,0 +1,32 @@
|
||||
import type { ICredentialType, INodeProperties } from 'n8n-workflow';
|
||||
|
||||
export class AzureStorageOAuth2Api implements ICredentialType {
|
||||
name = 'azureStorageOAuth2Api';
|
||||
|
||||
displayName = 'Azure Storage OAuth2 API';
|
||||
|
||||
extends = ['microsoftOAuth2Api'];
|
||||
|
||||
documentationUrl = 'azurestorage';
|
||||
|
||||
properties: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Account',
|
||||
name: 'account',
|
||||
type: 'string',
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Base URL',
|
||||
name: 'baseUrl',
|
||||
type: 'hidden',
|
||||
default: '=https://{{ $self["account"] }}.blob.core.windows.net',
|
||||
},
|
||||
{
|
||||
displayName: 'Scope',
|
||||
name: 'scope',
|
||||
type: 'hidden',
|
||||
default: 'https://storage.azure.com/.default',
|
||||
},
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
import type {
|
||||
ICredentialDataDecryptedObject,
|
||||
ICredentialType,
|
||||
IHttpRequestOptions,
|
||||
INodeProperties,
|
||||
} from 'n8n-workflow';
|
||||
import { createHmac } from 'node:crypto';
|
||||
|
||||
import {
|
||||
getCanonicalizedHeadersString,
|
||||
getCanonicalizedResourceString,
|
||||
HeaderConstants,
|
||||
} from '../nodes/Microsoft/Storage/GenericFunctions';
|
||||
|
||||
export class AzureStorageSharedKeyApi implements ICredentialType {
|
||||
name = 'azureStorageSharedKeyApi';
|
||||
|
||||
displayName = 'Azure Storage Shared Key API';
|
||||
|
||||
documentationUrl = 'azurestorage';
|
||||
|
||||
properties: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Account',
|
||||
name: 'account',
|
||||
description: 'Account name',
|
||||
type: 'string',
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Key',
|
||||
name: 'key',
|
||||
description: 'Account key',
|
||||
type: 'string',
|
||||
typeOptions: {
|
||||
password: true,
|
||||
},
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Base URL',
|
||||
name: 'baseUrl',
|
||||
type: 'hidden',
|
||||
default: '=https://{{ $self["account"] }}.blob.core.windows.net',
|
||||
},
|
||||
];
|
||||
|
||||
async authenticate(
|
||||
credentials: ICredentialDataDecryptedObject,
|
||||
requestOptions: IHttpRequestOptions,
|
||||
): Promise<IHttpRequestOptions> {
|
||||
if (requestOptions.qs) {
|
||||
for (const [key, value] of Object.entries(requestOptions.qs)) {
|
||||
if (value === undefined) {
|
||||
delete requestOptions.qs[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (requestOptions.headers) {
|
||||
for (const [key, value] of Object.entries(requestOptions.headers)) {
|
||||
if (value === undefined) {
|
||||
delete requestOptions.headers[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
requestOptions.method ??= 'GET';
|
||||
requestOptions.headers ??= {};
|
||||
|
||||
const stringToSign: string = [
|
||||
requestOptions.method.toUpperCase(),
|
||||
requestOptions.headers[HeaderConstants.CONTENT_LANGUAGE] ?? '',
|
||||
requestOptions.headers[HeaderConstants.CONTENT_ENCODING] ?? '',
|
||||
requestOptions.headers[HeaderConstants.CONTENT_LENGTH] ?? '',
|
||||
requestOptions.headers[HeaderConstants.CONTENT_MD5] ?? '',
|
||||
requestOptions.headers[HeaderConstants.CONTENT_TYPE] ?? '',
|
||||
requestOptions.headers[HeaderConstants.DATE] ?? '',
|
||||
requestOptions.headers[HeaderConstants.IF_MODIFIED_SINCE] ?? '',
|
||||
requestOptions.headers[HeaderConstants.IF_MATCH] ?? '',
|
||||
requestOptions.headers[HeaderConstants.IF_NONE_MATCH] ?? '',
|
||||
requestOptions.headers[HeaderConstants.IF_UNMODIFIED_SINCE] ?? '',
|
||||
requestOptions.headers[HeaderConstants.RANGE] ?? '',
|
||||
getCanonicalizedHeadersString(requestOptions) +
|
||||
getCanonicalizedResourceString(requestOptions, credentials),
|
||||
].join('\n');
|
||||
|
||||
const signature: string = createHmac('sha256', Buffer.from(credentials.key as string, 'base64'))
|
||||
.update(stringToSign, 'utf8')
|
||||
.digest('base64');
|
||||
|
||||
requestOptions.headers[HeaderConstants.AUTHORIZATION] =
|
||||
`SharedKey ${credentials.account as string}:${signature}`;
|
||||
|
||||
return requestOptions;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user