Browse Source

Use an env var for the API url

master
James E. Blair 3 months ago
parent
commit
7b680c18ec
3 changed files with 19 additions and 10 deletions
  1. 1
    0
      Dockerfile
  2. 1
    1
      vhost.conf
  3. 17
    9
      zuul-preview/main.cc

+ 1
- 0
Dockerfile View File

@@ -40,4 +40,5 @@ COPY --from=builder /usr/local /usr/local
40 40
 
41 41
 EXPOSE 80
42 42
 ENTRYPOINT ["/usr/bin/dumb-init", "--"]
43
+ENV ZUUL_API_URL=
43 44
 CMD ["/usr/sbin/apachectl", "-DFOREGROUND", "-e", "info"]

+ 1
- 1
vhost.conf View File

@@ -7,5 +7,5 @@
7 7
         # LogLevel alert rewrite:trace6
8 8
         RewriteEngine On
9 9
         RewriteMap preview "prg://usr/local/bin/zuul-preview"
10
-        RewriteRule "^/?(.*)$" "${preview:%{HTTP_HOST}}/$1" [P]
10
+        RewriteRule "^/?(.*)$" "${preview:%{ENV:ZUUL_API_URL} %{HTTP_HOST}}/$1" [P]
11 11
 </VirtualHost>

+ 17
- 9
zuul-preview/main.cc View File

@@ -31,12 +31,12 @@
31 31
 
32 32
 using namespace std;
33 33
 
34
-vector<string> split(const string &in)
34
+vector<string> split(const string &in, char delim)
35 35
 {
36 36
   istringstream stream(in);
37 37
   vector<string> parts;
38 38
   string part;
39
-  while (getline(stream, part, '.')) {
39
+  while (getline(stream, part, delim)) {
40 40
     parts.push_back(part);
41 41
   }
42 42
   return parts;
@@ -96,9 +96,7 @@ public:
96 96
 
97 97
 int main(int, char**)
98 98
 {
99
-  web::http::client::http_client client("https://zuul.opendev.org");
100
-
101
-  string hostname;
99
+  string input;
102 100
   Cache cache{1024};
103 101
 
104 102
   // For each request apache receieves, it sends us the HTTP host name
@@ -107,8 +105,17 @@ int main(int, char**)
107 105
   // (protected by an internal mutex) and expect exactly one line of
108 106
   // output for each.
109 107
   // Expected input:
110
-  // site.926bb0aaddad4bc3853269451e115dcb.openstack.preview.opendev.org
111
-  while (getline(cin, hostname)) {
108
+  // https://zuul.opendev.org site.926bb0aaddad4bc3853269451e115dcb.openstack.preview.opendev.org
109
+  while (getline(cin, input)) {
110
+
111
+    // Split the input into api_url, hostname
112
+    auto parts = split(input, ' ');
113
+    if (parts.size() != 2) {
114
+      cout << "Wrong number of args" << endl;
115
+      continue;
116
+    }
117
+    auto api_url = parts[0];
118
+    auto hostname = parts[1];
112 119
 
113 120
     // If we have the value in the cache, return it.
114 121
     if (auto val = cache.get(hostname)) {
@@ -118,9 +125,9 @@ int main(int, char**)
118 125
 
119 126
     // We use the first three parts of the hostname to look up the
120 127
     // build url.
121
-    auto parts = split(hostname);
128
+    parts = split(hostname, '.');
122 129
     if (parts.size() < 3) {
123
-      cout << "Not enough args" << endl;
130
+      cout << "Not enough hostname parts" << endl;
124 131
       continue;
125 132
     }
126 133
     auto artifact = parts[0];
@@ -129,6 +136,7 @@ int main(int, char**)
129 136
 
130 137
     try {
131 138
       // Use the Zuul API to look up the artifact URL.
139
+      web::http::client::http_client client(api_url);
132 140
       auto uri = web::uri_builder("/api/tenant/" + tenant + "/build");
133 141
       uri.append_path(buildid);
134 142
       auto response = client.request(

Loading…
Cancel
Save