-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for disabling ssl certificate validation to able co…
…nnect self-signed es cluster Signed-off-by: seven <[email protected]>
- Loading branch information
Showing
14 changed files
with
236 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,4 +30,4 @@ body { | |
color: var(--text-color); | ||
transition: .3s; | ||
font-size: 14px; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import Electron from 'electron'; | ||
import fetch from 'node-fetch'; | ||
import { CustomError, debug } from '../common'; | ||
import * as https from 'https'; | ||
|
||
type FetchApiOptions = { | ||
method: string; | ||
authorization: string; | ||
payload: string | undefined; | ||
ssl: boolean; | ||
}; | ||
|
||
export type FetchApiInput = { | ||
method: string; | ||
url: string; | ||
options: FetchApiOptions; | ||
}; | ||
|
||
const fetchApi: { [key: string]: (key: string, val: unknown) => unknown } = { | ||
fetch: async (url: string, { method, authorization, payload, ssl }: FetchApiOptions) => { | ||
const agent = url.startsWith('https') | ||
? new https.Agent({ | ||
rejectUnauthorized: ssl, | ||
}) | ||
: undefined; | ||
try { | ||
const result = await fetch(url, { | ||
method, | ||
headers: { 'Content-Type': 'application/json', authorization } as unknown as Headers, | ||
body: payload, | ||
agent, | ||
}); | ||
if (result.ok) { | ||
return { status: result.status, data: await result.json() }; | ||
} | ||
throw new CustomError(result.status, await result.text()); | ||
} catch (e) { | ||
debug('error encountered while node-fetch fetch target:', e); | ||
return { status: e.status || 500, details: e.details || e.message }; | ||
} | ||
}, | ||
}; | ||
export const registerFetchApiListener = (ipcMain: Electron.IpcMain) => { | ||
ipcMain.handle('fetchApi', (_, { method, url, options }: FetchApiInput) => | ||
fetchApi[method.toLowerCase()](url, options), | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.