mirror of
https://github.com/emqx/neuron.git
synced 2026-10-29 23:19:18 +08:00
fix(azure): clean configuration keys
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"client-id": {
|
||||
"device-id": {
|
||||
"name": "Device ID",
|
||||
"name_zh": "设备 ID",
|
||||
"description": "Azure IoT device ID, used as MQTT client id",
|
||||
@@ -84,7 +84,7 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"password": {
|
||||
"sas": {
|
||||
"name": "SAS Token",
|
||||
"name_zh": "SAS 令牌",
|
||||
"description": "Azure IoT Hub shared access signature (SAS) token",
|
||||
@@ -99,20 +99,6 @@
|
||||
"length": 255
|
||||
}
|
||||
},
|
||||
"ssl": {
|
||||
"name": "SSL",
|
||||
"name_zh": "SSL",
|
||||
"description": "Enable SSL connection",
|
||||
"description_zh": "是否启用 SSL 连接",
|
||||
"attribute": "optional",
|
||||
"type": "bool",
|
||||
"default": true,
|
||||
"condition": {
|
||||
"field": "invisible",
|
||||
"value": true
|
||||
},
|
||||
"valid": {}
|
||||
},
|
||||
"ca": {
|
||||
"name": "CA",
|
||||
"name_zh": "CA 证书",
|
||||
|
||||
@@ -28,6 +28,41 @@
|
||||
#define AUTH_SAS 0
|
||||
#define AUTH_CERT 1
|
||||
|
||||
static int parse_ssl_params(neu_plugin_t *plugin, const char *setting,
|
||||
neu_json_elem_t *ca, neu_json_elem_t *cert,
|
||||
neu_json_elem_t *key)
|
||||
{
|
||||
// ca, required
|
||||
int ret = neu_parse_param(setting, NULL, 1, ca);
|
||||
if (0 != ret) {
|
||||
plog_notice(plugin, "setting no ca");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (0 != decode_b64_param(plugin, ca)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// cert, required
|
||||
ret = neu_parse_param(setting, NULL, 1, cert);
|
||||
if (0 != ret) {
|
||||
plog_notice(plugin, "setting no cert");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (0 != decode_b64_param(plugin, cert)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// key, required
|
||||
ret = parse_b64_param(plugin, setting, key);
|
||||
if (0 != ret) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int azure_parse_config(neu_plugin_t *plugin, const char *setting,
|
||||
mqtt_config_t *config)
|
||||
{
|
||||
@@ -38,17 +73,15 @@ static int azure_parse_config(neu_plugin_t *plugin, const char *setting,
|
||||
char * write_resp_topic = NULL;
|
||||
char * username = NULL;
|
||||
|
||||
neu_json_elem_t client_id = { .name = "client-id", .t = NEU_JSON_STR };
|
||||
neu_json_elem_t client_id = { .name = "device-id", .t = NEU_JSON_STR };
|
||||
neu_json_elem_t qos = { .name = "qos", .t = NEU_JSON_INT };
|
||||
neu_json_elem_t format = { .name = "format", .t = NEU_JSON_INT };
|
||||
neu_json_elem_t host = { .name = "host", .t = NEU_JSON_STR };
|
||||
neu_json_elem_t auth = { .name = "auth", .t = NEU_JSON_INT };
|
||||
neu_json_elem_t password = { .name = "password", .t = NEU_JSON_STR };
|
||||
neu_json_elem_t ssl = { .name = "ssl", .t = NEU_JSON_BOOL };
|
||||
neu_json_elem_t password = { .name = "sas", .t = NEU_JSON_STR };
|
||||
neu_json_elem_t ca = { .name = "ca", .t = NEU_JSON_STR };
|
||||
neu_json_elem_t cert = { .name = "cert", .t = NEU_JSON_STR };
|
||||
neu_json_elem_t key = { .name = "key", .t = NEU_JSON_STR };
|
||||
neu_json_elem_t keypass = { .name = "keypass", .t = NEU_JSON_STR };
|
||||
|
||||
if (NULL == setting || NULL == config) {
|
||||
plog_error(plugin, "invalid argument, null pointer");
|
||||
@@ -104,11 +137,9 @@ static int azure_parse_config(neu_plugin_t *plugin, const char *setting,
|
||||
password.v.val_str = strdup("");
|
||||
}
|
||||
|
||||
ssl.v.val_bool = true;
|
||||
if (AUTH_CERT == auth.v.val_int) {
|
||||
ret =
|
||||
parse_ssl_params(plugin, setting, &ssl, &ca, &cert, &key, &keypass);
|
||||
if (0 != ret || NULL == ca.v.val_str || NULL == cert.v.val_str) {
|
||||
ret = parse_ssl_params(plugin, setting, &ca, &cert, &key);
|
||||
if (0 != ret) {
|
||||
plog_error(plugin, "setting certificates fail");
|
||||
goto error;
|
||||
}
|
||||
@@ -200,7 +231,6 @@ error:
|
||||
free(ca.v.val_str);
|
||||
free(cert.v.val_str);
|
||||
free(key.v.val_str);
|
||||
free(keypass.v.val_str);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -308,7 +338,11 @@ static int azure_plugin_request(neu_plugin_t *plugin, neu_reqresp_head_t *head,
|
||||
break;
|
||||
}
|
||||
case NEU_REQ_SUBSCRIBE_GROUP:
|
||||
case NEU_REQ_UPDATE_SUBSCRIBE_GROUP:
|
||||
case NEU_REQ_UPDATE_SUBSCRIBE_GROUP: {
|
||||
neu_req_subscribe_t *sub_info = data;
|
||||
free(sub_info->params);
|
||||
break;
|
||||
}
|
||||
case NEU_REQ_UNSUBSCRIBE_GROUP:
|
||||
case NEU_REQ_UPDATE_GROUP:
|
||||
case NEU_REQ_DEL_GROUP:
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
#define MB 1000000
|
||||
|
||||
static inline int decode_b64_param(neu_plugin_t *plugin, neu_json_elem_t *el)
|
||||
int decode_b64_param(neu_plugin_t *plugin, neu_json_elem_t *el)
|
||||
{
|
||||
int len = 0;
|
||||
char *s = (char *) neu_decode64(&len, el->v.val_str);
|
||||
@@ -47,8 +47,8 @@ static inline int decode_b64_param(neu_plugin_t *plugin, neu_json_elem_t *el)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int parse_b64_param(neu_plugin_t *plugin, const char *setting,
|
||||
neu_json_elem_t *el)
|
||||
int parse_b64_param(neu_plugin_t *plugin, const char *setting,
|
||||
neu_json_elem_t *el)
|
||||
{
|
||||
if (0 != neu_parse_param(setting, NULL, 1, el)) {
|
||||
plog_error(plugin, "setting no %s", el->name);
|
||||
@@ -64,10 +64,10 @@ static inline int parse_b64_param(neu_plugin_t *plugin, const char *setting,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int parse_ssl_params(neu_plugin_t *plugin, const char *setting,
|
||||
neu_json_elem_t *ssl, neu_json_elem_t *ca,
|
||||
neu_json_elem_t *cert, neu_json_elem_t *key,
|
||||
neu_json_elem_t *keypass)
|
||||
static int parse_ssl_params(neu_plugin_t *plugin, const char *setting,
|
||||
neu_json_elem_t *ssl, neu_json_elem_t *ca,
|
||||
neu_json_elem_t *cert, neu_json_elem_t *key,
|
||||
neu_json_elem_t *keypass)
|
||||
{
|
||||
// ssl, optional
|
||||
int ret = neu_parse_param(setting, NULL, 1, ssl);
|
||||
|
||||
@@ -70,10 +70,10 @@ typedef struct {
|
||||
// for backward compatibility
|
||||
} mqtt_config_t;
|
||||
|
||||
int parse_ssl_params(neu_plugin_t *plugin, const char *setting,
|
||||
neu_json_elem_t *ssl, neu_json_elem_t *ca,
|
||||
neu_json_elem_t *cert, neu_json_elem_t *key,
|
||||
neu_json_elem_t *keypass);
|
||||
int decode_b64_param(neu_plugin_t *plugin, neu_json_elem_t *el);
|
||||
int parse_b64_param(neu_plugin_t *plugin, const char *setting,
|
||||
neu_json_elem_t *el);
|
||||
|
||||
int mqtt_config_parse(neu_plugin_t *plugin, const char *setting,
|
||||
mqtt_config_t *config);
|
||||
void mqtt_config_fini(mqtt_config_t *config);
|
||||
|
||||
Reference in New Issue
Block a user