-
Notifications
You must be signed in to change notification settings - Fork 915
Ensure plugin path handled prior to plugin configs #404
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1529,8 +1529,10 @@ rd_kafka_conf_t *common_conf_setup (rd_kafka_type_t ktype, | |
* When both args and kwargs are present the kwargs take | ||
* precedence in case of duplicate keys. | ||
* All keys map to configuration properties. | ||
* | ||
* Copy configuration dict to avoid manipulating application config. | ||
*/ | ||
if (args) { | ||
if (args && PyTuple_Size(args)) { | ||
if (!PyTuple_Check(args) || | ||
PyTuple_Size(args) > 1) { | ||
PyErr_SetString(PyExc_TypeError, | ||
|
@@ -1542,6 +1544,7 @@ rd_kafka_conf_t *common_conf_setup (rd_kafka_type_t ktype, | |
"expected configuration dict"); | ||
return NULL; | ||
} | ||
confdict = PyDict_Copy(confdict); | ||
} | ||
|
||
if (!confdict) { | ||
|
@@ -1551,7 +1554,7 @@ rd_kafka_conf_t *common_conf_setup (rd_kafka_type_t ktype, | |
return NULL; | ||
} | ||
|
||
confdict = kwargs; | ||
confdict = PyDict_Copy(kwargs); | ||
|
||
} else if (kwargs) { | ||
/* Update confdict with kwargs */ | ||
|
@@ -1568,6 +1571,50 @@ rd_kafka_conf_t *common_conf_setup (rd_kafka_type_t ktype, | |
/* Enable valid offsets in delivery reports */ | ||
rd_kafka_topic_conf_set(tconf, "produce.offset.report", "true", NULL, 0); | ||
|
||
/* | ||
* Plugins must be configured prior to handling any of their configuration properties. | ||
* Dicts are unordered so we explicitly check for, set, and delete the plugin paths here. | ||
* This ensures plugin configuration properties are handled in the correct order. | ||
*/ | ||
if ((vo = PyDict_GetItemString(confdict, "plugin.library.paths"))) { | ||
const char *v; | ||
char errstr[256]; | ||
PyObject *vs = NULL, *vs8 = NULL; | ||
|
||
if (!(vs = cfl_PyObject_Unistr(vo))) { | ||
PyErr_SetString(PyExc_TypeError, | ||
"expected configuration property name " | ||
"as type unicode string"); | ||
rd_kafka_topic_conf_destroy(tconf); | ||
rd_kafka_conf_destroy(conf); | ||
Py_DECREF(confdict); | ||
|
||
return NULL; | ||
} | ||
|
||
v = cfl_PyUnistr_AsUTF8(vs, &vs8); | ||
|
||
if (rd_kafka_conf_set(conf, "plugin.library.paths", v, errstr, sizeof(errstr)) | ||
!= RD_KAFKA_CONF_OK) { | ||
cfl_PyErr_Format(RD_KAFKA_RESP_ERR__INVALID_ARG, | ||
"%s", errstr); | ||
|
||
rd_kafka_topic_conf_destroy(tconf); | ||
rd_kafka_conf_destroy(conf); | ||
Py_DECREF(confdict); | ||
|
||
Py_XDECREF(vs8); | ||
Py_XDECREF(vs); | ||
|
||
return NULL; | ||
} | ||
|
||
Py_XDECREF(vs8); | ||
Py_DECREF(vs); | ||
|
||
PyDict_DelItemString(confdict, "plugin.library.paths"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ooh, come to think of it, we shouldnt mutate the passed dict. |
||
} | ||
|
||
/* Convert config dict to config key-value pairs. */ | ||
while (PyDict_Next(confdict, &pos, &ko, &vo)) { | ||
PyObject *ks, *ks8; | ||
|
@@ -1583,6 +1630,8 @@ rd_kafka_conf_t *common_conf_setup (rd_kafka_type_t ktype, | |
"as type unicode string"); | ||
rd_kafka_topic_conf_destroy(tconf); | ||
rd_kafka_conf_destroy(conf); | ||
Py_DECREF(confdict); | ||
|
||
return NULL; | ||
} | ||
|
||
|
@@ -1592,6 +1641,7 @@ rd_kafka_conf_t *common_conf_setup (rd_kafka_type_t ktype, | |
Py_DECREF(ks); | ||
rd_kafka_topic_conf_destroy(tconf); | ||
rd_kafka_conf_destroy(conf); | ||
Py_DECREF(confdict); | ||
return NULL; | ||
} | ||
Py_XDECREF(ks8); | ||
|
@@ -1605,8 +1655,11 @@ rd_kafka_conf_t *common_conf_setup (rd_kafka_type_t ktype, | |
"as a callable function"); | ||
rd_kafka_topic_conf_destroy(tconf); | ||
rd_kafka_conf_destroy(conf); | ||
Py_DECREF(confdict); | ||
|
||
Py_XDECREF(ks8); | ||
Py_DECREF(ks); | ||
|
||
return NULL; | ||
} | ||
if (h->error_cb) { | ||
|
@@ -1627,8 +1680,11 @@ rd_kafka_conf_t *common_conf_setup (rd_kafka_type_t ktype, | |
"as a callable function"); | ||
rd_kafka_topic_conf_destroy(tconf); | ||
rd_kafka_conf_destroy(conf); | ||
Py_DECREF(confdict); | ||
|
||
Py_XDECREF(ks8); | ||
Py_DECREF(ks); | ||
|
||
return NULL; | ||
} | ||
if (h->throttle_cb) { | ||
|
@@ -1649,8 +1705,11 @@ rd_kafka_conf_t *common_conf_setup (rd_kafka_type_t ktype, | |
"as a callable function"); | ||
rd_kafka_topic_conf_destroy(tconf); | ||
rd_kafka_conf_destroy(conf); | ||
Py_DECREF(confdict); | ||
|
||
Py_XDECREF(ks8); | ||
Py_DECREF(ks); | ||
|
||
return NULL; | ||
} | ||
|
||
|
@@ -1691,6 +1750,8 @@ rd_kafka_conf_t *common_conf_setup (rd_kafka_type_t ktype, | |
Py_DECREF(ks); | ||
rd_kafka_topic_conf_destroy(tconf); | ||
rd_kafka_conf_destroy(conf); | ||
Py_DECREF(confdict); | ||
|
||
return NULL; | ||
|
||
} else if (r == 1) { | ||
|
@@ -1712,8 +1773,11 @@ rd_kafka_conf_t *common_conf_setup (rd_kafka_type_t ktype, | |
"unicode string"); | ||
rd_kafka_topic_conf_destroy(tconf); | ||
rd_kafka_conf_destroy(conf); | ||
Py_DECREF(confdict); | ||
|
||
Py_XDECREF(ks8); | ||
Py_DECREF(ks); | ||
|
||
return NULL; | ||
} | ||
v = cfl_PyUnistr_AsUTF8(vs, &vs8); | ||
|
@@ -1725,10 +1789,13 @@ rd_kafka_conf_t *common_conf_setup (rd_kafka_type_t ktype, | |
"%s", errstr); | ||
rd_kafka_topic_conf_destroy(tconf); | ||
rd_kafka_conf_destroy(conf); | ||
Py_DECREF(confdict); | ||
|
||
Py_XDECREF(vs8); | ||
Py_XDECREF(vs); | ||
Py_XDECREF(ks8); | ||
Py_DECREF(ks); | ||
|
||
return NULL; | ||
} | ||
|
||
|
@@ -1738,6 +1805,8 @@ rd_kafka_conf_t *common_conf_setup (rd_kafka_type_t ktype, | |
Py_DECREF(ks); | ||
} | ||
|
||
Py_DECREF(confdict); | ||
|
||
if (h->error_cb) | ||
rd_kafka_conf_set_error_cb(conf, error_cb); | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dito
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also check the other returns below