Make REST POST request timeout configurable
This commit is contained in:
@@ -213,9 +213,10 @@ static TNC_Result receive_msg(private_imv_swid_agent_t *this,
|
|||||||
inventory = attr_cast->get_inventory(attr_cast);
|
inventory = attr_cast->get_inventory(attr_cast);
|
||||||
tag_id_count = inventory->get_count(inventory);
|
tag_id_count = inventory->get_count(inventory);
|
||||||
|
|
||||||
DBG2(DBG_IMV, "received SWID tag ID inventory with %d items "
|
DBG2(DBG_IMV, "received SWID tag ID inventory with %d item%s "
|
||||||
"for request %d at eid %d of epoch 0x%08x",
|
"for request %d at eid %d of epoch 0x%08x",
|
||||||
tag_id_count, request_id, last_eid, eid_epoch);
|
tag_id_count, (tag_id_count == 1) ? "" : "s",
|
||||||
|
request_id, last_eid, eid_epoch);
|
||||||
|
|
||||||
if (request_id == swid_state->get_request_id(swid_state))
|
if (request_id == swid_state->get_request_id(swid_state))
|
||||||
{
|
{
|
||||||
@@ -247,9 +248,10 @@ static TNC_Result receive_msg(private_imv_swid_agent_t *this,
|
|||||||
inventory = attr_cast->get_inventory(attr_cast);
|
inventory = attr_cast->get_inventory(attr_cast);
|
||||||
tag_count = inventory->get_count(inventory);
|
tag_count = inventory->get_count(inventory);
|
||||||
|
|
||||||
DBG2(DBG_IMV, "received SWID tag inventory with %d items for "
|
DBG2(DBG_IMV, "received SWID tag inventory with %d item%s for "
|
||||||
"request %d at eid %d of epoch 0x%08x",
|
"request %d at eid %d of epoch 0x%08x",
|
||||||
tag_count, request_id, last_eid, eid_epoch);
|
tag_count, (tag_count == 1) ? "" : "s",
|
||||||
|
request_id, last_eid, eid_epoch);
|
||||||
|
|
||||||
|
|
||||||
if (request_id == swid_state->get_request_id(swid_state))
|
if (request_id == swid_state->get_request_id(swid_state))
|
||||||
@@ -474,7 +476,7 @@ METHOD(imv_agent_if_t, batch_ending, TNC_Result,
|
|||||||
swid_tag_id_t *tag_id;
|
swid_tag_id_t *tag_id;
|
||||||
status_t status = SUCCESS;
|
status_t status = SUCCESS;
|
||||||
|
|
||||||
if (this->rest_api)
|
if (this->rest_api && (received & IMV_SWID_ATTR_TAG_ID_INV))
|
||||||
{
|
{
|
||||||
if (asprintf(&command, "sessions/%d/swid_measurement/",
|
if (asprintf(&command, "sessions/%d/swid_measurement/",
|
||||||
session->get_session_id(session, NULL, NULL)) < 0)
|
session->get_session_id(session, NULL, NULL)) < 0)
|
||||||
@@ -547,7 +549,8 @@ METHOD(imv_agent_if_t, batch_ending, TNC_Result,
|
|||||||
swid_state->get_request_id(swid_state), 0);
|
swid_state->get_request_id(swid_state), 0);
|
||||||
|
|
||||||
tag_id_count = json_object_array_length(jresponse);
|
tag_id_count = json_object_array_length(jresponse);
|
||||||
DBG1(DBG_IMV, "%d SWID tag targets", tag_id_count);
|
DBG1(DBG_IMV, "%d SWID tag target%s", tag_id_count,
|
||||||
|
(tag_id_count == 1) ? "" : "s");
|
||||||
|
|
||||||
for (i = 0; i < tag_id_count; i++)
|
for (i = 0; i < tag_id_count; i++)
|
||||||
{
|
{
|
||||||
@@ -675,6 +678,7 @@ imv_agent_if_t *imv_swid_agent_create(const char *name, TNC_IMVID id,
|
|||||||
private_imv_swid_agent_t *this;
|
private_imv_swid_agent_t *this;
|
||||||
imv_agent_t *agent;
|
imv_agent_t *agent;
|
||||||
char *rest_api_uri;
|
char *rest_api_uri;
|
||||||
|
u_int rest_api_timeout;
|
||||||
|
|
||||||
agent = imv_agent_create(name, msg_types, countof(msg_types), id,
|
agent = imv_agent_create(name, msg_types, countof(msg_types), id,
|
||||||
actual_version);
|
actual_version);
|
||||||
@@ -698,9 +702,11 @@ imv_agent_if_t *imv_swid_agent_create(const char *name, TNC_IMVID id,
|
|||||||
|
|
||||||
rest_api_uri = lib->settings->get_str(lib->settings,
|
rest_api_uri = lib->settings->get_str(lib->settings,
|
||||||
"%s.plugins.imv-swid.rest_api_uri", NULL, lib->ns);
|
"%s.plugins.imv-swid.rest_api_uri", NULL, lib->ns);
|
||||||
|
rest_api_timeout = lib->settings->get_int(lib->settings,
|
||||||
|
"%s.plugins.imv-swid.rest_api_timeout", 120, lib->ns);
|
||||||
if (rest_api_uri)
|
if (rest_api_uri)
|
||||||
{
|
{
|
||||||
this->rest_api = imv_swid_rest_create(rest_api_uri);
|
this->rest_api = imv_swid_rest_create(rest_api_uri, rest_api_timeout);
|
||||||
}
|
}
|
||||||
libpts_init();
|
libpts_init();
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,11 @@ struct private_imv_swid_rest_t {
|
|||||||
*/
|
*/
|
||||||
char *uri;
|
char *uri;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Timeout of REST API connection
|
||||||
|
*/
|
||||||
|
u_int timeout;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define HTTP_STATUS_CODE_PRECONDITION_FAILED 412
|
#define HTTP_STATUS_CODE_PRECONDITION_FAILED 412
|
||||||
@@ -45,7 +50,6 @@ METHOD(imv_swid_rest_t, post, status_t,
|
|||||||
{
|
{
|
||||||
struct json_tokener *tokener;
|
struct json_tokener *tokener;
|
||||||
chunk_t data, response = chunk_empty;
|
chunk_t data, response = chunk_empty;
|
||||||
u_int timeout = 30;
|
|
||||||
status_t status;
|
status_t status;
|
||||||
char *uri;
|
char *uri;
|
||||||
int code;
|
int code;
|
||||||
@@ -57,7 +61,7 @@ METHOD(imv_swid_rest_t, post, status_t,
|
|||||||
data = chunk_from_str(json_object_to_json_string(jrequest));
|
data = chunk_from_str(json_object_to_json_string(jrequest));
|
||||||
|
|
||||||
status = lib->fetcher->fetch(lib->fetcher, uri, &response,
|
status = lib->fetcher->fetch(lib->fetcher, uri, &response,
|
||||||
FETCH_TIMEOUT, timeout,
|
FETCH_TIMEOUT, this->timeout,
|
||||||
FETCH_REQUEST_DATA, data,
|
FETCH_REQUEST_DATA, data,
|
||||||
FETCH_REQUEST_TYPE, "application/json; charset=utf-8",
|
FETCH_REQUEST_TYPE, "application/json; charset=utf-8",
|
||||||
FETCH_REQUEST_HEADER, "Accept: application/json",
|
FETCH_REQUEST_HEADER, "Accept: application/json",
|
||||||
@@ -70,8 +74,10 @@ METHOD(imv_swid_rest_t, post, status_t,
|
|||||||
{
|
{
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (code != HTTP_STATUS_CODE_PRECONDITION_FAILED || !response.ptr)
|
if (code != HTTP_STATUS_CODE_PRECONDITION_FAILED || !response.ptr)
|
||||||
{
|
{
|
||||||
|
DBG2(DBG_IMV, "REST http request failed with status code: %d", code);
|
||||||
return FAILED;
|
return FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,7 +103,7 @@ METHOD(imv_swid_rest_t, destroy, void,
|
|||||||
/**
|
/**
|
||||||
* Described in header.
|
* Described in header.
|
||||||
*/
|
*/
|
||||||
imv_swid_rest_t *imv_swid_rest_create(char *uri)
|
imv_swid_rest_t *imv_swid_rest_create(char *uri, u_int timeout)
|
||||||
{
|
{
|
||||||
private_imv_swid_rest_t *this;
|
private_imv_swid_rest_t *this;
|
||||||
|
|
||||||
@@ -107,6 +113,7 @@ imv_swid_rest_t *imv_swid_rest_create(char *uri)
|
|||||||
.destroy = _destroy,
|
.destroy = _destroy,
|
||||||
},
|
},
|
||||||
.uri = strdup(uri),
|
.uri = strdup(uri),
|
||||||
|
.timeout = timeout,
|
||||||
);
|
);
|
||||||
|
|
||||||
return &this->public;
|
return &this->public;
|
||||||
|
|||||||
@@ -56,7 +56,8 @@ struct imv_swid_rest_t {
|
|||||||
* Create an imv_swid_rest_t instance
|
* Create an imv_swid_rest_t instance
|
||||||
*
|
*
|
||||||
* @param uri REST URI (http://username:password@hostname[:port]/api/)
|
* @param uri REST URI (http://username:password@hostname[:port]/api/)
|
||||||
|
* @param timeout Timeout of the REST connection
|
||||||
*/
|
*/
|
||||||
imv_swid_rest_t* imv_swid_rest_create(char *uri);
|
imv_swid_rest_t* imv_swid_rest_create(char *uri, u_int timeout);
|
||||||
|
|
||||||
#endif /** IMV_SWID_REST_H_ @}*/
|
#endif /** IMV_SWID_REST_H_ @}*/
|
||||||
|
|||||||
Reference in New Issue
Block a user