Blame SOURCES/0032-TCURL-Support-HTTP-POST-for-creating-containers.patch

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