From b31caa6d6ae9f564d432a8a97ee54fc9ca286c63 Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Mon, 27 Feb 2023 00:13:31 +0100 Subject: [PATCH] cloud-setup: make nm_http_client_req() accept a method argument We'll need to be able to issue PUT calls. Conflicts: code formatting, missing nmcs-provider-aliyun and azure, missing commit 494819bbbf ("cloud-setup: move common code for get_config() to base class and improve cancellation") (cherry picked from commit cd74d75002783a79d1a4fca24b2fbe99ced933a8) (cherry picked from commit eff4372045290ad380bddf03e5075ab671a7cff6) (cherry picked from commit aaf66e9174eb04d2df1f45530ebdca16e77a6ec5) (cherry picked from commit 3d94f4fdf9f7f1fef6e8ec77593e4d3506d144df) (cherry picked from commit 181466c6dae4251f49596afb7abfc291b9769769) (cherry picked from commit 7243307bb8e4369aef8b0a68d64c2a05c47b0d8a) (cherry picked from commit 1aa88024cbf4720badb7b015c1f3a9be989eab70) (cherry picked from commit 59b5a8fdcb8c1dd33f9fd43ee9492aeaf8b1c186) (cherry picked from commit 0962b6e23da502827c3244c84b5c5aa371907e17) --- clients/cloud-setup/nm-http-client.c | 7 +++++++ clients/cloud-setup/nm-http-client.h | 1 + clients/cloud-setup/nmcs-provider-ec2.c | 4 ++++ clients/cloud-setup/nmcs-provider-gcp.c | 5 +++++ 4 files changed, 17 insertions(+) diff --git a/clients/cloud-setup/nm-http-client.c b/clients/cloud-setup/nm-http-client.c index 689a8fc400..d9dab96684 100644 --- a/clients/cloud-setup/nm-http-client.c +++ b/clients/cloud-setup/nm-http-client.c @@ -264,6 +264,7 @@ nm_http_client_req (NMHttpClient *self, int timeout_msec, gssize max_data, const char *const *http_headers, + const char * http_method, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) @@ -325,6 +326,9 @@ nm_http_client_req (NMHttpClient *self, curl_easy_setopt (edata->ehandle, CURLOPT_HTTPHEADER, edata->headers); } + if (http_method) + curl_easy_setopt(edata->ehandle, CURLOPT_CUSTOMREQUEST, http_method); + if (timeout_msec > 0) { edata->timeout_source = _source_attach (self, nm_g_timeout_source_new (timeout_msec, @@ -386,6 +390,7 @@ typedef struct { GTask *task; char *uri; const char *const *http_headers; + const char *http_method; NMHttpClientPollReqCheckFcn check_fcn; gpointer check_user_data; GBytes *response_data; @@ -423,6 +428,7 @@ _poll_req_probe_start_fcn (GCancellable *cancellable, poll_req_data->request_timeout_ms, poll_req_data->request_max_data, poll_req_data->http_headers, + poll_req_data->http_method, cancellable, callback, user_data); @@ -503,6 +509,7 @@ nm_http_client_poll_req (NMHttpClient *self, int poll_timeout_ms, int ratelimit_timeout_ms, const char *const *http_headers, + const char *http_method, GCancellable *cancellable, NMHttpClientPollReqCheckFcn check_fcn, gpointer check_user_data, diff --git a/clients/cloud-setup/nm-http-client.h b/clients/cloud-setup/nm-http-client.h index eeca3930d2..6f5338fd86 100644 --- a/clients/cloud-setup/nm-http-client.h +++ b/clients/cloud-setup/nm-http-client.h @@ -37,6 +37,7 @@ void nm_http_client_poll_req (NMHttpClient *self, int poll_timeout_ms, int ratelimit_timeout_ms, const char *const *http_headers, + const char *http_method, GCancellable *cancellable, NMHttpClientPollReqCheckFcn check_fcn, gpointer check_user_data, diff --git a/clients/cloud-setup/nmcs-provider-ec2.c b/clients/cloud-setup/nmcs-provider-ec2.c index 8d828f0241..eb2812b341 100644 --- a/clients/cloud-setup/nmcs-provider-ec2.c +++ b/clients/cloud-setup/nmcs-provider-ec2.c @@ -139,6 +139,7 @@ detect (NMCSProvider *provider, 7000, 1000, NULL, + NULL, g_task_get_cancellable (task), _detect_get_meta_data_check_cb, NULL, @@ -398,6 +399,7 @@ _get_config_metadata_ready_cb (GObject *source, 10000, 1000, NULL, + NULL, iface_data->cancellable, NULL, NULL, @@ -416,6 +418,7 @@ _get_config_metadata_ready_cb (GObject *source, 10000, 1000, NULL, + NULL, iface_data->cancellable, NULL, NULL, @@ -533,6 +536,7 @@ get_config (NMCSProvider *provider, 15000, 1000, NULL, + NULL, g_task_get_cancellable (get_config_data->task), _get_config_metadata_ready_check, metadata_data, diff --git a/clients/cloud-setup/nmcs-provider-gcp.c b/clients/cloud-setup/nmcs-provider-gcp.c index 9b98b33540..13f4af6a00 100644 --- a/clients/cloud-setup/nmcs-provider-gcp.c +++ b/clients/cloud-setup/nmcs-provider-gcp.c @@ -95,6 +95,7 @@ detect (NMCSProvider *provider, 7000, 1000, NM_MAKE_STRV (NM_GCP_METADATA_HEADER), + NULL, g_task_get_cancellable (task), NULL, NULL, @@ -297,6 +298,7 @@ _get_config_ips_list_cb (GObject *source, HTTP_POLL_TIMEOUT_MS, HTTP_RATE_LIMIT_MS, NM_MAKE_STRV (NM_GCP_METADATA_HEADER), + NULL, g_task_get_cancellable (gcp_data->config_data->task), NULL, NULL, @@ -360,6 +362,7 @@ _get_config_iface_cb (GObject *source, HTTP_POLL_TIMEOUT_MS, HTTP_RATE_LIMIT_MS, NM_MAKE_STRV (NM_GCP_METADATA_HEADER), + NULL, g_task_get_cancellable (gcp_data->config_data->task), NULL, NULL, @@ -455,6 +458,7 @@ _get_net_ifaces_list_cb (GObject *source, HTTP_POLL_TIMEOUT_MS, HTTP_RATE_LIMIT_MS, NM_MAKE_STRV (NM_GCP_METADATA_HEADER), + NULL, g_task_get_cancellable (gcp_data->config_data->task), NULL, NULL, @@ -494,6 +498,7 @@ get_config (NMCSProvider *provider, HTTP_POLL_TIMEOUT_MS, HTTP_RATE_LIMIT_MS, NM_MAKE_STRV (NM_GCP_METADATA_HEADER), + NULL, g_task_get_cancellable (gcp_data->config_data->task), NULL, NULL,