Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
90 lines
2.2 KiB
TypeScript
90 lines
2.2 KiB
TypeScript
import get from 'lodash/get';
|
|
import type {
|
|
IDataObject,
|
|
IExecuteFunctions,
|
|
IHookFunctions,
|
|
ILoadOptionsFunctions,
|
|
IWebhookFunctions,
|
|
IHttpRequestOptions,
|
|
JsonObject,
|
|
IHttpRequestMethods,
|
|
} from 'n8n-workflow';
|
|
import { jsonParse, NodeApiError } from 'n8n-workflow';
|
|
import { getAwsCredentials } from '../GenericFunctions';
|
|
|
|
export async function awsApiRequest(
|
|
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions | IWebhookFunctions,
|
|
service: string,
|
|
method: IHttpRequestMethods,
|
|
path: string,
|
|
body?: string | Buffer,
|
|
query: IDataObject = {},
|
|
headers?: object,
|
|
): Promise<any> {
|
|
const { credentials, credentialsType } = await getAwsCredentials(this);
|
|
|
|
const requestOptions = {
|
|
qs: {
|
|
service,
|
|
path,
|
|
...query,
|
|
},
|
|
headers,
|
|
method,
|
|
url: '',
|
|
body,
|
|
region: credentials?.region as string,
|
|
} as IHttpRequestOptions;
|
|
|
|
try {
|
|
return await this.helpers.requestWithAuthentication.call(this, credentialsType, requestOptions);
|
|
} catch (error) {
|
|
throw new NodeApiError(this.getNode(), error as JsonObject);
|
|
}
|
|
}
|
|
|
|
export async function awsApiRequestREST(
|
|
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions,
|
|
service: string,
|
|
method: IHttpRequestMethods,
|
|
path: string,
|
|
body?: string,
|
|
query: IDataObject = {},
|
|
headers?: object,
|
|
): Promise<any> {
|
|
const response = await awsApiRequest.call(this, service, method, path, body, query, headers);
|
|
try {
|
|
return JSON.parse(response as string);
|
|
} catch (e) {
|
|
return response;
|
|
}
|
|
}
|
|
|
|
export async function awsApiRequestAllItems(
|
|
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions,
|
|
propertyName: string,
|
|
service: string,
|
|
method: IHttpRequestMethods,
|
|
path: string,
|
|
body?: string,
|
|
query: IDataObject = {},
|
|
headers: IDataObject = {},
|
|
): Promise<any> {
|
|
const returnData: IDataObject[] = [];
|
|
|
|
let responseData;
|
|
|
|
do {
|
|
responseData = await awsApiRequestREST.call(this, service, method, path, body, query, headers);
|
|
if (responseData.NextToken) {
|
|
const data = jsonParse<any>(body as string, {
|
|
errorMessage: 'Response body is not valid JSON',
|
|
});
|
|
data.NextToken = responseData.NextToken;
|
|
}
|
|
returnData.push.apply(returnData, get(responseData, propertyName) as IDataObject[]);
|
|
} while (responseData.NextToken !== undefined);
|
|
|
|
return returnData;
|
|
}
|