Skip to content

Commit 705742f

Browse files
Merge branch 'master' into SER-2456-active-directory-tenant-id-is-not-set-correctly
2 parents 357d353 + c4fe69a commit 705742f

29 files changed

+2556
-80
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
## Version 25.03.XX
22
Fixes:
33
- [active_directory] Fix for reading azure application tenant id from config
4+
- [core] Set up default headers for common return methods
5+
46
## Version 25.03.8
57
Fixes:
68
- [core] Fix adding llm observability to cly-event-select component

Dockerfile-api

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ ARG COUNTLY_PLUGINS=mobile,web,desktop,plugins,density,locale,browser,sources,vi
66

77
ARG GEOIP=empty
88
EXPOSE 3001
9-
HEALTHCHECK --start-period=400s CMD curl --fail http://localhost:3001/o/ping || exit 1
9+
HEALTHCHECK --start-period=400s CMD bash -c '\
10+
if [ "$COUNTLY_CONFIG_API_API_SSL_ENABLED" = "true" ] || [ "$COUNTLY_CONFIG_API_API_SSL_ENABLED" = "\"true\"" ]; then \
11+
curl -k --fail https://localhost:3001/o/ping || exit 1; \
12+
else \
13+
curl --fail http://localhost:3001/o/ping || exit 1; \
14+
fi'
1015

1116
USER root
1217

Dockerfile-centos-api

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ ARG COUNTLY_PLUGINS=mobile,web,desktop,plugins,density,locale,browser,sources,vi
66

77
ARG GEOIP=empty
88
EXPOSE 3001
9-
HEALTHCHECK --start-period=400s CMD curl --fail http://localhost:3001/o/ping || exit 1
9+
HEALTHCHECK --start-period=400s CMD bash -c '\
10+
if [ "$COUNTLY_CONFIG_API_API_SSL_ENABLED" = "true" ] || [ "$COUNTLY_CONFIG_API_API_SSL_ENABLED" = "\"true\"" ]; then \
11+
curl -k --fail https://localhost:3001/o/ping || exit 1; \
12+
else \
13+
curl --fail http://localhost:3001/o/ping || exit 1; \
14+
fi'
1015

1116
USER root
1217

Dockerfile-centos-frontend

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ ARG COUNTLY_PLUGINS=mobile,web,desktop,plugins,density,locale,browser,sources,vi
55
#ARG COUNTLY_PLUGINS=mobile,web,desktop,plugins,density,locale,browser,sources,views,license,drill,funnels,retention_segments,flows,cohorts,surveys,remote-config,ab-testing,formulas,activity-map,concurrent_users,revenue,logger,systemlogs,populator,reports,crashes,push,geo,block,users,star-rating,slipping-away-users,compare,server-stats,dbviewer,crash_symbolication,crashes-jira,groups,white-labeling,alerts,times-of-day,compliance-hub,onboarding,active_users,performance-monitoring,config-transfer,consolidate,data-manager,hooks,dashboards,heatmaps,sdk,guides,journey_engine,content
66

77
EXPOSE 6001
8-
HEALTHCHECK --start-period=400s CMD curl --fail http://localhost:6001/ping || exit 1
8+
HEALTHCHECK --start-period=400s CMD bash -c '\
9+
if [ "$COUNTLY_CONFIG_FRONTEND_WEB_SSL_ENABLED" = "true" ] || [ "$COUNTLY_CONFIG_FRONTEND_WEB_SSL_ENABLED" = "\"true\"" ]; then \
10+
curl -k --fail https://localhost:6001/ping || exit 1; \
11+
else \
12+
curl --fail http://localhost:6001/ping || exit 1; \
13+
fi'
914

1015
USER root
1116

Dockerfile-frontend

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ ARG COUNTLY_PLUGINS=mobile,web,desktop,plugins,density,locale,browser,sources,vi
55
#ARG COUNTLY_PLUGINS=mobile,web,desktop,plugins,density,locale,browser,sources,views,license,drill,funnels,retention_segments,flows,cohorts,surveys,remote-config,ab-testing,formulas,activity-map,concurrent_users,revenue,logger,systemlogs,populator,reports,crashes,push,geo,block,users,star-rating,slipping-away-users,compare,server-stats,dbviewer,crash_symbolication,crashes-jira,groups,white-labeling,alerts,times-of-day,compliance-hub,onboarding,active_users,performance-monitoring,config-transfer,consolidate,data-manager,hooks,dashboards,heatmaps,sdk,guides,journey_engine,content
66

77
EXPOSE 6001
8-
HEALTHCHECK --start-period=400s CMD curl --fail http://localhost:6001/ping || exit 1
8+
HEALTHCHECK --start-period=400s CMD bash -c '\
9+
if [ "$COUNTLY_CONFIG_FRONTEND_WEB_SSL_ENABLED" = "true" ] || [ "$COUNTLY_CONFIG_FRONTEND_WEB_SSL_ENABLED" = "\"true\"" ]; then \
10+
curl -k --fail https://localhost:6001/ping || exit 1; \
11+
else \
12+
curl --fail http://localhost:6001/ping || exit 1; \
13+
fi'
914

1015
USER root
1116

@@ -19,6 +24,7 @@ ENV COUNTLY_CONTAINER="frontend" \
1924

2025
WORKDIR /opt/countly
2126
COPY . .
27+
2228
# install required dependencies which slim image doesn't have
2329
RUN apt-get update && \
2430
apt-get install -y iputils-ping net-tools telnet apt-transport-https procps curl wget git make gcc g++ unzip xz-utils

api/config.sample.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ var countlyConfig = {
7373
enabled: false,
7474
key: "/path/to/ssl/private.key",
7575
cert: "/path/to/ssl/certificate.crt",
76-
ca: "/path/to/ssl/ca_bundle.crt" // Optional: for client certificate verification
76+
// ca: "/path/to/ssl/ca_bundle.crt" // Optional: for client certificate verification, uncomment to activate
7777
}
7878
},
7979
/**

api/parts/data/usage.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,16 @@ plugins.register("/sdk/user_properties", async function(ob) {
11171117
userProps.av_major = versionComponents.major;
11181118
userProps.av_minor = versionComponents.minor;
11191119
userProps.av_patch = versionComponents.patch;
1120+
userProps.av_prerel = versionComponents.prerelease;
1121+
userProps.av_build = versionComponents.build;
1122+
}
1123+
else {
1124+
log.w("Invalid app version format: %s", params.qstring.metrics._app_version);
1125+
userProps.av_major = null;
1126+
userProps.av_minor = null;
1127+
userProps.av_patch = null;
1128+
userProps.av_rel = null;
1129+
userProps.av_build = null;
11201130
}
11211131
}
11221132
}

api/utils/common.js

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
* @typedef {import('../../types/requestProcessor').Params} Params
77
* @typedef {import('../../types/common').TimeObject} TimeObject
88
* @typedef {import('mongodb').ObjectId} ObjectId
9-
* typedef {import('moment-timezone').Moment} MomentTimezone
9+
* @typedef {import('moment-timezone').Moment} MomentTimezone
1010
*/
1111

1212
/** @lends module:api/utils/common **/
13-
/** @type(import('../../types/common').Common) */
13+
/** @type {import('../../types/common').Common} */
1414
const common = {};
1515

16-
/** @type(import('moment-timezone')) */
16+
/** @type {import('moment-timezone')} */
1717
const moment = require('moment-timezone');
1818
const crypto = require('crypto');
1919
const logger = require('./log.js');
@@ -176,6 +176,7 @@ function escape_html_entities(key, value, more) {
176176
common.getJSON = getJSON;
177177

178178
common.log = logger;
179+
const log = logger('api:utils:common');
179180

180181
common.dbMap = {
181182
'events': 'e',
@@ -1307,16 +1308,23 @@ common.returnRaw = function(params, returnCode, body, heads) {
13071308
}
13081309
return;
13091310
}
1311+
const defaultHeaders = {};
13101312
//set provided in configuration headers
1311-
var headers = {};
1313+
let headers = {};
13121314
if (heads) {
13131315
for (var i in heads) {
13141316
headers[i] = heads[i];
13151317
}
13161318
}
13171319
if (params && params.res && params.res.writeHead && !params.blockResponses) {
13181320
if (!params.res.finished) {
1319-
params.res.writeHead(returnCode, headers);
1321+
try {
1322+
params.res.writeHead(returnCode, headers);
1323+
}
1324+
catch (err) {
1325+
log.e(`Error writing header in 'returnRaw' ${err}`);
1326+
params.res.writeHead(returnCode, defaultHeaders);
1327+
}
13201328
if (body) {
13211329
params.res.write(body);
13221330
}
@@ -1347,9 +1355,10 @@ common.returnMessage = function(params, returnCode, message, heads, noResult = f
13471355
return;
13481356
}
13491357
//set provided in configuration headers
1350-
var headers = {
1358+
const defaultHeaders = {
13511359
'Content-Type': 'application/json; charset=utf-8'
13521360
};
1361+
let headers = { ...defaultHeaders };
13531362
var add_headers = (plugins.getConfig("security").api_additional_headers || "").replace(/\r\n|\r|\n/g, "\n").split("\n");
13541363
var parts;
13551364
for (let i = 0; i < add_headers.length; i++) {
@@ -1373,7 +1382,13 @@ common.returnMessage = function(params, returnCode, message, heads, noResult = f
13731382
}
13741383
if (params && params.res && params.res.writeHead && !params.blockResponses) {
13751384
if (!params.res.finished) {
1376-
params.res.writeHead(returnCode, headers);
1385+
try {
1386+
params.res.writeHead(returnCode, headers);
1387+
}
1388+
catch (err) {
1389+
log.e(`Error writing header in 'returnMessage' ${err}`);
1390+
params.res.writeHead(returnCode, defaultHeaders);
1391+
}
13771392
if (params.qstring.callback) {
13781393
params.res.write(params.qstring.callback + '(' + JSON.stringify({result: message}, escape_html_entities) + ')');
13791394
}
@@ -1415,9 +1430,10 @@ common.returnOutput = function(params, output, noescape, heads) {
14151430
return;
14161431
}
14171432
//set provided in configuration headers
1418-
var headers = {
1433+
const defaultHeaders = {
14191434
'Content-Type': 'application/json; charset=utf-8'
14201435
};
1436+
let headers = { ...defaultHeaders };
14211437
var add_headers = (plugins.getConfig("security").api_additional_headers || "").replace(/\r\n|\r|\n/g, "\n").split("\n");
14221438
var parts;
14231439
for (let i = 0; i < add_headers.length; i++) {
@@ -1442,7 +1458,13 @@ common.returnOutput = function(params, output, noescape, heads) {
14421458
}
14431459
if (params && params.res && params.res.writeHead && !params.blockResponses) {
14441460
if (!params.res.finished) {
1445-
params.res.writeHead(200, headers);
1461+
try {
1462+
params.res.writeHead(200, headers);
1463+
}
1464+
catch (err) {
1465+
log.e(`Error writing header in 'returnMessage' ${err}`);
1466+
params.res.writeHead(200, defaultHeaders);
1467+
}
14461468
if (params.qstring.callback) {
14471469
params.res.write(params.qstring.callback + '(' + JSON.stringify(output, escape) + ')');
14481470
}
@@ -2069,19 +2091,16 @@ common.parseAppVersion = function(version) {
20692091
version = String(version);
20702092
}
20712093

2072-
// Ensure version has at least one decimal point
2073-
if (version.indexOf('.') === -1) {
2074-
version += '.0';
2075-
}
2076-
2077-
const parsedVersion = semver.valid(semver.coerce(version));
2078-
if (parsedVersion) {
2079-
const versionObj = semver.parse(parsedVersion);
2094+
const isValid = semver.valid(semver.coerce(version, {includePrerelease: true}));
2095+
if (isValid) {
2096+
const versionObj = semver.parse(semver.coerce(version, {includePrerelease: true}));
20802097
if (versionObj) {
20812098
return {
20822099
major: versionObj.major,
20832100
minor: versionObj.minor,
20842101
patch: versionObj.patch,
2102+
prerelease: versionObj.prerelease,
2103+
build: versionObj.build,
20852104
original: version,
20862105
success: true
20872106
};
@@ -3465,5 +3484,5 @@ common.trimWhitespaceStartEnd = function(value) {
34653484
return value;
34663485
};
34673486

3468-
/** @type(import('../../types/common').Common) */
3487+
/** @type {import('../../types/common').Common} */
34693488
module.exports = common;

api/utils/localization.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @module api/utils/localization
44
*/
55

6-
/** @type(import('../../types/localization').Locale) */
6+
/** @type {import('../../types/localization').Locale} */
77
var locale = {},
88
fs = require('fs'),
99
path = require('path'),
@@ -91,5 +91,5 @@ locale.getProperties = function(lang, callback) {
9191
}
9292
};
9393

94-
/** @type(import('../../types/localization').Locale) */
94+
/** @type {import('../../types/localization').Locale} */
9595
module.exports = locale;

frontend/express/config.sample.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ var countlyConfig = {
8282
enabled: false,
8383
key: "/path/to/ssl/private.key",
8484
cert: "/path/to/ssl/certificate.crt",
85-
ca: "/path/to/ssl/ca_bundle.crt" // Optional: for client certificate verification
85+
// ca: "/path/to/ssl/ca_bundle.crt" // Optional: for client certificate verification, uncomment to activate
8686
}
8787
},
8888
/**
@@ -121,4 +121,4 @@ var countlyConfig = {
121121
passwordSecret: ""
122122
};
123123

124-
module.exports = require('../../api/configextender')('FRONTEND', countlyConfig, process.env);
124+
module.exports = require('../../api/configextender')('FRONTEND', countlyConfig, process.env);

0 commit comments

Comments
 (0)