|
| 1 | +import * as https from 'https'; |
1 | 2 | import * as LRUCache from 'lru-cache'; |
2 | 3 | import {Pretend, Get, Post, Put, Patch, Delete, Headers as Header, Interceptor, IPretendRequestInterceptor, |
3 | 4 | IPretendDecoder} from 'pretend'; |
@@ -180,11 +181,13 @@ export interface PullRequestStruct { |
180 | 181 | mergeable?: boolean|null; |
181 | 182 | } |
182 | 183 |
|
183 | | -export function getClient(endpoint: string, token: string, logger: (message: string) => void): GitHub { |
| 184 | +export function getClient(endpoint: string, token: string, logger: (message: string) => void, |
| 185 | + allowUnsafeSSL = false): GitHub { |
184 | 186 | return Pretend |
185 | 187 | .builder() |
186 | 188 | .interceptor(impl.githubCache()) |
187 | 189 | .requestInterceptor(impl.githubTokenAuthenticator(token)) |
| 190 | + .requestInterceptor(impl.githubHttpsAgent(!allowUnsafeSSL)) |
188 | 191 | .interceptor(impl.logger(logger)) |
189 | 192 | .decode(impl.githubDecoder()) |
190 | 193 | .target(impl.GitHubBlueprint, endpoint); |
@@ -251,6 +254,16 @@ namespace impl { |
251 | 254 | }; |
252 | 255 | } |
253 | 256 |
|
| 257 | + export function githubHttpsAgent(rejectUnauthorized: boolean): IPretendRequestInterceptor { |
| 258 | + return request => { |
| 259 | + if (!request.url.startsWith('https://')) { |
| 260 | + return request; |
| 261 | + } |
| 262 | + request.options.agent = new https.Agent({ rejectUnauthorized }); |
| 263 | + return request; |
| 264 | + }; |
| 265 | + } |
| 266 | + |
254 | 267 | export function githubDecoder(): IPretendDecoder { |
255 | 268 | return async response => { |
256 | 269 | if (response.status >= 400) { |
|
0 commit comments