|
|
bb7cd1 |
From 2777ccdcc9038d8f62be81a24ae885639fe6ea9a Mon Sep 17 00:00:00 2001
|
|
|
bb7cd1 |
From: Jakub Hrozek <jhrozek@redhat.com>
|
|
|
bb7cd1 |
Date: Tue, 14 Mar 2017 15:34:57 +0100
|
|
|
bb7cd1 |
Subject: [PATCH 32/36] TCURL: Support HTTP POST for creating containers
|
|
|
bb7cd1 |
MIME-Version: 1.0
|
|
|
bb7cd1 |
Content-Type: text/plain; charset=UTF-8
|
|
|
bb7cd1 |
Content-Transfer-Encoding: 8bit
|
|
|
bb7cd1 |
|
|
|
bb7cd1 |
The curl integration must allow us to create containers, therefore we
|
|
|
bb7cd1 |
also add support of the POST HTTP request type.
|
|
|
bb7cd1 |
|
|
|
bb7cd1 |
Reviewed-by: Michal Židek <mzidek@redhat.com>
|
|
|
bb7cd1 |
Reviewed-by: Simo Sorce <simo@redhat.com>
|
|
|
bb7cd1 |
---
|
|
|
bb7cd1 |
src/tests/intg/test_secrets.py | 28 ++++++++++++++++++++++++++++
|
|
|
bb7cd1 |
src/tests/tcurl_test_tool.c | 5 +++++
|
|
|
bb7cd1 |
src/util/tev_curl.c | 7 +++++++
|
|
|
bb7cd1 |
src/util/tev_curl.h | 1 +
|
|
|
bb7cd1 |
4 files changed, 41 insertions(+)
|
|
|
bb7cd1 |
|
|
|
bb7cd1 |
diff --git a/src/tests/intg/test_secrets.py b/src/tests/intg/test_secrets.py
|
|
|
bb7cd1 |
index cbc1a1f06d2abb826bc0a880cb5a842f577657ea..d71c1904558cc6f8a6eee36c4049582705bc30ac 100644
|
|
|
bb7cd1 |
--- a/src/tests/intg/test_secrets.py
|
|
|
bb7cd1 |
+++ b/src/tests/intg/test_secrets.py
|
|
|
bb7cd1 |
@@ -271,6 +271,34 @@ def test_curlwrap_crd_ops(setup_for_secrets,
|
|
|
bb7cd1 |
'http://localhost/secrets/foo'],
|
|
|
bb7cd1 |
404)
|
|
|
bb7cd1 |
|
|
|
bb7cd1 |
+ # Create a container
|
|
|
bb7cd1 |
+ run_curlwrap_tool([curlwrap_tool, '-o',
|
|
|
bb7cd1 |
+ '-v', '-s', sock_path,
|
|
|
bb7cd1 |
+ 'http://localhost/secrets/cont/'],
|
|
|
bb7cd1 |
+ 200)
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+ # set a secret foo:bar
|
|
|
bb7cd1 |
+ run_curlwrap_tool([curlwrap_tool, '-p',
|
|
|
bb7cd1 |
+ '-v', '-s', sock_path,
|
|
|
bb7cd1 |
+ 'http://localhost/secrets/cont/cfoo',
|
|
|
bb7cd1 |
+ 'foo_under_cont'],
|
|
|
bb7cd1 |
+ 200)
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+ # list secrets
|
|
|
bb7cd1 |
+ output = run_curlwrap_tool([curlwrap_tool,
|
|
|
bb7cd1 |
+ '-v', '-s', sock_path,
|
|
|
bb7cd1 |
+ 'http://localhost/secrets/cont/'],
|
|
|
bb7cd1 |
+ 200)
|
|
|
bb7cd1 |
+ assert "cfoo" in output
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+ # get the foo secret
|
|
|
bb7cd1 |
+ output = run_curlwrap_tool([curlwrap_tool,
|
|
|
bb7cd1 |
+ '-v', '-s', sock_path,
|
|
|
bb7cd1 |
+ 'http://localhost/secrets/cont/cfoo'],
|
|
|
bb7cd1 |
+ 200)
|
|
|
bb7cd1 |
+ assert "foo_under_cont" in output
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
|
|
|
bb7cd1 |
def test_curlwrap_parallel(setup_for_secrets,
|
|
|
bb7cd1 |
curlwrap_tool):
|
|
|
bb7cd1 |
diff --git a/src/tests/tcurl_test_tool.c b/src/tests/tcurl_test_tool.c
|
|
|
bb7cd1 |
index 38cea432885c97ca3827c8f158bf7e3ebfc67b31..2af950ebb76a22bdf4a6dfd58442b10486e64293 100644
|
|
|
bb7cd1 |
--- a/src/tests/tcurl_test_tool.c
|
|
|
bb7cd1 |
+++ b/src/tests/tcurl_test_tool.c
|
|
|
bb7cd1 |
@@ -88,6 +88,7 @@ int main(int argc, const char *argv[])
|
|
|
bb7cd1 |
{ "get", 'g', POPT_ARG_NONE, NULL, 'g', "Perform a HTTP GET (default)", NULL },
|
|
|
bb7cd1 |
{ "put", 'p', POPT_ARG_NONE, NULL, 'p', "Perform a HTTP PUT", NULL },
|
|
|
bb7cd1 |
{ "del", 'd', POPT_ARG_NONE, NULL, 'd', "Perform a HTTP DELETE", NULL },
|
|
|
bb7cd1 |
+ { "post", 'o', POPT_ARG_NONE, NULL, 'o', "Perform a HTTP POST", NULL },
|
|
|
bb7cd1 |
{ "verbose", 'v', POPT_ARG_NONE, NULL, 'v', "Print response code and body", NULL },
|
|
|
bb7cd1 |
POPT_TABLEEND
|
|
|
bb7cd1 |
};
|
|
|
bb7cd1 |
@@ -118,6 +119,9 @@ int main(int argc, const char *argv[])
|
|
|
bb7cd1 |
case 'd':
|
|
|
bb7cd1 |
req_type = TCURL_HTTP_DELETE;
|
|
|
bb7cd1 |
break;
|
|
|
bb7cd1 |
+ case 'o':
|
|
|
bb7cd1 |
+ req_type = TCURL_HTTP_POST;
|
|
|
bb7cd1 |
+ break;
|
|
|
bb7cd1 |
case 'v':
|
|
|
bb7cd1 |
pc_verbose = 1;
|
|
|
bb7cd1 |
break;
|
|
|
bb7cd1 |
@@ -145,6 +149,7 @@ int main(int argc, const char *argv[])
|
|
|
bb7cd1 |
switch (req_type) {
|
|
|
bb7cd1 |
case TCURL_HTTP_GET:
|
|
|
bb7cd1 |
case TCURL_HTTP_DELETE:
|
|
|
bb7cd1 |
+ case TCURL_HTTP_POST:
|
|
|
bb7cd1 |
urls[n_reqs++] = extra_arg_ptr;
|
|
|
bb7cd1 |
break;
|
|
|
bb7cd1 |
case TCURL_HTTP_PUT:
|
|
|
bb7cd1 |
diff --git a/src/util/tev_curl.c b/src/util/tev_curl.c
|
|
|
bb7cd1 |
index fd436653b5aeb611a9648a8b81a330fd3fcfe875..645d1182d10f825f209f48e0ba7e6804dde1971c 100644
|
|
|
bb7cd1 |
--- a/src/util/tev_curl.c
|
|
|
bb7cd1 |
+++ b/src/util/tev_curl.c
|
|
|
bb7cd1 |
@@ -154,6 +154,8 @@ static const char *http_req2str(enum tcurl_http_request req)
|
|
|
bb7cd1 |
return "PUT";
|
|
|
bb7cd1 |
case TCURL_HTTP_DELETE:
|
|
|
bb7cd1 |
return "DELETE";
|
|
|
bb7cd1 |
+ case TCURL_HTTP_POST:
|
|
|
bb7cd1 |
+ return "POST";
|
|
|
bb7cd1 |
}
|
|
|
bb7cd1 |
|
|
|
bb7cd1 |
return "Uknown request type";
|
|
|
bb7cd1 |
@@ -815,6 +817,11 @@ static errno_t tcurl_set_options(struct tcurl_http_state *state,
|
|
|
bb7cd1 |
}
|
|
|
bb7cd1 |
|
|
|
bb7cd1 |
switch (req_type) {
|
|
|
bb7cd1 |
+ case TCURL_HTTP_POST:
|
|
|
bb7cd1 |
+ crv = curl_easy_setopt(state->http_handle,
|
|
|
bb7cd1 |
+ CURLOPT_CUSTOMREQUEST,
|
|
|
bb7cd1 |
+ "POST");
|
|
|
bb7cd1 |
+ break;
|
|
|
bb7cd1 |
case TCURL_HTTP_PUT:
|
|
|
bb7cd1 |
/* CURLOPT_UPLOAD enables HTTP_PUT */
|
|
|
bb7cd1 |
crv = curl_easy_setopt(state->http_handle,
|
|
|
bb7cd1 |
diff --git a/src/util/tev_curl.h b/src/util/tev_curl.h
|
|
|
bb7cd1 |
index de0601df4327d97001a8a825cd4709936f6c8466..444eb286e09d189b4588e2b2152b5202df3914d8 100644
|
|
|
bb7cd1 |
--- a/src/util/tev_curl.h
|
|
|
bb7cd1 |
+++ b/src/util/tev_curl.h
|
|
|
bb7cd1 |
@@ -34,6 +34,7 @@ enum tcurl_http_request {
|
|
|
bb7cd1 |
TCURL_HTTP_GET,
|
|
|
bb7cd1 |
TCURL_HTTP_PUT,
|
|
|
bb7cd1 |
TCURL_HTTP_DELETE,
|
|
|
bb7cd1 |
+ TCURL_HTTP_POST,
|
|
|
bb7cd1 |
};
|
|
|
bb7cd1 |
|
|
|
bb7cd1 |
/**
|
|
|
bb7cd1 |
--
|
|
|
bb7cd1 |
2.9.3
|
|
|
bb7cd1 |
|