Skip to content
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

Revert "core: update deployment api to v2" #70

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 17 additions & 33 deletions core/src/mender-api.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* @brief Paths of the mender-server APIs
*/
#define MENDER_API_PATH_POST_AUTHENTICATION_REQUESTS "/api/devices/v1/authentication/auth_requests"
#define MENDER_API_PATH_GET_NEXT_DEPLOYMENT "/api/devices/v2/deployments/device/deployments/next"
#define MENDER_API_PATH_GET_NEXT_DEPLOYMENT "/api/devices/v1/deployments/device/deployments/next"
#define MENDER_API_PATH_PUT_DEPLOYMENT_STATUS "/api/devices/v1/deployments/device/deployments/%s/status"
#define MENDER_API_PATH_GET_DEVICE_CONFIGURATION "/api/devices/v1/deviceconfig/configuration"
#define MENDER_API_PATH_PUT_DEVICE_CONFIGURATION "/api/devices/v1/deviceconfig/configuration"
Expand Down Expand Up @@ -250,41 +250,28 @@ mender_api_check_for_deployment(char **id, char **artifact_name, char **uri) {
assert(NULL != artifact_name);
assert(NULL != uri);
mender_err_t ret;
cJSON * json_payload = NULL;
char * payload = NULL;
char * response = NULL;
int status = 0;
char * path = NULL;
char * response = NULL;
int status = 0;

/* Format payload */
if (NULL == (json_payload = cJSON_CreateObject())) {
mender_log_error("Unable to allocate memory");
ret = MENDER_FAIL;
goto END;
}
cJSON *json_device_provides = cJSON_AddObjectToObject(json_payload, "device_provides");
if (NULL == json_device_provides) {
mender_log_error("Unable to allocate memory");
ret = MENDER_FAIL;
goto END;
}
cJSON_AddStringToObject(json_device_provides, "device_type", mender_api_config.device_type);
cJSON_AddStringToObject(json_device_provides, "artifact_name", mender_api_config.artifact_name);
if (NULL == (payload = cJSON_PrintUnformatted(json_payload))) {
/* Compute path */
size_t str_length = strlen("?artifact_name=&device_type=") + strlen(MENDER_API_PATH_GET_NEXT_DEPLOYMENT) + strlen(mender_api_config.artifact_name)
+ strlen(mender_api_config.device_type) + 1;
if (NULL == (path = (char *)malloc(str_length))) {
mender_log_error("Unable to allocate memory");
ret = MENDER_FAIL;
goto END;
}
snprintf(path,
str_length,
"%s?artifact_name=%s&device_type=%s",
MENDER_API_PATH_GET_NEXT_DEPLOYMENT,
mender_api_config.artifact_name,
mender_api_config.device_type);

/* Perform HTTP request */
if (MENDER_OK
!= (ret = mender_http_perform(mender_api_jwt,
MENDER_API_PATH_GET_NEXT_DEPLOYMENT,
MENDER_HTTP_POST,
payload,
NULL,
&mender_api_http_text_callback,
(void *)&response,
&status))) {
!= (ret = mender_http_perform(mender_api_jwt, path, MENDER_HTTP_GET, NULL, NULL, &mender_api_http_text_callback, (void *)&response, &status))) {
mender_log_error("Unable to perform HTTP request");
goto END;
}
Expand Down Expand Up @@ -349,11 +336,8 @@ mender_api_check_for_deployment(char **id, char **artifact_name, char **uri) {
if (NULL != response) {
free(response);
}
if (NULL != payload) {
free(payload);
}
if (NULL != json_payload) {
cJSON_Delete(json_payload);
if (NULL != path) {
free(path);
}

return ret;
Expand Down
Loading