Skip to content

Commit 82c7fd1

Browse files
author
phillipperalez
authored
Enforce Max delivery size on Slack (Slack's own limit) (#668)
1 parent 07fc10c commit 82c7fd1

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

lib/actions/hubspot/hubspot.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ class HubspotAction extends Hub.Action {
3030
this.iconName = "hubspot/hubspot.png";
3131
this.params = [
3232
{
33-
description: "An api key for Hubspot.",
34-
label: "Hubspot API Key",
35-
name: "hubspot_api_key",
33+
description: "Access Token of your Private Hubspot App.",
34+
label: "Hubspot Access Token",
35+
name: "hubspot_access_token",
3636
required: true,
3737
sensitive: true,
3838
},
@@ -70,7 +70,7 @@ class HubspotAction extends Hub.Action {
7070
return this.executeHubspot(request);
7171
}
7272
hubspotClientFromRequest(request) {
73-
return new hubspot.Client({ apiKey: request.params.hubspot_api_key });
73+
return new hubspot.Client({ accessToken: request.params.hubspot_access_token });
7474
}
7575
taggedFields(fields, tags) {
7676
return fields.filter((f) => f.tags &&
@@ -198,6 +198,7 @@ class HubspotAction extends Hub.Action {
198198
errors.push(e);
199199
}
200200
if (errors.length > 0) {
201+
winston.debug(`Hubspot encountered errors: ${util.inspect(errors)}`);
201202
let msg = errors.map((e) => (e.message ? e.message : e)).join(", ");
202203
if (msg.length === 0) {
203204
msg = "An unknown error occurred while processing the Hubspot action.";

lib/actions/slack/utils.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { WebClient } from "@slack/web-api";
22
import * as Hub from "../../hub";
33
import { ActionFormField } from "../../hub";
44
export declare const API_LIMIT_SIZE = 1000;
5+
export declare const MAX_SIZE: number;
56
export declare const getDisplayedFormFields: (slack: WebClient, channelType: string) => Promise<ActionFormField[]>;
67
export declare const handleExecute: (request: Hub.ActionRequest, slack: WebClient) => Promise<Hub.ActionResponse>;
78
export declare const displayError: {

lib/actions/slack/utils.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
3-
exports.displayError = exports.handleExecute = exports.getDisplayedFormFields = exports.API_LIMIT_SIZE = void 0;
3+
exports.displayError = exports.handleExecute = exports.getDisplayedFormFields = exports.MAX_SIZE = exports.API_LIMIT_SIZE = void 0;
44
const web_api_1 = require("@slack/web-api");
55
const gaxios = require("gaxios");
66
const winston = require("winston");
77
const http_errors_1 = require("../../error_types/http_errors");
88
const Hub = require("../../hub");
99
const action_response_1 = require("../../hub/action_response");
1010
exports.API_LIMIT_SIZE = 1000;
11+
exports.MAX_SIZE = 2 ** 30;
1112
const LOG_PREFIX = "[SLACK]";
1213
const _usableChannels = async (slack) => {
1314
const options = {
@@ -139,7 +140,12 @@ const handleExecute = async (request, slack) => {
139140
await new Promise((resolve, reject) => {
140141
readable.on("readable", () => {
141142
let buff = readable.read();
143+
let size = 0;
142144
while (buff) {
145+
size += buff.length;
146+
if (size > exports.MAX_SIZE) {
147+
reject("Payload was over 1 GB which is not supported");
148+
}
143149
buffs.push(buff);
144150
buff = readable.read();
145151
}

src/actions/slack/utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {ActionFormField} from "../../hub"
77
import { Error, errorWith } from "../../hub/action_response"
88

99
export const API_LIMIT_SIZE = 1000
10+
export const MAX_SIZE = 2 ** 30
1011

1112
const LOG_PREFIX = "[SLACK]"
1213

@@ -153,7 +154,12 @@ export const handleExecute = async (request: Hub.ActionRequest, slack: WebClient
153154
await new Promise<void>((resolve, reject) => {
154155
readable.on("readable", () => {
155156
let buff = readable.read()
157+
let size = 0
156158
while (buff) {
159+
size += buff.length
160+
if (size > MAX_SIZE) {
161+
reject("Payload was over 1 GB which is not supported")
162+
}
157163
buffs.push(buff)
158164
buff = readable.read()
159165
}

0 commit comments

Comments
 (0)