@cryptotaxi247 / netdata-1 / commits / 6bc851a74

fix MQTT connection on OTP fail (#10839)

Timotej S committed Apr 20, 2021 at 10:52 UTC 6bc851a7433b126d1f94b7d0b891d58f0d3adfaf
3 files changed +13 -4
aclk/aclk.c
+5 -2
@@ -520,9 +520,12 @@ static int aclk_attempt_to_connect(mqtt_wss_client client)
520 continue;
521 }
522
523 - // TODO check success
524 - aclk_get_mqtt_otp(aclk_private_key, &mqtt_otp_user, &mqtt_otp_pass, &auth_url);
523 + ret = aclk_get_mqtt_otp(aclk_private_key, &mqtt_otp_user, &mqtt_otp_pass, &auth_url);
524 url_t_destroy(&auth_url);
525 + if (ret) {
526 + error("Error passing Challenge/Response to get OTP");
527 + continue;
528 + }
529
530 mqtt_conn_params.clientid = mqtt_otp_user;
531 mqtt_conn_params.username = mqtt_otp_user;
aclk/aclk_otp.c
+7 -1
@@ -189,7 +189,10 @@ static int aclk_https_request(https_req_t *request, https_req_response_t *respon
189 }
190
191 #define OTP_URL_PREFIX "/api/v1/auth/node/"
192 -void aclk_get_mqtt_otp(RSA *p_key, char **mqtt_usr, char **mqtt_pass, url_t *target) {
192 +int aclk_get_mqtt_otp(RSA *p_key, char **mqtt_usr, char **mqtt_pass, url_t *target) {
193 + // TODO this fnc will be rewritten and simplified in following PRs
194 + // still carries lot of baggage from ACLK Legacy
195 + int rc = 1;
196 BUFFER *url = buffer_create(strlen(OTP_URL_PREFIX) + UUID_STR_LEN + 20);
197
198 https_req_t req = HTTPS_REQ_T_INITIALIZER;
@@ -289,12 +292,15 @@ void aclk_get_mqtt_otp(RSA *p_key, char **mqtt_usr, char **mqtt_pass, url_t *tar
292 *mqtt_usr = agent_id;
293 agent_id = NULL;
294
295 + rc = 0;
296 +
297 cleanup_resp:
298 https_req_response_free(&resp);
299 cleanup:
300 if (agent_id != NULL)
301 freez(agent_id);
302 buffer_free(url);
303 + return rc;
304 }
305
306 #define PARSE_ENV_JSON_CHK_TYPE(it, type, name) \
aclk/aclk_otp.h
+1 -1
@@ -7,7 +7,7 @@
7
8 #include "https_client.h"
9
10 -void aclk_get_mqtt_otp(RSA *p_key, char **mqtt_usr, char **mqtt_pass, url_t *target);
10 +int aclk_get_mqtt_otp(RSA *p_key, char **mqtt_usr, char **mqtt_pass, url_t *target);
11 int aclk_get_env(aclk_env_t *env, const char *aclk_hostname, int aclk_port);
12
13 #endif /* ACLK_OTP_H */