Fetch Jenkins data with credentials included
If Jenkins requires authentication and it is hosted on a different
origin than Gerrit (which probably is the case) then the request will
fail with 403.
With "credentials = include" cookies are sent. So if I am logged in
Jenkins, the request will succeed and no explicit credentials passing is
required.
Change-Id: I3a9ce7911fd8c6472c99828dad347e68aced4ce6
diff --git a/web/fetcher.ts b/web/fetcher.ts
index 0988417..0eef435 100644
--- a/web/fetcher.ts
+++ b/web/fetcher.ts
@@ -141,7 +141,7 @@
async fetchJobInfo(url: string): Promise<Job> {
let response: Response;
try {
- response = await fetch(url);
+ response = await this.fetchFromJenkins(url);
if (!response.ok) {
throw response.statusText;
}
@@ -156,7 +156,7 @@
}
async fetchBuildInfo(url: string): Promise<BuildDetail> {
- const response = await fetch(url);
+ const response = await this.fetchFromJenkins(url);
if (!response.ok) {
throw response.statusText;
}
@@ -215,4 +215,9 @@
};
return run;
}
+
+ private fetchFromJenkins(url: string): Promise<Response> {
+ const options: RequestInit = { credentials: 'include' };
+ return fetch(url, options);
+ }
}