summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames E. Blair <jeblair@redhat.com>2019-02-09 12:53:17 -0800
committerJames E. Blair <jeblair@redhat.com>2019-02-09 12:53:17 -0800
commit5105fe9e964a20aae458b7325686147abc725f67 (patch)
treeda0953cd047f8dc73a0fa3815b63b5190b350582
parent00a92c15c869a5e43c1e941a653d1793285c7ad1 (diff)
Read a hostname in a loop
-rw-r--r--zuul-preview/main.cc61
1 files changed, 47 insertions, 14 deletions
diff --git a/zuul-preview/main.cc b/zuul-preview/main.cc
index 70df06e..6d24165 100644
--- a/zuul-preview/main.cc
+++ b/zuul-preview/main.cc
@@ -23,21 +23,54 @@
23 23
24using namespace std; 24using namespace std;
25 25
26vector<string> split(string in);
27
28vector<string> split(string in)
29{
30 istringstream stream(in);
31 vector<string> parts;
32 string part;
33 while (getline(stream, part, '.')) {
34 parts.push_back(part);
35 }
36 return parts;
37}
38
26int main(int, char**) 39int main(int, char**)
27{ 40{
28 web::http::client::http_client client("https://zuul.opendev.org"); 41 web::http::client::http_client client("https://zuul.opendev.org");
29 auto uri = web::uri_builder("/api/tenant/openstack/build"); 42
30 uri.append_path("75031cad206c4014ad7a3387091d15ab"); 43 string hostname;
31 auto response = client.request( 44 while (getline(cin, hostname)) {
32 web::http::methods::GET, uri.to_string()).get(); 45 // Expected hostname:
33 // body is a web::json::value 46 // site.75031cad206c4014ad7a3387091d15ab.openstack.preview.opendev.org
34 auto body = response.extract_json().get(); 47 // Apache will drop "preview.opendev.org", so our expected input will be:
35 cout << response.status_code() << endl; 48 // site.75031cad206c4014ad7a3387091d15ab.openstack
36 cout << body.serialize() << endl; 49
37 // body["log_url"] returns a web::json::value 50 auto parts = split(hostname);
38 cout << "The log url is " << body["log_url"] << endl; 51 if (parts.size() < 3) {
39 // body["log_url"].as_string() returns a const std::string& 52 cout << "not enough args" << endl;
40 cout << "The log url is " << body["log_url"].as_string() << endl; 53 continue;
41 // body.at("log_url").as_string() returns a const std::string& 54 }
42 cout << "The log url is " << body.at("log_url").as_string() << endl; 55 auto artifact = parts[0];
56 auto buildid = parts[1];
57 auto tenant = parts[2];
58 cout << artifact << endl
59 << buildid << endl
60 << tenant << endl;
61
62 // 75031cad206c4014ad7a3387091d15ab
63 auto uri = web::uri_builder("/api/tenant/" + tenant + "/build");
64 uri.append_path(buildid);
65 auto response = client.request(
66 web::http::methods::GET, uri.to_string()).get();
67 // body is a web::json::value
68 auto body = response.extract_json().get();
69 cout << response.status_code() << endl;
70 cout << body.serialize() << endl;
71
72 // TODO: use artifact
73 // body["log_url"].as_string() returns a const std::string&
74 cout << body["log_url"].as_string() << endl;
75 }
43} 76}