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

WIP feat(Microsoft Azure Storage Node): New node #12536

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type { ICredentialType, INodeProperties } from 'n8n-workflow';

export class MicrosoftStorageOAuth2Api implements ICredentialType {
name = 'microsoftStorageOAuth2Api';

displayName = 'Microsoft Storage API';

extends = ['microsoftOAuth2Api'];

documentationUrl = 'microsoftstorage';

properties: INodeProperties[] = [
{
displayName: 'Account',
name: 'account',
type: 'string',
default: '',
},
{
displayName: 'Base URL',
name: 'baseUrl',
type: 'hidden',
// default: '=https://{{ $self["account"] }}.blob.core.windows.net',
default: '=http://127.0.0.1:10000/{{ $self["account"] }}',
},
{
displayName: 'Scope',
name: 'scope',
type: 'hidden',
default: 'openid offline_access',
},
];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
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 MicrosoftStorageSharedKeyApi implements ICredentialType {
name = 'microsoftStorageSharedKeyApi';

displayName = 'Microsoft Storage API';

documentationUrl = 'microsoftstorage';

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',
default: '=http://127.0.0.1:10000/{{ $self["account"] }}',
},
];

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];
}
}
}

requestOptions.method ??= 'GET';
requestOptions.headers ??= {};
requestOptions.headers[HeaderConstants.X_MS_DATE] = new Date().toUTCString();
requestOptions.headers[HeaderConstants.X_MS_VERSION] = '2020-04-08'; // Minimum version: https://learn.microsoft.com/en-us/rest/api/storageservices/put-blob-from-url?tabs=microsoft-entra-id
// requestOptions.headers[HeaderConstants.X_MS_CLIENT_REQUEST_ID] = '123';

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;
}
}
Loading
Loading