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

chore(release): pull hotfix-release/v1.43.0 into main #2653

Merged
merged 2 commits into from
Sep 25, 2023
Merged
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [1.43.0](https://github.com/rudderlabs/rudder-transformer/compare/v1.42.0...v1.43.0) (2023-09-25)


### Features

* update google_cloud_function implementation as per custom destination ([#2652](https://github.com/rudderlabs/rudder-transformer/issues/2652)) ([5c981e1](https://github.com/rudderlabs/rudder-transformer/commit/5c981e12c8e203c80229881a07704c6413c842a9))

## [1.42.0](https://github.com/rudderlabs/rudder-transformer/compare/v1.41.1...v1.42.0) (2023-09-18)


Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rudder-transformer",
"version": "1.42.0",
"version": "1.43.0",
"description": "",
"homepage": "https://github.com/rudderlabs/rudder-transformer#readme",
"bugs": {
Expand Down
7 changes: 0 additions & 7 deletions src/v0/destinations/google_cloud_function/config.js

This file was deleted.

16 changes: 3 additions & 13 deletions src/v0/destinations/google_cloud_function/transform.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,19 @@
const _ = require('lodash');
const {
defaultRequestConfig,
defaultPostRequestConfig,
getSuccessRespEvents,
checkInvalidRtTfEvents,
handleRtTfSingleEventError,
} = require('../../util');

const { generateBatchedPayload, validateDestinationConfig, addHeader } = require('./util');
const { generateBatchedPayload, validateDestinationConfig } = require('./util');

// Main process Function to handle transformation
function process(event) {
const { message, destination } = event;
const { googleCloudFunctionUrl } = destination.Config;

// Config Validation
validateDestinationConfig(destination);

const response = defaultRequestConfig();
// adding header
addHeader(response, destination.Config);
response.method = defaultPostRequestConfig.requestMethod;
response.body.JSON = message;
response.endpoint = googleCloudFunctionUrl;

const response = message;
return response;
}

Expand All @@ -37,7 +27,7 @@ function batchEvents(successRespList, maxBatchSize = 10) {
const batchEventResponse = generateBatchedPayload(chunk);
batchedResponseList.push(
getSuccessRespEvents(
batchEventResponse.batchedRequest,
batchEventResponse.message,
batchEventResponse.metadata,
batchEventResponse.destination,
true,
Expand Down
50 changes: 10 additions & 40 deletions src/v0/destinations/google_cloud_function/util.js
Original file line number Diff line number Diff line change
@@ -1,77 +1,47 @@
const { defaultBatchRequestConfig } = require('../../util');
const { JSON_MIME_TYPE } = require('../../util/constant');
const { ConfigurationError } = require('../../util/errorTypes');

const { TRIGGERTYPE } = require('./config');

/**
* validate destination config
* @param {*} param0
*/
const validateDestinationConfig = ({ Config }) => {
// throw error if google Cloud Function is not provided
// throw error if google Cloud Function URL is not provided
if (!Config.googleCloudFunctionUrl) {
throw new ConfigurationError('[GCF]:: Url not found. Aborting');
}
if (
Config.triggerType === 'https' && // for triggerType https gcloud Authorization is mandatory
!Config.gcloudAuthorization
) {
throw new ConfigurationError('[GCF]:: Access Token not found. Aborting');
if (Config.requireAuthentication && !Config.credentials) {
throw new ConfigurationError(
'[GCF]:: Service Account credentials are required if your function required authentication. Aborting',
);
}
};

/**
* add headers in the payload that is provided in destination config
* @param {*} response
* @param {*} Config
*/
function addHeader(response, Config) {
const { triggerType, apiKeyId, gcloudAuthorization } = Config;

response.headers = { 'content-type': JSON_MIME_TYPE };
if (apiKeyId) {
const basicAuth = Buffer.from(`apiKey:${apiKeyId}`).toString('base64');
response.headers.ApiKey = `Basic ${basicAuth}`;
}
if (TRIGGERTYPE.HTTPS === triggerType.toLowerCase()) {
response.headers.Authorization = `bearer ${gcloudAuthorization}`;
}
}

/**
* Create GoogleCloudFunction Batch payload based on the passed events
* @param {*} events
* @returns
*/

function generateBatchedPayload(events) {
const batchResponseList = [];
const metadata = [];
// extracting destination
// from the first event in a batch
const { destination } = events[0];
const { googleCloudFunctionUrl } = destination.Config;
let batchEventResponse = defaultBatchRequestConfig();
let batchEventResponse = events.map((event) => event.message);
// Batch event into dest batch structure
events.forEach((ev) => {
batchResponseList.push(ev.message.body.JSON);
// batchResponseList.push(ev.message.body.JSON);
metadata.push(ev.metadata);
});
batchEventResponse.batchedRequest.body.JSON_ARRAY = {
batch: JSON.stringify(batchResponseList),
};
batchEventResponse.batchedRequest.endpoint = googleCloudFunctionUrl;
addHeader(batchEventResponse.batchedRequest, destination.Config);
batchEventResponse = {
...batchEventResponse,
metadata,
message: batchEventResponse,
destination,
metadata,
};
return batchEventResponse;
}

module.exports = {
validateDestinationConfig,
addHeader,
generateBatchedPayload,
};
170 changes: 0 additions & 170 deletions test/__tests__/data/google_cloud_function_router_input.json

This file was deleted.

Loading
Loading